~ubuntu-app-review-contributors/ubuntu-app-reviews/01

« back to all changes in this revision

Viewing changes to protoborsa/ProtoborsaWindow.py

  • Committer: crazycoder
  • Date: 2012-07-08 22:53:32 UTC
  • Revision ID: crazycoder@gmail.com-20120708225332-orlk0u5xi0ucdq3a
quickly saved

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        self.toolbar = self.builder.get_object('toolbar');
60
60
        ctx = self.toolbar.get_style_context();
61
61
        ctx.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
62
 
        self.launcher = Unity.LauncherEntry.get_for_desktop_id("protoborsa.desktop");
 
62
        self.launcher = Unity.LauncherEntry.get_for_desktop_id("extras-protoborsa.desktop");
63
63
        self.quicklist = Dbusmenu.Menuitem.new()
64
64
        self.data = []
65
65
        self.surface = None;
75
75
            self.liststock.clear();
76
76
        self.addQuickList('Reload');
77
77
        self.launcher.set_property('quicklist', self.quicklist);
78
 
        self.launcher.set_property("progress_visible", True)
79
 
        self.launcher.set_property("progress", 0.2)
 
78
        self.startLoading();
80
79
        glib.timeout_add(1000, self.loadStockData) #wait for interface loading...
81
80
    def setXTicks(self,daysToPlot):
82
81
        self.xticks = utilities.getAxisTicks(daysToPlot);
110
109
            self.connectionFault();
111
110
        print "Loading data finished";
112
111
    def startLoading(self):
113
 
        self.launcher.set_property("progress",0.35);
114
 
        self.launcher.set_property("progress_visible", True);
 
112
        print "startLoading called";
 
113
        self.launcher.set_property("progress", 0.3)
 
114
        self.launcher.set_property("progress_visible", True)
115
115
    def middleLoading(self):
 
116
        self.launcher.set_property("progress_visible", True)
116
117
        self.launcher.set_property("progress",0.60);
117
 
    def endLoading(self):
 
118
    def finishLoading(self):
118
119
        self.launcher.set_property("progress_visible", False);
119
120
    def connectionFault(self):
120
121
        self.liststock.clear();
152
153
                self.liststock.append([res['symbol'],res['naming'],str(res['price'])+' $',str(float(res['volume'])/1000000)+' Mio',res['market_cap'],str(float(res['avg_daily_volume'])/1000000)]);
153
154
            if (len(results)==0):
154
155
                self.connectionFault();
155
 
            self.endLoading();
 
156
            self.finishLoading();
156
157
    def on_showsearch_clicked(self,widget):
157
158
        print "on click for add dialog";
 
159
        self.startLoading();
158
160
        if self.SearchstockDialog is not None:
159
 
            searchDlg = self.SearchstockDialog() 
 
161
            searchDlg = self.SearchstockDialog()
 
162
            self.middleLoading();
160
163
            response = searchDlg.run()
 
164
            self.finishLoading();
161
165
            #print "RESP " + str(response);          
162
166
            if( response == Gtk.ResponseType.OK ):
163
167
                print "pressed ok! ";
180
184
            if( response == Gtk.ResponseType.CANCEL ):
181
185
                print "pressed Cancel!"
182
186
            searchDlg.destroy()
183
 
 
 
187
        self.finishLoading();
184
188
    def onStockSelectionChanged(self,widget):
185
189
        print "Selection changed";
186
190
        if(widget == None):
191
195
        model, tree_iter = selection.get_selected()
192
196
        if(tree_iter == None):
193
197
            return None;
194
 
        self.launcher.set_property("progress", 0.2)
195
 
        self.launcher.set_property("progress_visible", True)
 
198
        self.startLoading();
196
199
        self.chartLabel.set_text("Downloading data to plot..."); 
197
200
        symbol = model.get_value(tree_iter, 0);
198
201
        naming = model.get_value(tree_iter, 1);
258
261
        '''print "Downloading from " + utilities.getLastMonth4YBegin() + " to " +utilities.getLastMonth4YEnd() ;         
259
262
        GOOG = ystockquote.get_historical_prices(symbol,  utilities.getLastMonth4YBegin(), utilities.getLastMonth4YEnd());'''
260
263
        print 'download data to plot......';
261
 
        self.launcher.set_property("progress", 0.5)
 
264
        self.middleLoading();
262
265
        threadData = self.data4Chart(symbol,naming);
263
266
        GOOG = threadData['plotData'];
264
267
        self.chartLabel.set_text("Last Month of " + naming);
266
269
        # Populate lists from downloaded data
267
270
        #print len(GOOG)
268
271
        days = [];
269
 
        field = 1;
 
272
        field = 6;
270
273
        self.maxyvalue = 0;
271
274
        self.minyvalue = 0;
272
275
        reverse = 0;
288
291
        self.maxyvalue = self.maxyvalue + 2;
289
292
        self.setXTicks(days);
290
293
        print "Download complete"
291
 
        self.launcher.set_property("progress", 0.7)
292
294
        #print self.data;
293
295
        self.plotOnCanvas()
294
296
        self.gtkArea.queue_draw()
295
 
        self.launcher.set_property("progress", 1.0)
296
 
        self.launcher.set_property("progress_visible", False)
 
297
        self.finishLoading();
297
298
class ThreadUrl(threading.Thread):
298
299
    def __init__(self, queue,result):
299
300
        threading.Thread.__init__(self)
304
305
            z = self.queue.get() #grab a tupla (type,symbols,naming) from queue. type is ( data for ) "table" or "chart".
305
306
            symbol = z[1];
306
307
            stockdata = {};
307
 
            print "symbol proc: "+str(symbol);
 
308
            #print "symbol proc: "+str(symbol);
308
309
            try:
309
310
                if(z[0] == "table"):
310
311
                        stockdata = ystockquote.get_all(symbol);
311
 
                        print "ererq";
312
312
                elif(z[0] == "chart"):
313
313
                        stockdata['plotData'] = ystockquote.get_historical_prices(symbol, utilities.getLastMonth4YBegin(), utilities.getLastMonth4YEnd());
314
 
                        print "papi";
315
314
                else:
316
 
                        print "error...type not known";
317
315
                        self.queue.task_done();
318
316
                        return;
319
317
                if(len(stockdata) != 0):
320
 
                        print "Not 0!";
321
318
                        stockdata['symbol'] = symbol;
322
319
                        stockdata['naming'] = z[2];
323
320
                        self.result.append(stockdata);