]> Pileus Git - ~andy/csm213a-hw/commitdiff
Switch to Python 3 and Gtk 3
authorAndy Spencer <andy753421@gmail.com>
Mon, 3 Feb 2014 01:55:14 +0000 (01:55 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 3 Feb 2014 01:55:14 +0000 (01:55 +0000)
vis/config.py
vis/device.py
vis/visual.py

index 79da22307c552a657dae2059da8e5078a953fe3f..71dd99e5e35c98fe9cb8cbb54033541d53783927 100644 (file)
@@ -1,4 +1,4 @@
-from ConfigParser import ConfigParser
+from configparser import ConfigParser
 
 class Config:
        # Attributes
index b729f02fc80ecddca1705cd3cecaa8ba3cf8a770..385a142f1e9d14c4cd3fcf8385b16a9a25af8b27 100644 (file)
@@ -46,12 +46,14 @@ class Device:
 
        def process(self):
                items = []
+               count = 0
+               limit = 100
                while self.serial.readable():
                        try:
-                               char = self.serial.read()
+                               char = self.serial.read().decode()
                        except Exception as ex:
                                char = ''
-                       if char == '':
+                       if len(char) == 0:
                                break
                        if char == '\r' or char == '\n':
                                if len(self.inbuf) == 0:
@@ -62,6 +64,10 @@ class Device:
                                self.inbuf = []
                        else:
                                self.inbuf.append(char)
+                       if count > limit:
+                               print("Eror: exceeded read limit")
+                               break
+                       count += 1
                return items
 
        # Private methods
index 72fb7109c07e0d3602ca035c5401f61af2b0c1fd..5d0ff3976025271bdc1080b62e6440036af9a597 100644 (file)
@@ -1,18 +1,18 @@
 #!/usr/bin/env python
 
-import pygtk
-import gtk
+from gi.repository import Gtk
+from gi.repository import GLib
 
 class Visual:
        def __init__(self, config, device, logger):
                def get_objects(names):
-                       return map(lambda x:
-                               self.builder.get_object(x), names)
+                       return list(map(lambda x:
+                               self.builder.get_object(x), names))
 
                self.config   = config
                self.device   = device
                self.logger   = logger
-               self.builder  = gtk.Builder()
+               self.builder  = Gtk.Builder()
 
                self.builder.add_from_file('visual.ui')
                self.builder.connect_signals(self)
@@ -49,19 +49,19 @@ class Visual:
                return True
 
        def on_enable(self, _):
-               print "Unimplemented: on_enable"
+               print("Unimplemented: on_enable")
                return True
 
        def on_rate(self, _):
-               print "Unimplemented: on_rate"
+               print("Unimplemented: on_rate")
                return True
 
        def on_key(self, win, ev):
                if ev.string == 'q':
-                       gtk.main_quit();
+                       Gtk.main_quit();
 
        def on_destroy(self, win):
-               gtk.main_quit()
+               Gtk.main_quit()
 
         # Methods
        def load_config(self):
@@ -103,12 +103,12 @@ class Visual:
                setabs(self.a2ds,  state.a2d)
 
        def debug(self, state):
-               print 'update: ' + str(state)
-               print '\tacc - ' + str(state.acc)
-               print '\tmag - ' + str(state.mag)
-               print '\tlgt - ' + str(state.light)
-               print '\ttch - ' + str(state.touch)
-               print '\ta2d - ' + str(state.a2d)
+               print('update: ' + str(state))
+               print('\tacc - ' + str(state.acc))
+               print('\tmag - ' + str(state.mag))
+               print('\tlgt - ' + str(state.light))
+               print('\ttch - ' + str(state.touch))
+               print('\ta2d - ' + str(state.a2d))
        
        def timer(self):
                serial = self.builder.get_object("serial_btn")
@@ -116,10 +116,10 @@ class Visual:
 
                if self.device.running():
                        serial.set_active(True)
-                       status.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_BUTTON)
+                       status.set_from_stock(Gtk.STOCK_YES, Gtk.IconSize.BUTTON)
                else:
                        serial.set_active(False)
-                       status.set_from_stock(gtk.STOCK_NO,  gtk.ICON_SIZE_BUTTON)
+                       status.set_from_stock(Gtk.STOCK_NO,  Gtk.IconSize.BUTTON)
                if self.device.running():
                        for item in self.device.process():
                                self.update(item)
@@ -130,8 +130,8 @@ class Visual:
        def run(self):
                self.load_config()
                self.window.show()
-               gtk.timeout_add(1000/60, self.timer)
-               gtk.main()
+               GLib.timeout_add(1000/60, self.timer)
+               Gtk.main()
 
        # Private methods
        def status(self, msg):