Mercurial > code > home > repos > light9
comparison bin/gyrocontroller @ 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 |
comparison
equal
deleted
inserted
replaced
257:e50e87f1103f | 258:c9940e4e68d6 |
---|---|
85 class TkGyro(Tk.Canvas, AbstractSimpleController): | 85 class TkGyro(Tk.Canvas, AbstractSimpleController): |
86 def __init__(self, master, subnames): | 86 def __init__(self, master, subnames): |
87 Tk.Canvas.__init__(self, master, bg='black', bd=0, highlightthickness=0, | 87 Tk.Canvas.__init__(self, master, bg='black', bd=0, highlightthickness=0, |
88 confine=None) | 88 confine=None) |
89 AbstractSimpleController.__init__(self, subnames) | 89 AbstractSimpleController.__init__(self, subnames) |
90 self.send_levels_loop() | |
91 def pack(self, *args, **kw): | |
92 Tk.Canvas.pack(self, *args, **kw) | |
93 height = int(self.winfo_screenheight()) | 90 height = int(self.winfo_screenheight()) |
94 width = int(self.winfo_screenwidth()) | 91 width = int(self.winfo_screenwidth()) |
95 self.left = self.create_rectangle((0, 0, width / 2, height), | 92 self.left = self.create_rectangle((0, 0, width / 2, height), |
96 tags='left', fill='black') | 93 tags='left', fill='black') |
97 self.right = self.create_rectangle((width / 2, 0, width, height), | 94 self.right = self.create_rectangle((width / 2, 0, width, height), |
98 tags='right', fill='black') | 95 tags='right', fill='black') |
99 | 96 |
97 # the text is disabled so that it doesn't receive events | |
100 self.modetext = self.create_text((width / 2, height / 2), | 98 self.modetext = self.create_text((width / 2, height / 2), |
101 font='Courier 200', fill='white', text=self.keep_solo_mode, | 99 font='Courier 200', fill='white', text=self.keep_solo_mode, |
102 tags='middle', state='disabled') | 100 state='disabled') |
103 self.flashtextafter = '' | 101 self.flashtextafter = '' # current after timer for displaying text |
104 | 102 |
105 def setfill(item, color): | 103 def setfill(item, color): |
106 self.itemconfig(item, fill=color) | 104 self.itemconfig(item, fill=color) |
107 def setlevel(evt): | 105 def setlevel(evt): |
108 if evt.state & 512: | 106 if evt.state & 512: |
122 lambda evt, item=item, color=color: setfill(item, 'green'), '+') | 120 lambda evt, item=item, color=color: setfill(item, 'green'), '+') |
123 self.tag_bind(tag, '<ButtonRelease-1>', | 121 self.tag_bind(tag, '<ButtonRelease-1>', |
124 lambda evt, item=item, color=color: setfill(item, color), '+') | 122 lambda evt, item=item, color=color: setfill(item, color), '+') |
125 self.tag_bind(tag, '<Button-1>', | 123 self.tag_bind(tag, '<Button-1>', |
126 lambda evt, method=method: method(), '+') | 124 lambda evt, method=method: method(), '+') |
127 self.tag_bind(tag, '<Motion>', setlevel, '+') | 125 |
128 self.tag_bind(tag, '<Button-3>', | 126 # B2+drag sets current level, double-B2 resets kept levels |
129 lambda evt: self.toggle_keep_mode()) | 127 self.tag_bind('all', '<Motion>', setlevel, '+') |
130 self.tag_bind(tag, '<Double-Button-2>', | 128 self.tag_bind('all', '<Double-Button-2>', |
131 lambda evt: self.clear_kept_levels()) | 129 lambda evt: self.clear_kept_levels()) |
130 # B3 toggles between keep and solo mode | |
131 self.tag_bind('all', '<Button-3>', lambda evt: self.toggle_keep_mode()) | |
132 | |
133 self.send_levels_loop() | |
132 def toggle_keep_mode(self): | 134 def toggle_keep_mode(self): |
133 AbstractSimpleController.toggle_keep_mode(self) | 135 AbstractSimpleController.toggle_keep_mode(self) |
134 self.show_current_mode() | 136 self.show_current_mode() |
135 self.send_levels() | 137 self.send_levels() |
136 def show_current_mode(self): | 138 def show_current_mode(self): |
156 AbstractSimpleController.prev(self) | 158 AbstractSimpleController.prev(self) |
157 self.flash_text(self.current_sub.name) | 159 self.flash_text(self.current_sub.name) |
158 self.send_levels() | 160 self.send_levels() |
159 | 161 |
160 if __name__ == "__main__": | 162 if __name__ == "__main__": |
163 import sys, fileinput | |
164 subnames = sys.argv[1:] | |
165 if not subnames: | |
166 subnames = [line.strip() for line in fileinput.input()] | |
167 | |
161 root = Tk.Tk() | 168 root = Tk.Tk() |
162 | |
163 # these are hints to Fvwm2 if you add this to your .fvwm2rc: | 169 # these are hints to Fvwm2 if you add this to your .fvwm2rc: |
164 # Style "*NOTITLE*" NoTitle | 170 # Style "*NOTITLE*" NoTitle |
165 # Style "*NOBORDER*" BorderWidth 0, NoHandles | 171 # Style "*NOBORDER*" BorderWidth 0, NoHandles |
166 # Style "*ONTOP*" StaysOnTop Sticky | 172 # Style "*ONTOP*" StaysOnTop Sticky |
173 # hopefully, there's a better way to do this within Tk | |
167 root.title("NOTITLE NOBORDER ONTOP") | 174 root.title("NOTITLE NOBORDER ONTOP") |
168 | |
169 # for some reason, this doesn't make it fill the screen | |
170 root.wm_geometry('%sx%s' % (root.winfo_screenwidth(), | 175 root.wm_geometry('%sx%s' % (root.winfo_screenwidth(), |
171 root.winfo_screenheight())) | 176 root.winfo_screenheight())) |
172 | 177 |
173 gyro = TkGyro(root, [str(i) for i in range(1, 11)]) | 178 gyro = TkGyro(root, subnames) |
174 gyro.pack(fill='both', expand=1) | 179 gyro.pack(fill='both', expand=1) |
175 gyro.focus_get() | |
176 root.bind('<Key-q>', lambda evt: root.destroy()) | 180 root.bind('<Key-q>', lambda evt: root.destroy()) |
177 root.maxsize(root.winfo_screenwidth(), root.winfo_screenheight()) | 181 root.maxsize(root.winfo_screenwidth(), root.winfo_screenheight()) |
178 Tk.mainloop() | 182 Tk.mainloop() |