gnome-applets r10798 - trunk/invest-applet/invest
- From: callum svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-applets r10798 - trunk/invest-applet/invest
- Date: Mon, 14 Apr 2008 21:28:52 +0100 (BST)
Author: callum
Date: Mon Apr 14 21:28:52 2008
New Revision: 10798
URL: http://svn.gnome.org/viewvc/gnome-applets?rev=10798&view=rev
Log:
Restore the externally-visible indicator of stock health to the invest applet.
Modified:
trunk/invest-applet/invest/applet.py
trunk/invest-applet/invest/quotes.py
Modified: trunk/invest-applet/invest/applet.py
==============================================================================
--- trunk/invest-applet/invest/applet.py (original)
+++ trunk/invest-applet/invest/applet.py Mon Apr 14 21:28:52 2008
@@ -28,13 +28,16 @@
applet_icon.show()
evbox.add(applet_icon)
+ self.investments_change_icon = gtk.Image()
+ evbox.add(self.investments_change_icon)
+ self.set_investments_change_icon(0)
self.applet.add(evbox)
self.applet.connect("button-press-event",self.button_clicked)
self.applet.show_all()
self.new_ilw()
def new_ilw(self):
- self.quotes_updater = QuoteUpdater()
+ self.quotes_updater = QuoteUpdater(self.set_investments_change_icon)
self.investwidget = InvestWidget(self.quotes_updater)
self.ilw = InvestmentsListWindow(self.applet, self.investwidget)
@@ -47,11 +50,20 @@
def on_preferences(self, component, verb):
invest.preferences.show_preferences(self)
- self.quotes_updater.refresh()
+ self.ilw.destroy()
+ self.new_ilw()
def on_refresh(self, component, verb):
self.quotes_updater.refresh()
+ def set_investments_change_icon(self, change):
+ if change == 1:
+ self.investments_change_icon.set_from_stock(gtk.STOCK_GO_UP, gtk.ICON_SIZE_MENU)
+ elif change == 0:
+ self.investments_change_icon.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_MENU)
+ else:
+ self.investments_change_icon.set_from_stock(gtk.STOCK_GO_DOWN, gtk.ICON_SIZE_MENU)
+
class InvestmentsListWindow(gtk.Window):
def __init__(self, applet, list):
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
Modified: trunk/invest-applet/invest/quotes.py
==============================================================================
--- trunk/invest-applet/invest/quotes.py (original)
+++ trunk/invest-applet/invest/quotes.py Mon Apr 14 21:28:52 2008
@@ -9,9 +9,10 @@
class QuoteUpdater(gtk.ListStore):
SYMBOL, TICKER_ONLY, BALANCE, BALANCE_PCT, VALUE, VARIATION = range(6)
- def __init__ (self):
+ def __init__ (self, change_icon_callback):
gtk.ListStore.__init__ (self, gobject.TYPE_STRING, bool, float, float, float, float, gtk.gdk.Pixbuf)
gobject.timeout_add(invest.AUTOREFRESH_TIMEOUT, self.refresh)
+ self.change_icon_callback = change_icon_callback
self.refresh()
def refresh(self):
@@ -65,6 +66,11 @@
quote_items = quotes.items ()
quote_items.sort ()
+ simple_quotes_change = 0
+ simple_quotes_count = 0
+ positions_balance = 0
+ positions_count = 0
+
for ticker, val in quote_items:
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 1, 1)
@@ -76,8 +82,11 @@
break
if is_simple_quote:
+ simple_quotes_count += 1
row = self.insert(0, [ticker, True, 0, 0, val["trade"], val["variation"], pb])
+ simple_quotes_change += val['variation']
else:
+ positions_count += 1
current = sum([purchase["amount"]*val["trade"] for purchase in invest.STOCKS[ticker] if purchase["amount"] != 0])
paid = sum([purchase["amount"]*purchase["bought"] + purchase["comission"] for purchase in invest.STOCKS[ticker] if purchase["amount"] != 0])
balance = current - paid
@@ -86,9 +95,16 @@
else:
change = 100 # Not technically correct, but it will look more intuitive than the real result of infinity.
row = self.insert(0, [ticker, False, balance, change, val["trade"], val["variation"], pb])
+ positions_balance += balance
invest.chart.FinancialSparklineChartPixbuf(ticker, self.set_pb_callback, row)
-
+
+ if simple_quotes_count > 0:
+ change = simple_quotes_change/float(simple_quotes_count)
+ self.change_icon_callback(change/abs(change))
+ else:
+ self.change_icon_callback(positions_balance/abs(positions_balance))
+
def set_pb_callback(self, pb, row):
self.set_value(row, 6, pb)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]