from marketdata import markets, idmarket, localmarkets, localids
from marketdata import markets, idmarket, localmarkets, localids
- self.window.set_default_size(800, 480)
- self.window.set_title('StocksPy')
+ self.window.set_default_size(800, 480)
+ self.window.set_title('StockThis')
self.window.connect("destroy", gtk.main_quit)
self.window.connect("key-press-event", self.on_key_press)
self.window.connect("window-state-event", self.on_window_state_change)
self.window_in_fullscreen = False
self.window.connect("destroy", gtk.main_quit)
self.window.connect("key-press-event", self.on_key_press)
self.window.connect("window-state-event", self.on_window_state_change)
self.window_in_fullscreen = False
else:
menu = gtk.Menu()
self.window.set_menu(menu)
about_menu = gtk.MenuItem("About")
about_menu.set_size_request(-1, 55)
else:
menu = gtk.Menu()
self.window.set_menu(menu)
about_menu = gtk.MenuItem("About")
about_menu.set_size_request(-1, 55)
-
- about_menu.connect("activate", self.on_about)
- menu.append(about_menu)
+ about_menu.connect("activate", self.on_about)
+
+ menu.append(about_menu)
self.toolbar = gtk.HBox()
self.toolbar.set_property("no-show-all", True)
self.toolbar.hide()
self.toolbar.set_homogeneous(True)
self.toolbar.set_size_request(-1, 55)
self.toolbar = gtk.HBox()
self.toolbar.set_property("no-show-all", True)
self.toolbar.hide()
self.toolbar.set_homogeneous(True)
self.toolbar.set_size_request(-1, 55)
self.markets_btn = gtk.Button('Markets')
self.markets_btn.connect("clicked", self.create_markets_view)
self.markets_btn.set_property("can_focus", False)
self.markets_btn = gtk.Button('Markets')
self.markets_btn.connect("clicked", self.create_markets_view)
self.markets_btn.set_property("can_focus", False)
- self.components_btn.set_property("can_focus", False)
-
- self.graph_btn = gtk.Button('Graphs')
+ self.components_btn.set_property("can_focus", False)
+
+ self.graph_btn = gtk.Button('Graph')
self.graph_btn.connect("clicked", self.create_graphs_view)
self.graph_btn.set_property("can_focus", False)
self.graph_btn.connect("clicked", self.create_graphs_view)
self.graph_btn.set_property("can_focus", False)
self.refresh_btn = gtk.Button('Refresh')
self.refresh_btn.connect("clicked", self.refresh_stock_data)
self.refresh_btn.set_property("can_focus", False)
self.refresh_btn = gtk.Button('Refresh')
self.refresh_btn.connect("clicked", self.refresh_stock_data)
self.refresh_btn.set_property("can_focus", False)
- self.quotes_btn.set_property("can_focus", False)
-
- self.toolbar.pack_start(self.markets_btn)
+ self.quotes_btn.set_property("can_focus", False)
+
+ self.toolbar.pack_start(self.markets_btn)
for i in range(lnames):
button = gtk.Button(names[i])
button.connect("clicked", self.create_components_view, ids[i])
button.set_size_request(-1, 65)
button.set_property("can_focus", False)
self.marketsbox.pack_start(button, True, True, 2)
for i in range(lnames):
button = gtk.Button(names[i])
button.connect("clicked", self.create_components_view, ids[i])
button.set_size_request(-1, 65)
button.set_property("can_focus", False)
self.marketsbox.pack_start(button, True, True, 2)
self.mainbox.pack_start(self.marketsbox, True, True, 2)
self.mainbox.show_all()
self.mainbox.pack_start(self.marketsbox, True, True, 2)
self.mainbox.show_all()
if not FREMANTLE:
selection = self.components_trv.get_selection()
selection.connect("changed", self.changed_selection, ids)
else:
self.components_trv.connect("row-activated", self.select_component, ids)
if not FREMANTLE:
selection = self.components_trv.get_selection()
selection.connect("changed", self.changed_selection, ids)
else:
self.components_trv.connect("row-activated", self.select_component, ids)
self.components_model = self.__create_components_model()
self.components_trv.set_model(self.components_model)
self.components_model = self.__create_components_model()
self.components_trv.set_model(self.components_model)
-
- self.compbox.pack_start(self.components_trv, True, True, 0)
+
+ self.compbox.pack_start(self.components_trv, True, True, 0)
self.mainbox.pack_start(self.compbox, True, True, 0)
self.mainbox.show_all()
def select_component(self, widget, path, column, ids):
self.create_quotes_view(widget,self.components_model[path][1] )
self.mainbox.pack_start(self.compbox, True, True, 0)
self.mainbox.show_all()
def select_component(self, widget, path, column, ids):
self.create_quotes_view(widget,self.components_model[path][1] )
def changed_selection(self, widget, ids):
n, i, m = self.get_selected_from_treeview(self.components_trv, self.components_model, 1)
if n is not None:
self.create_quotes_view(widget, n)
def changed_selection(self, widget, ids):
n, i, m = self.get_selected_from_treeview(self.components_trv, self.components_model, 1)
if n is not None:
self.create_quotes_view(widget, n)
def __create_components_model(self):
lstore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
return lstore
def __create_components_model(self):
lstore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
return lstore
#renderer.set_property("background", 'lightgray')
renderer.set_property("xpad", 15)
column = gtk.TreeViewColumn('Name', renderer, text=0)
column.set_expand(True)
#renderer.set_property("background", 'lightgray')
renderer.set_property("xpad", 15)
column = gtk.TreeViewColumn('Name', renderer, text=0)
column.set_expand(True)
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn('IDS', renderer, text=1)
column.set_visible(False)
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn('IDS', renderer, text=1)
column.set_visible(False)
def add_initial_components(self, kind, ids):
for i in range(len(kind)):
def add_initial_components(self, kind, ids):
for i in range(len(kind)):
- niter = self.components_model.append()
- self.components_model.set(niter, 0, kind[i], 1, ids[i])
+ niter = self.components_model.append()
+ self.components_model.set(niter, 0, kind[i], 1, ids[i])
def get_selected_from_treeview(self, treeview, model, setting):
selection = treeview.get_selection()
def get_selected_from_treeview(self, treeview, model, setting):
selection = treeview.get_selection()
- label1 = gtk.Label('')
- label1.set_markup('<b><big>'+localmarkets[ind1][ind2]+'</big></b>')
- color = gtk.gdk.color_parse("#03A5FF")
- label1.modify_fg(gtk.STATE_NORMAL, color)
+ self.titlelbl = gtk.Label('')
+ self.titlelbl.set_markup('<b><big>'+localmarkets[ind1][ind2].replace('&', '')+'</big></b>')
+ color = gtk.gdk.color_parse("#03A5FF")
+ self.titlelbl.modify_fg(gtk.STATE_NORMAL, color)
hbox1.pack_start(label2, False, False, 50)
hbox1.pack_start(self.lprice, False, False, 185)
hbox1.pack_start(label2, False, False, 50)
hbox1.pack_start(self.lprice, False, False, 185)
hbox2 = gtk.HBox()
label4 = gtk.Label('')
label4.set_markup('<b><big>Change:</big></b>')
self.lchange = gtk.Label('')
self.lpercent = gtk.Label('')
hbox2 = gtk.HBox()
label4 = gtk.Label('')
label4.set_markup('<b><big>Change:</big></b>')
self.lchange = gtk.Label('')
self.lpercent = gtk.Label('')
hbox2.pack_start(label4, False, False, 50)
hbox2.pack_start(label4, False, False, 50)
- hbox2.pack_start(self.lchange , False, False, 145)
+ hbox2.pack_start(self.lchange , False, False, 145)
hbox2.pack_start(self.lpercent, False, False, 0)
hbox2.pack_start(self.lpercent, False, False, 0)
hbox3.pack_start(label7, False, False, 50)
hbox3.pack_start(label7, False, False, 50)
- hbox3.pack_start(self.lvolume , False, False, 145)
-
+ hbox3.pack_start(self.lvolume , False, False, 145)
+
hbox4.pack_start(label9, False, False, 50)
hbox4.pack_start(label9, False, False, 50)
- hbox4.pack_start(self.l52whigh , False, False, 55)
-
+ hbox4.pack_start(self.l52whigh , False, False, 55)
+
hbox5.pack_start(label11, False, False, 50)
hbox5.pack_start(self.l52wlow , False, False, 70)
hbox5.pack_start(label11, False, False, 50)
hbox5.pack_start(self.l52wlow , False, False, 70)
self.databox.pack_start(hbox1, True, True, 0)
self.databox.pack_start(hbox2, True, True, 0)
self.databox.pack_start(hbox3, True, True, 0)
self.databox.pack_start(hbox4, True, True, 0)
self.databox.pack_start(hbox5, True, True, 0)
self.databox.pack_start(hbox1, True, True, 0)
self.databox.pack_start(hbox2, True, True, 0)
self.databox.pack_start(hbox3, True, True, 0)
self.databox.pack_start(hbox4, True, True, 0)
self.databox.pack_start(hbox5, True, True, 0)
-
- self.quotesbox.pack_start(label1, False, False, 0)
- self.quotesbox.pack_start(gtk.HSeparator(), False, False, 0)
- self.quotesbox.pack_start(self.databox, True, True, 0)
- self.quotesbox.pack_start(self.imagebox, True, True, 0)
+
+ self.quotesbox.pack_start(self.titlelbl, False, False, 0)
+ self.quotesbox.pack_start(gtk.HSeparator(), False, False, 0)
+ self.quotesbox.pack_start(self.databox, True, True, 0)
+ self.quotesbox.pack_start(self.imagebox, True, True, 0)
self.mainbox.pack_start(self.quotesbox, True, True, 0)
self.mainbox.show_all()
self.mainbox.pack_start(self.quotesbox, True, True, 0)
self.mainbox.show_all()
- ch_percent = 100.0 * float(data['change'])/float(data['price'])
+ data = yt.get_all(kind)
+ except:
+ print 'Failed to get internet data'
+ data = {'price': 'N/A', 'change': 'N/A', 'volume':'N/A',
+ '52_week_high': 'N/A', '52_week_low': 'N/A'}
+ self.titlelbl.set_markup('<b><big>Failed to get data</big></b>')
+
+ try:
+ ch_percent = 100.0 * float(data['change'])/(float(data['price'])-float(data['change']))
except ValueError:
ch_percent = 0.0
self.lprice.set_label(data['price'])
self.lchange.set_label(data['change'])
self.lpercent.set_label('%6.2f %%' % ch_percent)
except ValueError:
ch_percent = 0.0
self.lprice.set_label(data['price'])
self.lchange.set_label(data['change'])
self.lpercent.set_label('%6.2f %%' % ch_percent)
self.lvolume.set_label(data['volume'])
self.l52whigh.set_label(data['52_week_high'])
self.l52wlow.set_label(data['52_week_low'])
self.lvolume.set_label(data['volume'])
self.l52whigh.set_label(data['52_week_high'])
self.l52wlow.set_label(data['52_week_low'])
def refresh_stock_data(self, widget):
self.show_data(self.stocks_id)
def refresh_stock_data(self, widget):
self.show_data(self.stocks_id)
for i in range(len(localids)):
if kind in localids[i]:
ind1, ind2 = i, localids[i].index(kind)
for i in range(len(localids)):
if kind in localids[i]:
ind1, ind2 = i, localids[i].index(kind)
hbox1 = gtk.HBox()
hbox1.set_size_request(-1, 55)
hbox1.set_homogeneous(True)
hbox1 = gtk.HBox()
hbox1.set_size_request(-1, 55)
hbox1.set_homogeneous(True)
self.btn1d = gtk.Button('1d')
self.btn1d.set_property("can_focus", False)
self.btn1d.connect("clicked", self.show_graph, '1d', kind)
self.btn1d = gtk.Button('1d')
self.btn1d.set_property("can_focus", False)
self.btn1d.connect("clicked", self.show_graph, '1d', kind)
self.btnmax = gtk.Button('max')
self.btnmax.set_property("can_focus", False)
self.btnmax.connect("clicked", self.show_graph, 'max', kind)
self.btnmax = gtk.Button('max')
self.btnmax.set_property("can_focus", False)
self.btnmax.connect("clicked", self.show_graph, 'max', kind)
- hbox1.pack_start(self.btn5d)
- hbox1.pack_start(self.btn3m)
- hbox1.pack_start(self.btn6m)
- hbox1.pack_start(self.btn1y)
- hbox1.pack_start(self.btn2y)
- hbox1.pack_start(self.btn5y)
- hbox1.pack_start(self.btnmax)
-
- self.graphbox.pack_start(label1, False, False, 2)
- self.graphbox.pack_start(hbox1, False, False, 0)
+ hbox1.pack_start(self.btn5d)
+ hbox1.pack_start(self.btn3m)
+ hbox1.pack_start(self.btn6m)
+ hbox1.pack_start(self.btn1y)
+ hbox1.pack_start(self.btn2y)
+ hbox1.pack_start(self.btn5y)
+ hbox1.pack_start(self.btnmax)
+
+ self.graphbox.pack_start(self.graphs_title, False, False, 2)
+ self.graphbox.pack_start(hbox1, False, False, 0)
self.graphbox.pack_start(self.graph, True, True, 5)
self.graphbox.pack_start(self.graph, True, True, 5)
self.mainbox.pack_start(self.graphbox, False, False, 2)
self.mainbox.pack_start(self.graphbox, False, False, 2)
def show_graph(self, widget, option, kind):
import thread
def show_graph(self, widget, option, kind):
import thread
def get_graph_data(self, option, kind):
if option == '1d':
url = 'http://uk.ichart.yahoo.com/b?s=%s' % kind
def get_graph_data(self, option, kind):
if option == '1d':
url = 'http://uk.ichart.yahoo.com/b?s=%s' % kind
- pbl = gtk.gdk.PixbufLoader()
- pbl.write(imgdata)
+ try:
+ myimg = urllib2.urlopen(url)
+ imgdata=myimg.read()
+
+ pbl = gtk.gdk.PixbufLoader()
+ pbl.write(imgdata)
+
+ pbuf = pbl.get_pixbuf()
+ pbl.close()
+ self.graph.set_from_pixbuf(pbuf)
+ except:
+ print 'no internet data'
+ self.graphs_title.set_label('Failed to get data')
+ self.graph.destroy()
- def on_window_state_change(self, widget, event, *args):
+ def on_window_state_change(self, widget, event, *args):
if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
self.window_in_fullscreen = True
else:
self.window_in_fullscreen = False
#F6 fullscreen, F7 bigger font, F8 smaller font
if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
self.window_in_fullscreen = True
else:
self.window_in_fullscreen = False
#F6 fullscreen, F7 bigger font, F8 smaller font
- def on_key_press(self, widget, event, *args):
+ def on_key_press(self, widget, event, *args):
if event.keyval == gtk.keysyms.F6:
if self.window_in_fullscreen:
self.window.unfullscreen ()
else:
if event.keyval == gtk.keysyms.F6:
if self.window_in_fullscreen:
self.window.unfullscreen ()
else:
def on_about(self, widget):
dialog = gtk.AboutDialog()
dialog.set_name("StockThis")
def on_about(self, widget):
dialog = gtk.AboutDialog()
dialog.set_name("StockThis")
dialog.set_copyright("Copyright © 2009")
dialog.set_website("http://stockthis.garage.maemo.org")
dialog.set_authors(["Daniel Martin Yerga <dyerga@gmail.com>"])
dialog.set_copyright("Copyright © 2009")
dialog.set_website("http://stockthis.garage.maemo.org")
dialog.set_authors(["Daniel Martin Yerga <dyerga@gmail.com>"])