summaryrefslogtreecommitdiff
path: root/invest-applet/invest/chart.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/chart.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/chart.py')
-rw-r--r--invest-applet/invest/chart.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/invest-applet/invest/chart.py b/invest-applet/invest/chart.py
index 358c51df..e13e0686 100644
--- a/invest-applet/invest/chart.py
+++ b/invest-applet/invest/chart.py
@@ -1,7 +1,11 @@
#!/usr/bin/env python
-import gtk, gtk.gdk
-import gobject
+import gi
+gi.require_version("Gtk", "2.0")
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GdkPixbuf
+from gi.repository import GObject
import os
import mate_invest
from gettext import gettext as _
@@ -15,16 +19,16 @@ import time
AUTOREFRESH_TIMEOUT = 20*60*1000 # 15 minutes
# based on http://www.johnstowers.co.nz/blog/index.php/2007/03/12/threading-and-pygtk/
-class _IdleObject(gobject.GObject):
+class _IdleObject(GObject.GObject):
"""
- Override gobject.GObject to always emit signals in the main thread
+ Override GObject.GObject to always emit signals in the main thread
by emmitting on an idle handler
"""
def __init__(self):
- gobject.GObject.__init__(self)
+ GObject.GObject.__init__(self)
def emit(self, *args):
- gobject.idle_add(gobject.GObject.emit,self,*args)
+ GObject.idle_add(GObject.GObject.emit,self,*args)
class ImageRetriever(Thread, _IdleObject):
"""
@@ -33,11 +37,11 @@ class ImageRetriever(Thread, _IdleObject):
"""
__gsignals__ = {
"completed": (
- gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
+ GObject.SignalFlags.RUN_LAST, None, []),
# FIXME: should we be making use of this?
#"progress": (
- # gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
- # gobject.TYPE_FLOAT]) #percent complete
+ # GObject.SignalFlags.RUN_LAST, None, [
+ # GObject.TYPE_FLOAT]) #percent complete
}
def __init__(self, image_url):
@@ -47,12 +51,12 @@ class ImageRetriever(Thread, _IdleObject):
self.retrieved = False
def run(self):
- self.image = gtk.Image()
+ self.image = Gtk.Image()
try: sock = urllib.urlopen(self.image_url, proxies = mate_invest.PROXY)
except Exception, msg:
mate_invest.debug("Error while opening %s: %s" % (self.image_url, msg))
else:
- loader = gtk.gdk.PixbufLoader()
+ loader = GdkPixbuf.PixbufLoader()
loader.connect("closed", lambda loader: self.image.set_from_pixbuf(loader.get_pixbuf()))
loader.write(sock.read())
sock.close()
@@ -107,7 +111,7 @@ class FinancialChart:
win.set_title(_("Financial Chart"))
try:
- pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(join(mate_invest.ART_DATA_DIR, "invest_neutral.svg"), 96,96)
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(join(mate_invest.ART_DATA_DIR, "invest_neutral.svg"), 96,96)
self.ui.get_object("plot").set_from_pixbuf(pixbuf)
except Exception, msg:
mate_invest.debug("Could not load 'invest-neutral.svg' file: %s" % msg)
@@ -241,14 +245,14 @@ class FinancialChart:
def on_autorefresh_toggled(self, autorefresh):
if self.autorefresh_id != 0:
- gobject.source_remove(self.autorefresh_id)
+ GObject.source_remove(self.autorefresh_id)
self.autorefresh_id = 0
if autorefresh.get_active():
- self.autorefresh_id = gobject.timeout_add(AUTOREFRESH_TIMEOUT, self.on_refresh_chart, True)
+ self.autorefresh_id = GObject.timeout_add(AUTOREFRESH_TIMEOUT, self.on_refresh_chart, True)
def show_chart(tickers):
- ui = gtk.Builder();
+ ui = Gtk.Builder();
ui.add_from_file(os.path.join(mate_invest.BUILDER_DATA_DIR, "financialchart.ui"))
chart = FinancialChart(ui)
ui.get_object("s").set_text(' '.join(tickers))