summaryrefslogtreecommitdiff
path: root/invest-applet/invest/widgets.py
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2012-12-03 23:48:48 +0100
committerStefano Karapetsas <[email protected]>2012-12-03 23:48:48 +0100
commit540e2e460c8155a22b10c1712eec71c9bf25aea9 (patch)
treefedf92ae6b47340fc4155319c5c978124a17df9e /invest-applet/invest/widgets.py
parentba7f835eb79762dd65356a0722aa3e64ad03decb (diff)
downloadmate-applets-540e2e460c8155a22b10c1712eec71c9bf25aea9.tar.bz2
mate-applets-540e2e460c8155a22b10c1712eec71c9bf25aea9.tar.xz
invest-applet: port to gobject introspection
there is an issue to fix with self.applet.window.get_origin in applet.py
Diffstat (limited to 'invest-applet/invest/widgets.py')
-rw-r--r--invest-applet/invest/widgets.py67
1 files changed, 40 insertions, 27 deletions
diff --git a/invest-applet/invest/widgets.py b/invest-applet/invest/widgets.py
index 0a897e30..d7ff9228 100644
--- a/invest-applet/invest/widgets.py
+++ b/invest-applet/invest/widgets.py
@@ -1,6 +1,13 @@
import os, time
from os.path import *
-import mateapplet, gtk, gtk.gdk, mateconf, gobject, pango
+
+import gi
+gi.require_version("Gtk", "2.0")
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GObject
+from gi.repository import Pango
+
from gettext import gettext as _
import locale
import csv
@@ -35,12 +42,12 @@ MEDIUM = -1
TICKER_TIMEOUT = 10000#3*60*1000#
-class InvestWidget(gtk.TreeView):
+class InvestWidget(Gtk.TreeView):
def __init__(self, quotes_updater):
- gtk.TreeView.__init__(self)
+ Gtk.TreeView.__init__(self)
self.set_property("rules-hint", True)
- self.set_reorderable(True)
- self.set_hover_selection(True)
+# self.set_property("reorderable", True)
+ self.set_property("hover-selection", True)
simple_quotes_only = quotes_updater.simple_quotes_only()
@@ -54,10 +61,10 @@ class InvestWidget(gtk.TreeView):
self._getcelldata_balancepct]
for i, col_name in enumerate(col_names):
if i < 3:
- cell = gtk.CellRendererText()
+ cell = Gtk.CellRendererText()
if i > 0:
cell.set_property("xalign", 1.0)
- column = gtk.TreeViewColumn (col_name, cell)
+ column = Gtk.TreeViewColumn (col_name, cell)
if i == 0:
column.set_sort_column_id(quotes_updater.LABEL)
elif i == 2:
@@ -65,15 +72,15 @@ class InvestWidget(gtk.TreeView):
column.set_cell_data_func(cell, col_cellgetdata_functions[i])
self.append_column(column)
elif i == 3:
- cell_pb = gtk.CellRendererPixbuf()
- column = gtk.TreeViewColumn (col_name, cell_pb, pixbuf=quotes_updater.PB)
+ cell_pb = Gtk.CellRendererPixbuf()
+ column = Gtk.TreeViewColumn (col_name, cell_pb, pixbuf=quotes_updater.PB)
self.append_column(column)
else:
# add the last two column only if we have any positions
if simple_quotes_only == False:
- cell = gtk.CellRendererText()
+ cell = Gtk.CellRendererText()
cell.set_property("xalign", 1.0)
- column = gtk.TreeViewColumn (col_name, cell)
+ column = Gtk.TreeViewColumn (col_name, cell)
if i == 4:
column.set_sort_column_id(quotes_updater.BALANCE)
elif i == 5:
@@ -101,11 +108,17 @@ class InvestWidget(gtk.TreeView):
return locale.format("%+.2f", value, True, True) + " " + currency
- def _getcelldata_label(self, column, cell, model, iter):
- cell.set_property('text', model[iter][model.LABEL])
+ def _getcelldata_label(self, column, cell, model, iter, userdata):
+ label = model[iter][model.LABEL]
+ cell.set_property('text', label)
- def _getcelldata_value(self, column, cell, model, iter):
- cell.set_property('text', self.format_currency(model[iter][model.VALUE], model[iter][model.CURRENCY]))
+ def _getcelldata_value(self, column, cell, model, iter, userdata):
+ value = model[iter][model.VALUE];
+ currency = model[iter][model.CURRENCY];
+ if value == None or currency == None:
+ cell.set_property('text', "")
+ else:
+ cell.set_property('text', self.format_currency(value, currency))
def is_selected(self, model, iter):
m, it = self.get_selection().get_selected()
@@ -120,14 +133,14 @@ class InvestWidget(gtk.TreeView):
intensity = LIGHT
return palette[intensity]
- def _getcelldata_variation(self, column, cell, model, iter):
+ def _getcelldata_variation(self, column, cell, model, iter, userdata):
color = self.get_color(model, iter, model.VARIATION_PCT)
change_pct = self.format_percent(model[iter][model.VARIATION_PCT])
cell.set_property('markup',
"<span foreground='%s'>%s</span>" %
(color, change_pct))
- def _getcelldata_balance(self, column, cell, model, iter):
+ def _getcelldata_balance(self, column, cell, model, iter, userdata):
is_ticker_only = model[iter][model.TICKER_ONLY]
color = self.get_color(model, iter, model.BALANCE)
if is_ticker_only:
@@ -138,7 +151,7 @@ class InvestWidget(gtk.TreeView):
"<span foreground='%s'>%s</span>" %
(color, balance))
- def _getcelldata_balancepct(self, column, cell, model, iter):
+ def _getcelldata_balancepct(self, column, cell, model, iter, userdata):
is_ticker_only = model[iter][model.TICKER_ONLY]
color = self.get_color(model, iter, model.BALANCE_PCT)
if is_ticker_only:
@@ -156,12 +169,12 @@ class InvestWidget(gtk.TreeView):
mate_invest.chart.show_chart([ticker])
-#class InvestTicker(gtk.Label):
+#class InvestTicker(Gtk.Label):
# def __init__(self):
-# gtk.Label.__init__(self, _("Waiting..."))
+# Gtk.Label.__init__(self, _("Waiting..."))
#
# self.quotes = []
-# gobject.timeout_add(TICKER_TIMEOUT, self.scroll_quotes)
+# GObject.timeout_add(TICKER_TIMEOUT, self.scroll_quotes)
#
# get_quotes_updater().connect('quotes-updated', self.on_quotes_update)
#
@@ -188,11 +201,11 @@ class InvestWidget(gtk.TreeView):
#
# return True
#
-#gobject.type_register(InvestTicker)
+#GObject.type_register(InvestTicker)
-class InvestTrend(gtk.Image):
+class InvestTrend(Gtk.Image):
def __init__(self):
- gtk.Image.__init__(self)
+ Gtk.Image.__init__(self)
self.pixbuf = None
self.previous_allocation = (0,0)
self.connect('size-allocate', self.on_size_allocate)
@@ -202,14 +215,14 @@ class InvestTrend(gtk.Image):
if self.previous_allocation == (allocation.width, allocation.height):
return
- self.pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, allocation.height, allocation.height)
+ self.pixbuf = GdkPixbuf.Pixbuf(GdkPixbuf.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:
- color = pango.Color(color)
+ color = Pango.Color(color)
factor = float(0xFF)/0xFFFF
self.pixbuf.fill(
int(color.red*factor)<<24|int(color.green*factor)<<16|int(color.blue*factor)<<8|opacity)
@@ -247,4 +260,4 @@ class InvestTrend(gtk.Image):
self.set_color(color, opacity)
-gobject.type_register(InvestTrend)
+GObject.type_register(InvestTrend)