Mercurial > code > home > repos > light9
annotate bin/gyrocontroller @ 267:9de7bbf50267
curvecalc fixes, especially a slowdown of the updates that's working better
author | drewp@bigasterisk.com |
---|---|
date | Fri, 17 Jun 2005 03:49:07 +0000 |
parents | 60b6471fb0d2 |
children | 97c08a1c4351 |
rev | line source |
---|---|
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
2 # vi: syntax=python |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
3 |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
4 import run_local |
254
1546c423b467
Fix bugs introduced in "SubClient created, keyboardcomposer and gyrocontroller use it now"
David McClosky <dmcc@bigasterisk.com>
parents:
253
diff
changeset
|
5 from light9.Submaster import Submasters, combine_subdict |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
6 from light9.subclient import SubClient |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
7 |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
8 import Tix as Tk |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
9 |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
10 # TODO: move to Utility? |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
11 class circcycle: |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
12 """Like itertools.cycle, but with a prev() method too. You lose |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
13 all iterator benefits by using this, since it will store the whole |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
14 sequence/iterator in memory. Also, do not run this on an infinite |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
15 iterator, as it tuple'ifies the input.""" |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
16 def __init__(self, sequence): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
17 self.sequence = tuple(sequence) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
18 self.index = None |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
19 def __iter__(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
20 return self |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
21 def change_index(self, delta): |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
22 if self.index is None: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
23 if delta > 0: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
24 self.index = (-1 + delta) % len(self.sequence) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
25 elif delta < 0: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
26 self.index = delta % len(self.sequence) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
27 else: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
28 self.index = (self.index + delta) % len(self.sequence) |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
29 def next(self): |
254
1546c423b467
Fix bugs introduced in "SubClient created, keyboardcomposer and gyrocontroller use it now"
David McClosky <dmcc@bigasterisk.com>
parents:
253
diff
changeset
|
30 self.change_index(1) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
31 return self.sequence[self.index] |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
32 def prev(self): |
254
1546c423b467
Fix bugs introduced in "SubClient created, keyboardcomposer and gyrocontroller use it now"
David McClosky <dmcc@bigasterisk.com>
parents:
253
diff
changeset
|
33 self.change_index(-1) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
34 return self.sequence[self.index] |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
35 |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
36 class AbstractSimpleController(SubClient): |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
37 """Simple controller with minimal input and output: |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
38 |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
39 Input is 4 directions and 3 buttons. |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
40 Output is an integer and a color and maybe more. |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
41 |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
42 Left + B1/right + B1: prev/next sub |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
43 Y-axis + B2: set current level |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
44 B3: toggle keep/solo mode |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
45 Double-B3: clear kept levels""" |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
46 def __init__(self, subnames): |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
47 SubClient.__init__(self) |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
48 self.subnames = subnames |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
49 self.refresh() |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
50 def refresh(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
51 # reload subs from disk |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
52 self.submasters = Submasters() |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
53 self.all_subs = circcycle(self.subnames) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
54 self.current_sub = self.submasters.get_sub_by_name(self.all_subs.next()) |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
55 self.current_level = 1.0 |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
56 self.kept_levels = {} # subname : level [0..1] |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
57 self.keep_solo_mode = 'keep' # either 'keep' or 'solo' |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
58 def clear_kept_levels(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
59 self.kept_levels.clear() |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
60 def next(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
61 if self.keep_solo_mode == 'keep': |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
62 self.kept_levels[self.current_sub] = self.current_level |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
63 |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
64 self.current_sub = self.submasters.get_sub_by_name(self.all_subs.next()) |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
65 def prev(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
66 if self.keep_solo_mode == 'keep': |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
67 self.kept_levels[self.current_sub] = self.current_level |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
68 |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
69 self.current_sub = self.submasters.get_sub_by_name(self.all_subs.prev()) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
70 def toggle_keep_mode(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
71 if self.keep_solo_mode == 'keep': |
259
60b6471fb0d2
TkGyro: stamp current sub+level when toggling modes
David McClosky <dmcc@bigasterisk.com>
parents:
258
diff
changeset
|
72 self.kept_levels[self.current_sub] = self.current_level |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
73 self.keep_solo_mode = 'solo' |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
74 else: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
75 self.keep_solo_mode = 'keep' |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
76 |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
77 def get_levels_as_sub(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
78 if self.keep_solo_mode == 'keep': |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
79 # send all levels in self.kept_levels |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
80 levelsub = combine_subdict(self.kept_levels) |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
81 else: |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
82 levelsub = self.current_sub * self.current_level |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
83 |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
84 return levelsub |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
85 |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
86 class TkGyro(Tk.Canvas, AbstractSimpleController): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
87 def __init__(self, master, subnames): |
256
e543deec6678
TkGyro: "disable" text so it gets no events now
David McClosky <dmcc@bigasterisk.com>
parents:
255
diff
changeset
|
88 Tk.Canvas.__init__(self, master, bg='black', bd=0, highlightthickness=0, |
e543deec6678
TkGyro: "disable" text so it gets no events now
David McClosky <dmcc@bigasterisk.com>
parents:
255
diff
changeset
|
89 confine=None) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
90 AbstractSimpleController.__init__(self, subnames) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
91 height = int(self.winfo_screenheight()) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
92 width = int(self.winfo_screenwidth()) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
93 self.left = self.create_rectangle((0, 0, width / 2, height), |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
94 tags='left', fill='black') |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
95 self.right = self.create_rectangle((width / 2, 0, width, height), |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
96 tags='right', fill='black') |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
97 |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
98 # the text is disabled so that it doesn't receive events |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
99 self.modetext = self.create_text((width / 2, height / 2), |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
100 font='Courier 200', fill='white', text=self.keep_solo_mode, |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
101 state='disabled') |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
102 self.flashtextafter = '' # current after timer for displaying text |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
103 |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
104 def setfill(item, color): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
105 self.itemconfig(item, fill=color) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
106 def setlevel(evt): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
107 if evt.state & 512: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
108 y = (height - evt.y) / float(height) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
109 self.flash_text('<%d>' % (y * 100)) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
110 self.current_level = y |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
111 self.send_levels() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
112 |
256
e543deec6678
TkGyro: "disable" text so it gets no events now
David McClosky <dmcc@bigasterisk.com>
parents:
255
diff
changeset
|
113 data = ((self.left, 'left', '#000099', self.prev), |
e543deec6678
TkGyro: "disable" text so it gets no events now
David McClosky <dmcc@bigasterisk.com>
parents:
255
diff
changeset
|
114 (self.right, 'right', '#990000', self.next)) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
115 for item, tag, color, method in data: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
116 self.tag_bind(tag, '<Enter>', |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
117 lambda evt, item=item, color=color: setfill(item, color)) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
118 self.tag_bind(tag, '<Leave>', |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
119 lambda evt, item=item, color=color: setfill(item, 'black')) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
120 self.tag_bind(tag, '<ButtonPress-1>', |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
121 lambda evt, item=item, color=color: setfill(item, 'green'), '+') |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
122 self.tag_bind(tag, '<ButtonRelease-1>', |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
123 lambda evt, item=item, color=color: setfill(item, color), '+') |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
124 self.tag_bind(tag, '<Button-1>', |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
125 lambda evt, method=method: method(), '+') |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
126 |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
127 # B2+drag sets current level, double-B2 resets kept levels |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
128 self.tag_bind('all', '<Motion>', setlevel, '+') |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
129 self.tag_bind('all', '<Double-Button-2>', |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
130 lambda evt: self.clear_kept_levels()) |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
131 # B3 toggles between keep and solo mode |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
132 self.tag_bind('all', '<Button-3>', lambda evt: self.toggle_keep_mode()) |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
133 |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
134 self.send_levels_loop() |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
135 def toggle_keep_mode(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
136 AbstractSimpleController.toggle_keep_mode(self) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
137 self.show_current_mode() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
138 self.send_levels() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
139 def show_current_mode(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
140 if self.keep_solo_mode == 'keep': |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
141 self.keep_solo_mode = 'keep' |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
142 else: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
143 self.keep_solo_mode = '' |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
144 |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
145 self.itemconfig(self.modetext, text=self.keep_solo_mode) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
146 def clear_kept_levels(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
147 AbstractSimpleController.clear_kept_levels(self) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
148 self.flash_text('cleared') |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
149 self.send_levels() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
150 def flash_text(self, text): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
151 self.itemconfig(self.modetext, text=text) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
152 self.after_cancel(self.flashtextafter) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
153 self.flashtextafter = self.after(2000, self.show_current_mode) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
154 def next(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
155 AbstractSimpleController.next(self) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
156 self.flash_text(self.current_sub.name) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
157 self.send_levels() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
158 def prev(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
159 AbstractSimpleController.prev(self) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
160 self.flash_text(self.current_sub.name) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
161 self.send_levels() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
162 |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
163 if __name__ == "__main__": |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
164 import sys, fileinput |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
165 subnames = sys.argv[1:] |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
166 if not subnames: |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
167 subnames = [line.strip() for line in fileinput.input()] |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
168 |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
169 root = Tk.Tk() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
170 # these are hints to Fvwm2 if you add this to your .fvwm2rc: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
171 # Style "*NOTITLE*" NoTitle |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
172 # Style "*NOBORDER*" BorderWidth 0, NoHandles |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
173 # Style "*ONTOP*" StaysOnTop Sticky |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
174 # hopefully, there's a better way to do this within Tk |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
175 root.title("NOTITLE NOBORDER ONTOP") |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
176 root.wm_geometry('%sx%s' % (root.winfo_screenwidth(), |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
177 root.winfo_screenheight())) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
178 |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
179 gyro = TkGyro(root, subnames) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
180 gyro.pack(fill='both', expand=1) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
181 root.bind('<Key-q>', lambda evt: root.destroy()) |
257
e50e87f1103f
TkGyro: now really goes fullscreen
David McClosky <dmcc@bigasterisk.com>
parents:
256
diff
changeset
|
182 root.maxsize(root.winfo_screenwidth(), root.winfo_screenheight()) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
183 Tk.mainloop() |