[gnome-applets] invest: Make the selection of stocks nicer (hover)
- From: Callum McKenzie <callum src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-applets] invest: Make the selection of stocks nicer (hover)
- Date: Fri, 10 Jul 2009 09:01:24 +0000 (UTC)
commit 3541818f77407b62ce128ecf9dafac344540bd76
Author: Callum McKenzie <callum spooky-possum org>
Date: Fri Jul 10 20:42:50 2009 +1200
invest: Make the selection of stocks nicer (hover)
Patch from Enrico Minack. Bug 508419. I also updated the file that
is checked to detect an uninstalled version since ChangeLog has been
removed. We now use Makefile.am.
invest-applet/invest/invest-applet.py | 22 +++++++++---------
invest-applet/invest/widgets.py | 37 +++++++++++++++++----------------
2 files changed, 30 insertions(+), 29 deletions(-)
---
diff --git a/invest-applet/invest/invest-applet.py b/invest-applet/invest/invest-applet.py
index c16fadd..3991214 100755
--- a/invest-applet/invest/invest-applet.py
+++ b/invest-applet/invest/invest-applet.py
@@ -9,7 +9,7 @@ from os.path import *
# Allow to use uninstalled
def _check(path):
- return exists(path) and isdir(path) and isfile(path+"/ChangeLog")
+ return exists(path) and isdir(path) and isfile(path+"/Makefile.am")
name = join(dirname(__file__), '..')
if _check(name):
@@ -44,16 +44,16 @@ def build_window():
app.set_title(_("Invest Applet"))
app.connect("destroy", gtk.main_quit)
app.set_property('resizable', False)
-
+
applet = gnomeapplet.Applet()
applet_factory(applet, None)
applet.reparent(app)
-
+
app.show_all()
-
+
return app
-
-
+
+
def usage():
print """=== Invest applet: Usage
$ invest-applet [OPTIONS]
@@ -64,10 +64,10 @@ OPTIONS:
-w, --window Launch the applet in a standalone window for test purposes (default=no).
"""
sys.exit()
-
-if __name__ == "__main__":
+
+if __name__ == "__main__":
standalone = False
-
+
try:
opts, args = getopt.getopt(sys.argv[1:], "hdw", ["help", "debug", "window"])
except getopt.GetoptError:
@@ -75,7 +75,7 @@ if __name__ == "__main__":
# no options were passed
opts = []
args = sys.argv[1:]
-
+
for o, a in opts:
if o in ("-h", "--help"):
usage()
@@ -84,7 +84,7 @@ if __name__ == "__main__":
print "Debugging enabled"
elif o in ("-w", "--window"):
standalone = True
-
+
if standalone:
import gnome
gnome.init(invest.defs.PACKAGE, invest.defs.VERSION)
diff --git a/invest-applet/invest/widgets.py b/invest-applet/invest/widgets.py
index 0b491e5..3cc99b2 100644
--- a/invest-applet/invest/widgets.py
+++ b/invest-applet/invest/widgets.py
@@ -42,16 +42,17 @@ class InvestWidget(gtk.TreeView):
gtk.TreeView.__init__(self)
self.set_property("rules-hint", True)
self.set_reorderable(True)
+ self.set_hover_selection(True)
simple_quotes_only = quotes_updater.simple_quotes_only()
# model: SYMBOL, TICKER_ONLY, BALANCE, BALANCE_PCT, VALUE, VARIATION_PCT, PB
# Translators: these words all refer to a stock. Last is short
- # for "last price". Gain is referring to the gain since the
+ # for "last price". Gain is referring to the gain since the
# stock was purchased.
col_names = [_('Ticker'), _('Last'), _('Change %'), _('Chart'), _('Gain'), _('Gain %')]
col_cellgetdata_functions = [self._getcelldata_symbol, self._getcelldata_value,
- self._getcelldata_variation, None, self._getcelldata_balance,
+ self._getcelldata_variation, None, self._getcelldata_balance,
self._getcelldata_balancepct]
for i, col_name in enumerate(col_names):
if i < 3:
@@ -76,7 +77,7 @@ class InvestWidget(gtk.TreeView):
self.connect('row-activated', self.on_row_activated)
self.set_model(quotes_updater)
-
+
def _getcelldata_symbol(self, column, cell, model, iter):
cell.set_property('text', model[iter][model.SYMBOL])
@@ -123,45 +124,45 @@ class InvestWidget(gtk.TreeView):
#class InvestTicker(gtk.Label):
# def __init__(self):
# gtk.Label.__init__(self, _("Waiting..."))
-#
+#
# self.quotes = []
# gobject.timeout_add(TICKER_TIMEOUT, self.scroll_quotes)
-#
+#
# get_quotes_updater().connect('quotes-updated', self.on_quotes_update)
-#
+#
# def on_quotes_update(self, updater):
# self.quotes = []
# updater.foreach(self.update_quote, None)
-#
+#
# def update_quote(self, model, path, iter, user_data):
# color = GREEN
# if model[iter][model.BALANCE] < 0:
# color = RED
-#
+#
# self.quotes.append(
# "%s: <span foreground='%s'>%+.2f (%+.2f%%)</span> %.2f" %
# (model[iter][model.SYMBOL], color, model[iter][model.BALANCE], model[iter][model.BALANCE_PCT], model[iter][model.VALUE]))
-#
+#
# def scroll_quotes(self):
# if len(self.quotes) == 0:
# return True
-#
+#
# q = self.quotes.pop()
# self.set_markup("<span face='Monospace'>%s</span>" % q)
# self.quotes.insert(0, q)
-#
+#
# return True
#
#gobject.type_register(InvestTicker)
-class InvestTrend(gtk.Image):
+class InvestTrend(gtk.Image):
def __init__(self):
gtk.Image.__init__(self)
self.pixbuf = None
self.previous_allocation = (0,0)
self.connect('size-allocate', self.on_size_allocate)
get_quotes_updater().connect('quotes-updated', self.on_quotes_update)
-
+
def on_size_allocate(self, widget, allocation):
if self.previous_allocation == (allocation.width, allocation.height):
return
@@ -169,7 +170,7 @@ class InvestTrend(gtk.Image):
self.pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, allocation.height, allocation.height)
self.set_color("grey")
self.previous_allocation = (allocation.width, allocation.height)
-
+
def set_color(self, color, opacity=0xFF):
if self.pixbuf != None:
try:
@@ -188,16 +189,16 @@ class InvestTrend(gtk.Image):
# Don't count the ticker only symbols in the color-trend
if row[updater.TICKER_ONLY]:
continue
-
+
var = row[updater.VARIATION]/100
now = row[updater.VALUE]
start = now / (1 + var)
-
+
portfolio_number = sum([purchase["amount"] for purchase in invest.STOCKS[row[updater.SYMBOL]]])
start_total += start * portfolio_number
now_total += now * portfolio_number
-
+
day_var = 0
if start_total != 0:
day_var = (now_total - start_total) / start_total * 100
@@ -210,5 +211,5 @@ class InvestTrend(gtk.Image):
color = COLORSCALE_POSITIVE[min(len(COLORSCALE_POSITIVE)-1, abs(color))]
self.set_color(color, opacity)
-
+
gobject.type_register(InvestTrend)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]