Commits

Jason Scheirer committed 0129943

Curses skeleton

Comments (0)

Files changed (1)

+import curses
+import datetime
+from bikesniff import gpsfix, networks
+
+class CursesUI(object):
+    def __init__(self):
+        self.stdscr = curses.initscr()
+        curses.start_color()
+        import twisted.internet.reactor
+        self.reactor = twisted.internet.reactor
+        self.reactor.callLater(0, self.update)
+        curses.noecho()
+        curses.cbreak()
+        self.stdscr.keypad(1)
+        self.stdscr.nodelay(1)
+    def shutdown(self):
+        curses.nocbreak()
+        self.stdscr.keypad(0)
+        curses.echo()
+        curses.endwin()
+    def update(self):
+        try:
+            self.stdscr.addstr(0, 0, str(datetime.datetime.now()), curses.A_BOLD)
+            curses.setsyx(self.stdscr.height, self.stdscr.width)
+            self.stdscr.refresh()
+        except:
+            pass
+        finally:
+            if self.stdscr.getch() in (27, ord('q'), ord('Q')):
+                self.shutdown()
+                self.reactor.stop()
+            else:
+                self.reactor.callLater(0.5, self.update)
+
+if __name__ == "__main__":
+    import dbus.mainloop.glib
+    import gobject
+    from twisted.internet import glib2reactor
+
+    glib2reactor.install()
+    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+    import twisted.internet.reactor
+    netlist = networks.NetworkList()
+    gps = gpsfix.GpsD(twisted.internet.reactor)
+    
+    ui = CursesUI()
+
+    twisted.internet.reactor.run()