Changeset - c9940e4e68d6
[Not reviewed]
default
0 1 0
David McClosky - 20 years ago 2005-06-16 05:16:30
dmcc@bigasterisk.com
TkGyro: read subs from argv or stdin, cleanups
Some documentation and code reorganization/cleanups
1 file changed with 18 insertions and 14 deletions:
0 comments (0 inline, 0 general)
bin/gyrocontroller
Show inline comments
 
@@ -84,26 +84,24 @@ class AbstractSimpleController(SubClient
 

	
 
class TkGyro(Tk.Canvas, AbstractSimpleController):
 
    def __init__(self, master, subnames):
 
        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),
 
            tags='left', fill='black')
 
        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)
 
        def setlevel(evt):
 
            if evt.state & 512:
 
                y = (height - evt.y) / float(height)
 
@@ -121,17 +119,21 @@ class TkGyro(Tk.Canvas, AbstractSimpleCo
 
            self.tag_bind(tag, '<ButtonPress-1>', 
 
                lambda evt, item=item, color=color: setfill(item, 'green'), '+')
 
            self.tag_bind(tag, '<ButtonRelease-1>', 
 
                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>', 
 

	
 
        # 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()
 
        self.send_levels()
 
    def show_current_mode(self):
 
        if self.keep_solo_mode == 'keep':
 
@@ -155,24 +157,26 @@ class TkGyro(Tk.Canvas, AbstractSimpleCo
 
    def prev(self):
 
        AbstractSimpleController.prev(self)
 
        self.flash_text(self.current_sub.name)
 
        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()
0 comments (0 inline, 0 general)