Mercurial > code > home > repos > light9
annotate light8/uihelpers.py @ 93:d6c48d2d3bd6
shrunk the useful range of the slider so there won't be any noise at the ends
author | drewp |
---|---|
date | Sat, 13 Jul 2002 03:09:26 +0000 |
parents | d34a4956417a |
children | d5deeed83228 |
rev | line source |
---|---|
0 | 1 """all the tiny tk helper functions""" |
51
71489bb71528
- Meet Fader. He is going to grow up and be a crossfader some day
dmcc
parents:
47
diff
changeset
|
2 |
47 | 3 from __future__ import nested_scopes |
0 | 4 from Tkinter import * |
51
71489bb71528
- Meet Fader. He is going to grow up and be a crossfader some day
dmcc
parents:
47
diff
changeset
|
5 from Tix import * |
34
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
6 from types import StringType |
0 | 7 |
68 | 8 windowlocations = { |
9 'sub' : '425x738+00+00', | |
10 'console' : '168x24+848+000', | |
11 'leveldisplay' : '144x340+870+400', | |
12 'cuefader' : '314x212+546+741', | |
13 'effect' : '24x24+0963+338', | |
69 | 14 'stage' : '823x683+37+030', |
15 'scenes' : '504x198+462+12', | |
16 | |
68 | 17 } |
18 | |
0 | 19 def make_frame(parent): |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
20 f = Frame(parent, bd=0) |
0 | 21 f.pack(side='left') |
22 return f | |
23 | |
24 def bindkeys(root,key, func): | |
25 root.bind(key, func) | |
26 for w in root.winfo_children(): | |
27 w.bind(key, func) | |
28 | |
84 | 29 |
30 def toplevel_savegeometry(tl,name): | |
31 try: | |
90
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
84
diff
changeset
|
32 geo = tl.geometry() |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
84
diff
changeset
|
33 if not geo.startswith("1x1"): |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
84
diff
changeset
|
34 f=open(".light9-window-geometry-%s" % name.replace(' ','_'),'w') |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
84
diff
changeset
|
35 f.write(tl.geometry()) |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
84
diff
changeset
|
36 # else the window never got mapped |
84 | 37 except: |
38 # it's ok if there's no saved geometry | |
39 pass | |
40 | |
41 # this would get called repeatedly for each child of the window (i | |
42 # dont know why) so we unbind after the first Destroy event | |
43 tl.unbind("<Destroy>",tl._toplevelat_funcid) | |
44 | |
78
0969d8a6729d
support for external sliders. fill in ExternalInput with real IO
dmcc
parents:
69
diff
changeset
|
45 def toplevelat(name): |
51
71489bb71528
- Meet Fader. He is going to grow up and be a crossfader some day
dmcc
parents:
47
diff
changeset
|
46 tl = Toplevel() |
67 | 47 |
84 | 48 try: |
49 f=open(".light9-window-geometry-%s" % name.replace(' ','_')) | |
50 windowlocations[name]=f.read() # file has no newline | |
51 except: | |
52 # it's ok if there's no saved geometry | |
53 pass | |
54 | |
78
0969d8a6729d
support for external sliders. fill in ExternalInput with real IO
dmcc
parents:
69
diff
changeset
|
55 if name in windowlocations: |
84 | 56 tl.geometry(windowlocations[name]) |
57 | |
58 tl._toplevelat_funcid=tl.bind("<Destroy>",lambda ev,tl=tl,name=name: toplevel_savegeometry(tl,name)) | |
68 | 59 |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
60 return tl |
0 | 61 |
62 def toggle_slider(s): | |
63 if s.get() == 0: | |
64 s.set(100) | |
65 else: | |
66 s.set(0) | |
67 | |
68 # for lambda callbacks | |
69 def printout(t): | |
70 print t | |
58 | 71 |
72 def printevent(ev): | |
73 for k in dir(ev): | |
74 if not k.startswith('__'): | |
75 print k,getattr(ev,k) | |
76 print "" | |
0 | 77 |
58 | 78 def eventtoparent(ev,sequence): |
79 "passes an event to the parent" | |
80 evdict={} | |
81 for x in ['state', 'time', 'y', 'x', 'serial']: | |
82 evdict[x]=getattr(ev,x) | |
83 # evdict['button']=ev.num | |
84 par=ev.widget.winfo_parent() | |
85 if par!=".": | |
86 ev.widget.nametowidget(par).event_generate(sequence,**evdict) | |
87 #else the event made it all the way to the top, unhandled | |
88 | |
0 | 89 def colorlabel(label): |
90 """color a label based on its own text""" | |
91 txt=label['text'] or "0" | |
92 lev=float(txt)/100 | |
93 low=(80,80,180) | |
94 high=(255,55,050) | |
95 out = [int(l+lev*(h-l)) for h,l in zip(high,low)] | |
96 col="#%02X%02X%02X" % tuple(out) | |
97 label.config(bg=col) | |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
98 |
34
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
99 # TODO: get everyone to use this |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
100 def colorfade(low, high, percent): |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
101 '''not foolproof. make sure 0 < percent < 1''' |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
102 out = [int(l+percent*(h-l)) for h,l in zip(high,low)] |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
103 col="#%02X%02X%02X" % tuple(out) |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
104 return col |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
105 |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
106 def colortotuple(anytkobj, colorname): |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
107 'pass any tk object and a color name, like "yellow"' |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
108 rgb = anytkobj.winfo_rgb(colorname) |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
109 return [v / 256 for v in rgb] |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
110 |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
111 class Togglebutton(Button): |
47 | 112 """works like a single radiobutton, but it's a button so the |
113 label's on the button face, not to the side. the optional command | |
114 callback is called on button set, not on unset. takes a variable | |
115 just like a checkbutton""" | |
52 | 116 def __init__(self,parent,variable=None,command=None,downcolor='red',**kw): |
47 | 117 |
118 self.oldcommand = command | |
119 Button.__init__(self,parent,command=self.invoke,**kw) | |
120 | |
121 self._origbkg = self.cget('bg') | |
52 | 122 self.downcolor = downcolor |
47 | 123 |
124 self._variable = variable | |
125 if self._variable: | |
126 self._variable.trace('w',self._varchanged) | |
127 self._setstate(self._variable.get()) | |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
128 else: |
47 | 129 self._setstate(0) |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
130 |
47 | 131 self.bind("<Return>",self.invoke) |
132 self.bind("<1>",self.invoke) | |
133 self.bind("<space>",self.invoke) | |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
134 |
47 | 135 def _varchanged(self,*args): |
136 self._setstate(self._variable.get()) | |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
137 |
47 | 138 def invoke(self,*ev): |
139 if self._variable: | |
140 self._variable.set(not self.state) | |
141 else: | |
142 self._setstate(not self.state) | |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
143 |
47 | 144 if self.oldcommand and self.state: # call command only when state goes to 1 |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
145 self.oldcommand() |
47 | 146 return "break" |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
147 |
47 | 148 def _setstate(self,newstate): |
149 self.state = newstate | |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
150 if newstate: # set |
52 | 151 self.config(bg=self.downcolor,relief='sunken') |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
152 else: # unset |
47 | 153 self.config(bg=self._origbkg,relief='raised') |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
154 return "break" |
47 | 155 |
156 if __name__=='__main__': | |
157 root=Tk() | |
158 root.tk_focusFollowsMouse() | |
159 iv=IntVar() | |
160 def cb(): | |
161 print "cb!" | |
162 t = Togglebutton(root,text="testbutton",command=cb,variable=iv) | |
163 t.pack() | |
164 Entry(root,textvariable=iv).pack() | |
165 root.mainloop() |