From: Daniel Martin Yerga Date: Sun, 28 Feb 2010 11:17:54 +0000 (+0100) Subject: new portfolio features, metal graphs, preparing for 0.4 release X-Git-Url: https://vcs.maemo.org/git/?p=stockthis;a=commitdiff_plain;h=HEAD new portfolio features, metal graphs, preparing for 0.4 release --- diff --git a/changelog b/changelog index b6a543a..c4060d1 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,8 @@ +2010-02-27 Daniel Martin Yerga + + * Possibility to edit items from portfolio. + * Added graphs for some metals. + 2010-02-23 Daniel Martin Yerga * A bit improved search dialog (and using Nokia icon). diff --git a/debian/changelog b/debian/changelog index 460519d..ee580e2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,17 @@ +stockthis (0.4-1) fremantle; urgency=low + + * Possibility to edit items from portfolio. + * Change and percentage columns added to portfolio view. + * Added graphs for some metals. + * Settings are saved with the system backup. Fixes: MB#6078 + * A bit improved search dialog (and using Nokia icon). + * Enter key activates most dialogs. + * New, improved About dialog. + * It's possible to add to the Portfolio without setting a name. Fixes: MB#6077 + * Changed the rating URL to the right maemo.org download page. + + -- Daniel Martin Yerga Sun, 28 Feb 2010 12:15:00 +0100 + stockthis (0.3-1) fremantle; urgency=low * Fixed: It uses existing browser window instead of a new one: MB #5802 diff --git a/marketdata.py b/marketdata.py index 6ae332f..b77d555 100644 --- a/marketdata.py +++ b/marketdata.py @@ -1,5 +1,5 @@ -main = ["Markets indices", "US Markets", "European Markets", "Other Markets", "Currencies", "Exchange-Traded Funds"] -idmain = ["indices", "usm", "eum", "om", "currency", "etf"] +main = ["Markets indices", "US Markets", "European Markets", "Other Markets", "Currencies", "Exchange-Traded Funds", "Metal graphs"] +idmain = ["indices", "usm", "eum", "om", "currency", "etf", "metals"] #DOW JONES dow_jones_symbols=['AA', 'AXP', 'BA', 'BAC', 'C', 'CAT', 'CVX', 'DD', 'DIS', 'GE', 'GM', 'HD', 'HPQ', 'IBM', 'INTC', 'JNJ', 'JPM', 'KFT', 'KO', 'MCD', 'MMM', 'MRK', 'MSFT', 'PFE', 'PG', 'T', 'UTX', 'VZ', 'WMT', 'XOM'] @@ -171,13 +171,15 @@ currency_names = ["EUR/USD", "EUR/GBP", "EUR/CHF", "EUR/SEK", "GBP/USD", "USD/JP etf_symbols = ["IXC", "IXN", "ICLN", "IXJ", "IXG", "IOO", "EWD", "EEM", "FXI", "BKF", "THD"] etf_names = ["iShares S&P Global Energy", "iShares S&P Global Technology", "iShares S&P Global Clean Energy Index", "iShares S&P Global Healthcare", "iShares S&P Global Financials", "iShares S&P Global 100 Index", "iShares MSCI Sweden Index", "iShares MSCI Emerging Markets Index", "iShares FTSE/Xinhua China 25 Index", "iShares MSCI BRIC Index", "iShares MSCI Thailand Invest Mkt Index"] +metal_symbols = ["-", "-", "-", "-", "-", "-", "-", "-", "-", "-"] +metal_names = ["Gold", "Silver", "Platinum", "Palladium", "Rhodium", "Copper", "Nickel", "Aluminium", "Zinc", "Lead"] ## GET ALL LISTS ## localmarkets = [indexesnames, usmarkets, eumarkets, otmarkets, currency_names, - etf_names] + etf_names, metal_names] localids = [idindexes, idusmarkets, ideumarkets, idotmarkets, currency_symbols, - etf_symbols] + etf_symbols, metal_symbols] wnamesindexes = [usindex_names, eurindex_names, othindex_names] widsindexes = [usindex_symbols, eurindex_symbols, othindex_symbols] diff --git a/stockthis.py b/stockthis.py index b180771..7ca72b4 100644 --- a/stockthis.py +++ b/stockthis.py @@ -123,9 +123,6 @@ class StocksPy: button = gtk.Button("About") button.connect("clicked", About) menu.append(button) - button = gtk.Button("Log") - button.connect("clicked", Log, logfile) - menu.append(button) menu.show_all() def show_instrument_view(self, widget, path, column, inmodel, names, @@ -145,7 +142,12 @@ class StocksPy: parea.connect("horizontal-movement", self.horizontal_mov) tv = hildon.GtkTreeView(ui_normal) model = self.__create_model(names, ids) - tv.connect("row-activated", self.show_quotes_view, model, False) + + if market == 'metals': + tv.connect("row-activated", self.show_metal_graphs, model) + else: + tv.connect("row-activated", self.show_quotes_view, model, False) + tv.set_model(model) self._tv_columns(tv) parea.add(tv) @@ -607,6 +609,188 @@ class StocksPy: self.graphs_title.set_label('Failed to get data') self.graph.destroy() + def show_metal_graphs(self, widget, path, column, model): + metal = model[path][1] + metal_urls = self.get_metal_graphs_urls(metal) + options = [] + for i in metal_urls: + options.append(i[0]) + + win = hildon.StackableWindow() + #self.create_menu(win) + win.set_title(metal) + + vbox = gtk.VBox() + #toolbar = self.main_toolbar(False, True, None, '', '', False) + + self.metalgraph_title = gtk.Label(metal) + color = gtk.gdk.color_parse("#03A5FF") + self.metalgraph_title.modify_fg(gtk.STATE_NORMAL, color) + + parea = hildon.PannableArea() + parea.set_property("mov-mode", hildon.MOVEMENT_MODE_BOTH) + + vbox1 = gtk.VBox() + + hbox = gtk.HBox() + hbox.set_homogeneous(True) + + button = hildon.Button(fhsize, horbtn) + button.set_label('live') + button.connect("clicked", self.show_metalgraph, 'live', win, metal_urls) + if 'live' in options: + hbox.pack_start(button) + + button = hildon.Button(fhsize, horbtn) + button.set_label('30d') + button.connect("clicked", self.show_metalgraph, '30d', win, metal_urls) + if '30d' in options: + hbox.pack_start(button) + + button = hildon.Button(fhsize, horbtn) + button.set_label('60d') + button.connect("clicked", self.show_metalgraph, '60d', win, metal_urls) + if '60d' in options: + hbox.pack_start(button) + + button = hildon.Button(fhsize, horbtn) + button.set_label('6m') + button.connect("clicked", self.show_metalgraph, '6m', win, metal_urls) + if '6m' in options: + hbox.pack_start(button) + + vbox1.pack_start(hbox, False, False, 0) + hbox = gtk.HBox() + hbox.set_homogeneous(True) + + button = hildon.Button(fhsize, horbtn) + button.set_label('1y') + button.connect("clicked", self.show_metalgraph, '1y', win, metal_urls) + if '1y' in options: + hbox.pack_start(button) + + button = hildon.Button(fhsize, horbtn) + button.set_label('5y') + button.connect("clicked", self.show_metalgraph, '5y', win, metal_urls) + if '5y' in options: + hbox.pack_start(button) + + button = hildon.Button(fhsize, horbtn) + button.set_label('10y') + button.connect("clicked", self.show_metalgraph, '10y', win, metal_urls) + if '10y' in options: + hbox.pack_start(button) + + vbox1.pack_start(hbox, False, False, 0) + + self.metalgraph = gtk.Image() + vbox1.pack_start(self.metalgraph, True, True, 0) + + parea.add_with_viewport(vbox1) + + vbox.pack_start(self.metalgraph_title, False, False, 0) + vbox.pack_start(gtk.HSeparator(), False, False, 0) + vbox.pack_start(parea, True, True, 0) + vbox.pack_start(gtk.HSeparator(), False, False, 5) + #vbox.pack_start(toolbar, False, False, 0) + + win.add(vbox) + win.show_all() + + self.show_metalgraph(None, options[0], win, metal_urls) + + def show_metalgraph(self, widget, option, win, metal_urls): + import thread + winprogind(win, 1) + thread.start_new_thread(self.get_metalgraph_data, (option, win, metal_urls)) + + def get_metalgraph_data(self, option, win, metal_urls): + for i in metal_urls: + if i[0] == option: + print i[1] + url = i[1] + + try: + myimg = urllib2.urlopen(url) + imgdata = myimg.read() + + pbl = gtk.gdk.PixbufLoader() + pbl.write(imgdata) + + + pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 475, 235) + pixbuf.fill(0xffffffff) + + + pbuf = pbl.get_pixbuf() + pbuf = pbuf.scale_simple(475, 235, gtk.gdk.INTERP_TILES) + + pixbuf.composite(pbuf, 0, 0, pixbuf.props.width, pixbuf.props.height, 0, 0, 1.0, 1.0, gtk.gdk.INTERP_HYPER, 55) + + + pbl.close() + self.metalgraph.set_from_pixbuf(pbuf) + winprogind(win, 0) + except: + logger.exception("Getting graph data: %s" % url) + winprogind(win, 0) + self.metalgraph_title.set_label('Failed to get data') + self.metalgraph.destroy() + + def get_metal_graphs_urls(self, metal): + metal_urls = [] + liveurl = 'http://www.kitco.com/images/live/%s' + graphurl = 'http://www.kitco.com/LFgif/%s' + t24url = 'http://www.kitconet.com/charts/metals/base/%s' + if metal == 'Gold': + metal_urls.append(['live', liveurl % 'gold.gif']) + metal_urls.append(['30d', graphurl % 'au0030lnb.gif']) + metal_urls.append(['60d', graphurl % 'au0060lnb.gif']) + metal_urls.append(['6m', graphurl % 'au0182nyb.gif']) + metal_urls.append(['1y', graphurl % 'au0365nyb.gif']) + metal_urls.append(['5y', graphurl % 'au1825nyb.gif']) + metal_urls.append(['10y', graphurl % 'au3650nyb.gif']) + elif metal == 'Silver': + metal_urls.append(['live', liveurl % 'silver.gif']) + metal_urls.append(['30d', graphurl % 'ag0030lnb.gif']) + metal_urls.append(['60d', graphurl % 'ag0060lnb.gif']) + metal_urls.append(['6m', graphurl % 'ag0182nyb.gif']) + metal_urls.append(['1y', graphurl % 'ag0365nyb.gif']) + metal_urls.append(['5y', graphurl % 'ag1825nyb.gif']) + metal_urls.append(['10y', graphurl % 'ag3650nyb.gif']) + elif metal == 'Platinum': + metal_urls.append(['live', liveurl % 'plati.gif']) + metal_urls.append(['30d', graphurl % 'pt0030lnb.gif']) + metal_urls.append(['60d', graphurl % 'pt0060lnb.gif']) + metal_urls.append(['6m', graphurl % 'pt0182nyb.gif']) + metal_urls.append(['1y', graphurl % 'pt0365nyb.gif']) + metal_urls.append(['5y', graphurl % 'pt1825nyb.gif']) + elif metal == 'Palladium': + metal_urls.append(['live', liveurl % 'plad.gif']) + metal_urls.append(['30d', graphurl % 'pd0030lnb.gif']) + metal_urls.append(['60d', graphurl % 'pd0060lnb.gif']) + metal_urls.append(['6m', graphurl % 'pd0182nyb.gif']) + metal_urls.append(['1y', graphurl % 'pd0365nyb.gif']) + metal_urls.append(['5y', graphurl % 'pd1825nyb.gif']) + elif metal == 'Rhodium': + metal_urls.append(['30d', graphurl % 'rh0030lnb.gif']) + metal_urls.append(['60d', graphurl % 'rh0060lnb.gif']) + metal_urls.append(['6m', graphurl % 'rh0182lnb.gif']) + metal_urls.append(['1y', graphurl % 'rh0365lnb.gif']) + metal_urls.append(['5y', graphurl % 'rh1825lnb.gif']) + elif metal == 'Copper': + metal_urls.append(['live', t24url % 't24_cp450x275.gif']) + elif metal == 'Nickel': + metal_urls.append(['live', t24url % 't24_nk450x275.gif']) + elif metal == 'Aluminium': + metal_urls.append(['live', t24url % 't24_al450x275.gif']) + elif metal == 'Zinc': + metal_urls.append(['live', t24url % 't24_zc450x275.gif']) + elif metal == 'Lead': + metal_urls.append(['live', t24url % 't24_ld450x275.gif']) + + return metal_urls + def _tv_columns(self, treeview): column = gtk.TreeViewColumn('ID', gtk.CellRendererText(), text=0) column.set_visible(False) @@ -771,7 +955,6 @@ class StocksPy: window.add(vbox) window.show_all() - def show_app_information(self, widget): self.show_information_note(self.window, ( "The data is got from Yahoo! Finance.\n" @@ -798,7 +981,8 @@ class StocksPy: tv = hildon.GtkTreeView(ui_normal) tv.set_headers_visible(True) self.portfolio_model = self._create_portfolio_model(data) - tv.connect("row-activated", self.show_quotes_view, self.portfolio_model, True) + self.quotes_id = tv.connect("row-activated", self.show_quotes_view, + self.portfolio_model, True) tv.set_model(self.portfolio_model) self._tv_portfolio_columns(tv) parea.add(tv) @@ -811,7 +995,7 @@ class StocksPy: button = hildon.Button(fhsize, horbtn) button.set_title("Add manually") - button.connect("clicked", self.add_item_dlg) + button.connect("clicked", self.add_item_dlg, None, None) hbox.pack_start(button, True, True, 0) button = hildon.Button(fhsize, horbtn) @@ -819,13 +1003,55 @@ class StocksPy: button.connect("clicked", self.remove_item) hbox.pack_start(button, True, True, 0) + button = hildon.CheckButton(fhsize) + button.set_label("Edit") + + button.connect("toggled", self.edit_toggled, tv) + hbox.pack_start(button, True, True, 0) + + vbox.pack_start(parea, True, True, 0) vbox.pack_start(hbox, False, False, 0) win.add(vbox) win.show_all() - def add_item_dlg(self, widget): - dlg = gtk.Dialog(title='Add to portfolio', parent=None, flags=0) + def edit_toggled(self, widget, tv): + if widget.get_active(): + tv.disconnect(self.quotes_id) + self.edit_id = tv.connect("row-activated", + self.edit_portfolio_item, self.portfolio_model) + else: + tv.disconnect(self.edit_id) + self.quotes_id = tv.connect("row-activated", + self.show_quotes_view, self.portfolio_model, True) + + def edit_portfolio_item(self, widget, path, column, model): + seliter = model.get_iter(path) + + symbol = model[path][0] + name = model[path][1] + shares = model[path][2] + + data = [shares, symbol, name] + self.add_item_dlg(widget, data, seliter) + + def add_item_dlg(self, widget, data, seliter): + if data: + shares = data[0] + symbol = data[1] + name = data[2] + title = "Edit item from portfolio" + btntext = "Edit" + edit = True + else: + shares = "0" + symbol = "" + name = "" + title = "Add to portfolio" + btntext = "Add" + edit = False + + dlg = gtk.Dialog(title=title, parent=None, flags=0) dlg.set_has_separator(False) button1 = hildon.PickerButton(fhsize, horbtn) @@ -834,31 +1060,35 @@ class StocksPy: selector = self.create_selector(data, True) button1.set_selector(selector) button1.set_title("Your shares") - button1.set_value("0") + button1.set_value(shares) dlg.vbox.pack_start(button1, False, False, 0) entry1 = hildon.Entry(fhsize) + entry1.set_text(name) entry2 = hildon.Entry(fhsize) + entry2.set_text(symbol) entry1.set_placeholder("Name") - entry1.connect("activate", self.add_item, dlg, button1, entry1, entry2) + entry1.connect("activate", self.add_item, dlg, button1, entry1, + entry2, edit, seliter) dlg.vbox.pack_start(entry1, False, False, 0) - - entry2.connect("activate", self.add_item, dlg, button1, entry1, entry2) + entry2.connect("activate", self.add_item, dlg, button1, entry1, + entry2, edit, seliter) entry2.set_placeholder("Yahoo Finance symbol") dlg.vbox.pack_start(entry2, False, False, 0) button = hildon.Button(fhsize, horbtn) - button.set_label("Add") - button.connect("clicked", self.add_item, dlg, button1, entry1, entry2) + button.set_label(btntext) + button.connect("clicked", self.add_item, dlg, button1, entry1, + entry2, edit, seliter) dlg.vbox.pack_start(button, False, False, 0) dlg.show_all() dlg.run() dlg.destroy() - def add_item(self, widget, dlg, button, entry1, entry2): + def add_item(self, widget, dlg, button, entry1, entry2, edit, seliter): symbol = entry2.get_text() name = entry1.get_text() shares = button.get_value() @@ -870,8 +1100,13 @@ class StocksPy: self.add_to_portfolio(widget, button, symbol, name) dlg.destroy() - niter = self.portfolio_model.append() - self.portfolio_model.set(niter, 0, symbol, 1, name, 2, shares, 3, "-") + if edit: + self.portfolio_model.set(seliter, 0, symbol, 1, name, 2, shares, + 3, "-", 4, "-", 5, "-", 6, "green") + else: + niter = self.portfolio_model.append() + self.portfolio_model.set(niter, 0, symbol, 1, name, 2, shares, + 3, "-", 4, "-", 5, "-", 6, "green") def remove_item(self, widget): win = hildon.StackableWindow()