annotate bin/gyrocontroller @ 255:6f6d9235e8a0

TkGyro added to gyrocontroller, seems mostly functional Some bugs that still need to be fixed: - It refuses to go full screen on my machine. - Text in the middle can catch some events, we'd like it to pass them to the rectangles under it.
author David McClosky <dmcc@bigasterisk.com>
date Wed, 15 Jun 2005 20:33:05 +0000
parents 1546c423b467
children e543deec6678
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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':
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
72 self.keep_solo_mode = 'solo'
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
73 else:
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
74 self.keep_solo_mode = 'keep'
253
a92b6d1ac072 SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents: 246
diff changeset
75
246
89cd37c4314b gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
76 def get_levels_as_sub(self):
89cd37c4314b gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
77 if self.keep_solo_mode == 'keep':
89cd37c4314b gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
78 # 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
79 levelsub = combine_subdict(self.kept_levels)
246
89cd37c4314b gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
80 else:
253
a92b6d1ac072 SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents: 246
diff changeset
81 levelsub = self.current_sub * self.current_level
246
89cd37c4314b gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
82
253
a92b6d1ac072 SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents: 246
diff changeset
83 return levelsub
246
89cd37c4314b gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
84
255
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
85 class TkGyro(Tk.Canvas, AbstractSimpleController):
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
86 def __init__(self, master, subnames):
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
87 Tk.Canvas.__init__(self, master, bg='black', bd=0, highlightthickness=0)
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
88 AbstractSimpleController.__init__(self, subnames)
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
89 self.send_levels_loop()
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
90 def pack(self, *args, **kw):
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
91 Tk.Canvas.pack(self, *args, **kw)
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
92 height = int(self.winfo_screenheight())
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
93 width = int(self.winfo_screenwidth())
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
94 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
95 tags='left', fill='black')
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
96 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
97 tags='right', fill='black')
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
98
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,
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
101 tags='middle')
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
102 self.flashtextafter = ''
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
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
113 data = ((self.left, 'left', '#000077', self.prev),
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
114 (self.right, 'right', '#770000', self.next))
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(), '+')
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
126 self.tag_bind(tag, '<Motion>', setlevel, '+')
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
127 self.tag_bind(tag, '<Button-3>',
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
128 lambda evt: self.toggle_keep_mode())
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
129 self.tag_bind(tag, '<Double-Button-2>',
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
130 lambda evt: self.clear_kept_levels())
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
131
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
132 # TODO: the text should pass Enter, Leave, and button-1 events
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
133 # to the rectangle under it
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
134
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
135 self.tag_bind('middle', '<Motion>', setlevel, '+')
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
136 self.tag_bind('middle', '<Button-3>',
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
137 lambda evt: self.toggle_keep_mode())
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
138 self.tag_bind('middle', '<Double-Button-2>',
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
139 lambda evt: self.clear_kept_levels())
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
140 def toggle_keep_mode(self):
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
141 AbstractSimpleController.toggle_keep_mode(self)
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
142 self.show_current_mode()
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
143 self.send_levels()
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
144 def show_current_mode(self):
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
145 if self.keep_solo_mode == 'keep':
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
146 self.keep_solo_mode = 'keep'
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
147 else:
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
148 self.keep_solo_mode = ''
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
149
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
150 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
151 def clear_kept_levels(self):
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
152 AbstractSimpleController.clear_kept_levels(self)
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
153 self.flash_text('cleared')
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
154 self.send_levels()
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
155 def flash_text(self, text):
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
156 self.itemconfig(self.modetext, text=text)
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
157 self.after_cancel(self.flashtextafter)
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
158 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
159 def next(self):
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
160 AbstractSimpleController.next(self)
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
161 self.flash_text(self.current_sub.name)
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
162 self.send_levels()
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
163 def prev(self):
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
164 AbstractSimpleController.prev(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
246
89cd37c4314b gyrocontroller and Submaster.combine_subdict
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
168 if __name__ == "__main__":
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
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
171 # 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
172 # Style "*NOTITLE*" NoTitle
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
173 # Style "*NOBORDER*" BorderWidth 0, NoHandles
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
174 # Style "*ONTOP*" StaysOnTop Sticky
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
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
177 # for some reason, this doesn't make it fill the screen
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
178 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
179 root.winfo_screenheight()))
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
180
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
181 gyro = TkGyro(root, [str(i) for i in range(1, 11)])
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
182 gyro.pack(fill='both', expand=1)
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
183 gyro.focus_get()
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
184 root.bind('<Key-q>', lambda evt: root.destroy())
6f6d9235e8a0 TkGyro added to gyrocontroller, seems mostly functional
David McClosky <dmcc@bigasterisk.com>
parents: 254
diff changeset
185 Tk.mainloop()