Mercurial > code > home > repos > light9
annotate bin/gyrocontroller @ 272:460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
author | David McClosky <dmcc@bigasterisk.com> |
---|---|
date | Fri, 17 Jun 2005 07:00:51 +0000 |
parents | 97c08a1c4351 |
children | 3b73f0a58a54 |
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 |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
5 from light9.Submaster import Submasters, Submaster, 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 |
272
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
7 import light9.Patch as Patch |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
8 |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
9 import Tix as Tk |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
10 |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
11 # TODO: move to Utility? |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
12 class circcycle: |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
13 """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
|
14 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
|
15 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
|
16 iterator, as it tuple'ifies the input.""" |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
17 def __init__(self, sequence): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
18 self.sequence = tuple(sequence) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
19 self.index = None |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
20 def __iter__(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
21 return self |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
22 def change_index(self, delta): |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
23 if self.index is None: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
24 if delta > 0: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
25 self.index = (-1 + delta) % len(self.sequence) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
26 elif delta < 0: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
27 self.index = delta % len(self.sequence) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
28 else: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
29 self.index = (self.index + delta) % len(self.sequence) |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
30 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
|
31 self.change_index(1) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
32 return self.sequence[self.index] |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
33 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
|
34 self.change_index(-1) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
35 return self.sequence[self.index] |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
36 |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
37 class AbstractSimpleController(SubClient): |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
38 """Simple controller with minimal input and output: |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
39 |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
40 Input is 4 directions and 3 buttons. |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
41 Output is an integer and a color and maybe more. |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
42 |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
43 Left + B1/right + B1: prev/next sub |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
44 Y-axis + B3: set current level |
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
45 B2: toggle keep/solo mode |
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
46 Triple-B2: clear kept levels""" |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
47 def __init__(self, subnames): |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
48 SubClient.__init__(self) |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
49 self.subnames = subnames |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
50 self.refresh() |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
51 def get_sub(self, name): |
272
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
52 if name in self.submasters.get_all_sub_names(): |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
53 return self.submasters.get_sub_by_name(name) |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
54 |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
55 try: |
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
56 val = int(name) |
272
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
57 s = Submaster("#%d" % val, {val : 1.0}, temporary=True) |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
58 return s |
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
59 except ValueError: |
272
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
60 pass |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
61 |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
62 try: |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
63 subnum = Patch.get_dmx_channel(name) |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
64 s = Submaster("'%s'" % name, {subnum : 1.0}, temporary=True) |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
65 return s |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
66 except ValueError: |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
67 pass |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
68 |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
69 # make an error sub |
460bc5ebcaaf
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
David McClosky <dmcc@bigasterisk.com>
parents:
271
diff
changeset
|
70 return Submaster('%s!?' % name) |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
71 def refresh(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
72 # reload subs from disk |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
73 self.submasters = Submasters() |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
74 self.all_subs = circcycle(self.subnames) |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
75 self.current_sub = self.get_sub(self.all_subs.next()) |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
76 self.current_level = 1.0 |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
77 self.kept_levels = {} # subname : level [0..1] |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
78 self.keep_solo_mode = 'solo' # either 'keep' or 'solo' |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
79 def clear_kept_levels(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
80 self.kept_levels.clear() |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
81 def next(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
82 if self.keep_solo_mode == 'keep': |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
83 self.kept_levels[self.current_sub] = self.current_level |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
84 |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
85 self.current_sub = self.get_sub(self.all_subs.next()) |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
86 def prev(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
87 if self.keep_solo_mode == 'keep': |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
88 self.kept_levels[self.current_sub] = self.current_level |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
89 |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
90 self.current_sub = self.get_sub(self.all_subs.prev()) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
91 def toggle_keep_mode(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
92 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
|
93 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
|
94 self.keep_solo_mode = 'solo' |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
95 else: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
96 self.keep_solo_mode = 'keep' |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
97 |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
98 def get_levels_as_sub(self): |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
99 if self.keep_solo_mode == 'keep': |
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
100 # send all levels in self.kept_levels |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
101 self.kept_levels[self.current_sub] = self.current_level |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
102 levelsub = combine_subdict(self.kept_levels) |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
103 else: |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
104 levelsub = self.current_sub * self.current_level |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
105 |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
106 return levelsub |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
107 |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
108 class TkGyro(Tk.Canvas, AbstractSimpleController): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
109 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
|
110 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
|
111 confine=None) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
112 AbstractSimpleController.__init__(self, subnames) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
113 height = int(self.winfo_screenheight()) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
114 width = int(self.winfo_screenwidth()) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
115 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
|
116 tags='left', fill='black') |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
117 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
|
118 tags='right', fill='black') |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
119 self.levelbar = self.create_rectangle(0, 0, width, 5, tags='level', |
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
120 fill='yellow', state='disabled', outline='') |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
121 |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
122 # 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
|
123 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
|
124 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
|
125 state='disabled') |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
126 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
|
127 |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
128 def setfill(item, color): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
129 self.itemconfig(item, fill=color) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
130 def setlevel(evt): |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
131 if evt.state & 0x400 or evt.num == 3: |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
132 y = (height - evt.y) / float(height) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
133 self.flash_text('<%d>' % (y * 100)) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
134 self.current_level = y |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
135 self.coords(self.levelbar, 0, evt.y, width, evt.y + 5) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
136 self.send_levels() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
137 |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
138 data = ((self.left, 'left', 'blue', self.prev), |
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
139 (self.right, 'right', 'red', self.next)) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
140 for item, tag, color, method in data: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
141 self.tag_bind(tag, '<Enter>', |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
142 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
|
143 self.tag_bind(tag, '<Leave>', |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
144 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
|
145 self.tag_bind(tag, '<ButtonPress-1>', |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
146 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
|
147 self.tag_bind(tag, '<ButtonRelease-1>', |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
148 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
|
149 self.tag_bind(tag, '<Button-1>', |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
150 lambda evt, method=method: method(), '+') |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
151 |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
152 # 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
|
153 self.tag_bind('all', '<Motion>', setlevel, '+') |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
154 self.tag_bind('all', '<ButtonPress-3>', setlevel, '+') |
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
155 self.tag_bind('all', '<Triple-Button-2>', |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
156 lambda evt: self.clear_kept_levels()) |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
157 # B3 toggles between keep and solo mode |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
158 self.tag_bind('all', '<Button-2>', lambda evt: self.toggle_keep_mode()) |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
159 |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
160 self.send_levels_loop() |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
161 def toggle_keep_mode(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
162 AbstractSimpleController.toggle_keep_mode(self) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
163 self.show_current_mode() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
164 self.send_levels() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
165 def show_current_mode(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
166 if self.keep_solo_mode == 'keep': |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
167 self.keep_solo_mode = 'keep' |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
168 else: |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
169 self.keep_solo_mode = '' |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
170 |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
171 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
|
172 def clear_kept_levels(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
173 AbstractSimpleController.clear_kept_levels(self) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
174 self.flash_text('cleared') |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
175 self.send_levels() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
176 def flash_text(self, text): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
177 self.itemconfig(self.modetext, text=text) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
178 self.after_cancel(self.flashtextafter) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
179 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
|
180 def next(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
181 AbstractSimpleController.next(self) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
182 self.flash_text(self.current_sub.name) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
183 self.send_levels() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
184 def prev(self): |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
185 AbstractSimpleController.prev(self) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
186 self.flash_text(self.current_sub.name) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
187 self.send_levels() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
188 |
246
89cd37c4314b
gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff
changeset
|
189 if __name__ == "__main__": |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
190 import sys, fileinput |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
191 subnames = sys.argv[1:] |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
192 if not subnames: |
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
193 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
|
194 |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
195 root = Tk.Tk() |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
196 # 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
|
197 # Style "*NOTITLE*" NoTitle |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
198 # Style "*NOBORDER*" BorderWidth 0, NoHandles |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
199 # Style "*ONTOP*" StaysOnTop Sticky |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
200 # 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
|
201 root.title("NOTITLE NOBORDER ONTOP") |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
202 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
|
203 root.winfo_screenheight())) |
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
204 |
258
c9940e4e68d6
TkGyro: read subs from argv or stdin, cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
257
diff
changeset
|
205 gyro = TkGyro(root, subnames) |
255
6f6d9235e8a0
TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents:
254
diff
changeset
|
206 gyro.pack(fill='both', expand=1) |
271
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
207 def quit(event): |
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
208 gyro.send_zeroes() |
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
209 root.destroy() |
97c08a1c4351
gyrocontroller: remap buttons, fix keep mode
David McClosky <dmcc@bigasterisk.com>
parents:
259
diff
changeset
|
210 root.bind('<Key-q>', quit) |
257
e50e87f1103f
TkGyro: now really goes fullscreen
David McClosky <dmcc@bigasterisk.com>
parents:
256
diff
changeset
|
211 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
|
212 Tk.mainloop() |