]> Pileus Git - ~andy/csm213a-hw/blobdiff - vis/visual.py
Support Python 2.7 and GTK+2
[~andy/csm213a-hw] / vis / visual.py
index 978eb977a7d7fde4173f96f61c7854ef66c7c64a..5580b5b47700c80359c733d69aade5b32d1fa01a 100644 (file)
@@ -1,7 +1,19 @@
 #!/usr/bin/env python
 
-from gi.repository import Gtk
-from gi.repository import GLib
+import sys
+
+if sys.version_info<(3,0,0):
+       import pygtk as PyGtk
+       import gtk   as Gtk
+       import gtk   as GLib
+else:
+       from gi.repository import Gtk
+       from gi.repository import GLib
+
+if sys.version_info<(3,0,0):
+       ICON_SIZE_BUTTON = Gtk.ICON_SIZE_BUTTON
+else:
+       ICON_SIZE_BUTTON = Gtk.IconSize.BUTTON
 
 class Visual:
        def __init__(self, config, device, logger):
@@ -142,7 +154,7 @@ class Visual:
                        con = self.builder.get_object(name + '_con')
                        img = Gtk.STOCK_YES if state else Gtk.STOCK_NO
                        btn.set_active(state)
-                       con.set_from_stock(img, Gtk.IconSize.BUTTON)
+                       con.set_from_stock(img, ICON_SIZE_BUTTON)
 
                check(self.device.running(), "serial")
                check(self.logger.running(), "xively")