Mercurial > code > home > repos > light9
annotate light8/uihelpers.py @ 72:609cb9ae53b1
results of 7.10 rehearsal, rollback broken IO changes
author | dmcc |
---|---|
date | Thu, 11 Jul 2002 15:26:28 +0000 |
parents | ab0be21b549b |
children | 0969d8a6729d |
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 | |
67 | 29 # def toplevelat(x,y,w=None,h=None): |
68 | 30 def toplevelat(name, windowpos=None): |
51
71489bb71528
- Meet Fader. He is going to grow up and be a crossfader some day
dmcc
parents:
47
diff
changeset
|
31 tl = Toplevel() |
67 | 32 |
68 | 33 tl.wm_geometry(windowlocations[name]) |
34 | |
35 # if name in windowpos: | |
36 # tkname, geom = windowpos[name] | |
37 # tl.wm_geometry(geom) | |
38 # windowpos[name] = str(tl), geom | |
67 | 39 |
40 # if w and h: | |
41 # tl.wm_geometry("%dx%d+%d+%d" % (w,h,x,y)) | |
42 # else: | |
43 # tl.wm_geometry("+%d+%d" % (x,y)) | |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
44 return tl |
0 | 45 |
46 def toggle_slider(s): | |
47 if s.get() == 0: | |
48 s.set(100) | |
49 else: | |
50 s.set(0) | |
51 | |
52 # for lambda callbacks | |
53 def printout(t): | |
54 print t | |
58 | 55 |
56 def printevent(ev): | |
57 for k in dir(ev): | |
58 if not k.startswith('__'): | |
59 print k,getattr(ev,k) | |
60 print "" | |
0 | 61 |
58 | 62 def eventtoparent(ev,sequence): |
63 "passes an event to the parent" | |
64 evdict={} | |
65 for x in ['state', 'time', 'y', 'x', 'serial']: | |
66 evdict[x]=getattr(ev,x) | |
67 # evdict['button']=ev.num | |
68 par=ev.widget.winfo_parent() | |
69 if par!=".": | |
70 ev.widget.nametowidget(par).event_generate(sequence,**evdict) | |
71 #else the event made it all the way to the top, unhandled | |
72 | |
0 | 73 def colorlabel(label): |
74 """color a label based on its own text""" | |
75 txt=label['text'] or "0" | |
76 lev=float(txt)/100 | |
77 low=(80,80,180) | |
78 high=(255,55,050) | |
79 out = [int(l+lev*(h-l)) for h,l in zip(high,low)] | |
80 col="#%02X%02X%02X" % tuple(out) | |
81 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
|
82 |
34
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
83 # TODO: get everyone to use this |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
84 def colorfade(low, high, percent): |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
85 '''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
|
86 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
|
87 col="#%02X%02X%02X" % tuple(out) |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
88 return col |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
89 |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
90 def colortotuple(anytkobj, colorname): |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
91 '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
|
92 rgb = anytkobj.winfo_rgb(colorname) |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
30
diff
changeset
|
93 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
|
94 |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
95 class Togglebutton(Button): |
47 | 96 """works like a single radiobutton, but it's a button so the |
97 label's on the button face, not to the side. the optional command | |
98 callback is called on button set, not on unset. takes a variable | |
99 just like a checkbutton""" | |
52 | 100 def __init__(self,parent,variable=None,command=None,downcolor='red',**kw): |
47 | 101 |
102 self.oldcommand = command | |
103 Button.__init__(self,parent,command=self.invoke,**kw) | |
104 | |
105 self._origbkg = self.cget('bg') | |
52 | 106 self.downcolor = downcolor |
47 | 107 |
108 self._variable = variable | |
109 if self._variable: | |
110 self._variable.trace('w',self._varchanged) | |
111 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
|
112 else: |
47 | 113 self._setstate(0) |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
114 |
47 | 115 self.bind("<Return>",self.invoke) |
116 self.bind("<1>",self.invoke) | |
117 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
|
118 |
47 | 119 def _varchanged(self,*args): |
120 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
|
121 |
47 | 122 def invoke(self,*ev): |
123 if self._variable: | |
124 self._variable.set(not self.state) | |
125 else: | |
126 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
|
127 |
47 | 128 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
|
129 self.oldcommand() |
47 | 130 return "break" |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
131 |
47 | 132 def _setstate(self,newstate): |
133 self.state = newstate | |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
134 if newstate: # set |
52 | 135 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
|
136 else: # unset |
47 | 137 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
|
138 return "break" |
47 | 139 |
140 if __name__=='__main__': | |
141 root=Tk() | |
142 root.tk_focusFollowsMouse() | |
143 iv=IntVar() | |
144 def cb(): | |
145 print "cb!" | |
146 t = Togglebutton(root,text="testbutton",command=cb,variable=iv) | |
147 t.pack() | |
148 Entry(root,textvariable=iv).pack() | |
149 root.mainloop() |