changeset 258:c9940e4e68d6

TkGyro: read subs from argv or stdin, cleanups Some documentation and code reorganization/cleanups
author David McClosky <dmcc@bigasterisk.com>
date Thu, 16 Jun 2005 05:16:30 +0000
parents e50e87f1103f
children 60b6471fb0d2
files bin/gyrocontroller
diffstat 1 files changed, 19 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/bin/gyrocontroller	Wed Jun 15 23:54:50 2005 +0000
+++ b/bin/gyrocontroller	Thu Jun 16 05:16:30 2005 +0000
@@ -87,9 +87,6 @@
         Tk.Canvas.__init__(self, master, bg='black', bd=0, highlightthickness=0,
             confine=None)
         AbstractSimpleController.__init__(self, subnames)
-        self.send_levels_loop()
-    def pack(self, *args, **kw):
-        Tk.Canvas.pack(self, *args, **kw)
         height = int(self.winfo_screenheight())
         width = int(self.winfo_screenwidth())
         self.left = self.create_rectangle((0, 0, width / 2, height),
@@ -97,10 +94,11 @@
         self.right = self.create_rectangle((width / 2, 0, width, height),
             tags='right', fill='black')
 
+        # the text is disabled so that it doesn't receive events
         self.modetext = self.create_text((width / 2, height / 2), 
             font='Courier 200', fill='white', text=self.keep_solo_mode,
-            tags='middle', state='disabled')
-        self.flashtextafter = ''
+            state='disabled')
+        self.flashtextafter = '' # current after timer for displaying text
 
         def setfill(item, color):
             self.itemconfig(item, fill=color)
@@ -124,11 +122,15 @@
                 lambda evt, item=item, color=color: setfill(item, color), '+')
             self.tag_bind(tag, '<Button-1>', 
                 lambda evt, method=method: method(), '+')
-            self.tag_bind(tag, '<Motion>', setlevel, '+')
-            self.tag_bind(tag, '<Button-3>', 
-                lambda evt: self.toggle_keep_mode())
-            self.tag_bind(tag, '<Double-Button-2>', 
-                lambda evt: self.clear_kept_levels())
+
+        # B2+drag sets current level, double-B2 resets kept levels
+        self.tag_bind('all', '<Motion>', setlevel, '+')
+        self.tag_bind('all', '<Double-Button-2>', 
+            lambda evt: self.clear_kept_levels())
+        # B3 toggles between keep and solo mode
+        self.tag_bind('all', '<Button-3>', lambda evt: self.toggle_keep_mode())
+
+        self.send_levels_loop()
     def toggle_keep_mode(self):
         AbstractSimpleController.toggle_keep_mode(self)
         self.show_current_mode()
@@ -158,21 +160,23 @@
         self.send_levels()
 
 if __name__ == "__main__":
+    import sys, fileinput
+    subnames = sys.argv[1:] 
+    if not subnames:
+        subnames = [line.strip() for line in fileinput.input()]
+
     root = Tk.Tk()
-
     # these are hints to Fvwm2 if you add this to your .fvwm2rc:
     #   Style "*NOTITLE*"   NoTitle
     #   Style "*NOBORDER*"  BorderWidth 0, NoHandles
     #   Style "*ONTOP*"     StaysOnTop Sticky
+    # hopefully, there's a better way to do this within Tk
     root.title("NOTITLE NOBORDER ONTOP")
-
-    # for some reason, this doesn't make it fill the screen
     root.wm_geometry('%sx%s' % (root.winfo_screenwidth(), 
                                 root.winfo_screenheight()))
 
-    gyro = TkGyro(root, [str(i) for i in range(1, 11)])
+    gyro = TkGyro(root, subnames)
     gyro.pack(fill='both', expand=1)
-    gyro.focus_get()
     root.bind('<Key-q>', lambda evt: root.destroy())
     root.maxsize(root.winfo_screenwidth(), root.winfo_screenheight())
     Tk.mainloop()