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