annotate light8/uihelpers.py @ 112:afbdae5e1359

dmx light output is now via a separate process which light8 talks to. dmx light output is now via a separate process which light8 talks to. other programs can also submit dmx to the server
author drewp
date Wed, 11 Jun 2003 09:36:35 +0000
parents e04f7b552bcd
children 4136e92829e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
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
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
3 from __future__ import nested_scopes
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
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
45b12307c695 Initial revision
drewp
parents:
diff changeset
7
68
57b3c454465a result of 7.8.2002 run-through
dmcc
parents: 67
diff changeset
8 windowlocations = {
57b3c454465a result of 7.8.2002 run-through
dmcc
parents: 67
diff changeset
9 'sub' : '425x738+00+00',
57b3c454465a result of 7.8.2002 run-through
dmcc
parents: 67
diff changeset
10 'console' : '168x24+848+000',
57b3c454465a result of 7.8.2002 run-through
dmcc
parents: 67
diff changeset
11 'leveldisplay' : '144x340+870+400',
57b3c454465a result of 7.8.2002 run-through
dmcc
parents: 67
diff changeset
12 'cuefader' : '314x212+546+741',
57b3c454465a result of 7.8.2002 run-through
dmcc
parents: 67
diff changeset
13 'effect' : '24x24+0963+338',
69
ab0be21b549b result of 7.9.2002 rehearsal
dmcc
parents: 68
diff changeset
14 'stage' : '823x683+37+030',
ab0be21b549b result of 7.9.2002 rehearsal
dmcc
parents: 68
diff changeset
15 'scenes' : '504x198+462+12',
68
57b3c454465a result of 7.8.2002 run-through
dmcc
parents: 67
diff changeset
16 }
57b3c454465a result of 7.8.2002 run-through
dmcc
parents: 67
diff changeset
17
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
18 def make_frame(parent):
102
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
19 f = Frame(parent, bd=0, bg='black')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
20 f.pack(side='left')
45b12307c695 Initial revision
drewp
parents:
diff changeset
21 return f
45b12307c695 Initial revision
drewp
parents:
diff changeset
22
45b12307c695 Initial revision
drewp
parents:
diff changeset
23 def bindkeys(root,key, func):
45b12307c695 Initial revision
drewp
parents:
diff changeset
24 root.bind(key, func)
45b12307c695 Initial revision
drewp
parents:
diff changeset
25 for w in root.winfo_children():
45b12307c695 Initial revision
drewp
parents:
diff changeset
26 w.bind(key, func)
45b12307c695 Initial revision
drewp
parents:
diff changeset
27
84
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
28
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
29 def toplevel_savegeometry(tl,name):
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
30 try:
90
d34a4956417a rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents: 84
diff changeset
31 geo = tl.geometry()
d34a4956417a rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents: 84
diff changeset
32 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
33 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
34 f.write(tl.geometry())
d34a4956417a rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents: 84
diff changeset
35 # else the window never got mapped
84
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
36 except:
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
37 # it's ok if there's no saved geometry
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
38 pass
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
39
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
40 # this would get called repeatedly for each child of the window (i
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
41 # dont know why) so we unbind after the first Destroy event
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
42 tl.unbind("<Destroy>",tl._toplevelat_funcid)
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
43
78
0969d8a6729d support for external sliders. fill in ExternalInput with real IO
dmcc
parents: 69
diff changeset
44 def toplevelat(name):
51
71489bb71528 - Meet Fader. He is going to grow up and be a crossfader some day
dmcc
parents: 47
diff changeset
45 tl = Toplevel()
67
0bf7e664f913 window pos saving
dmcc
parents: 61
diff changeset
46
84
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
47 try:
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
48 f=open(".light9-window-geometry-%s" % name.replace(' ','_'))
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
49 windowlocations[name]=f.read() # file has no newline
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
50 except:
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
51 # it's ok if there's no saved geometry
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
52 pass
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
53
78
0969d8a6729d support for external sliders. fill in ExternalInput with real IO
dmcc
parents: 69
diff changeset
54 if name in windowlocations:
84
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
55 tl.geometry(windowlocations[name])
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
56
09b3bf8a9201 fixed window geometry finally
drewp
parents: 78
diff changeset
57 tl._toplevelat_funcid=tl.bind("<Destroy>",lambda ev,tl=tl,name=name: toplevel_savegeometry(tl,name))
68
57b3c454465a result of 7.8.2002 run-through
dmcc
parents: 67
diff changeset
58
12
7adc65771676 big restructuring - moved lots of things (including most panels) to other files
drewp
parents: 0
diff changeset
59 return tl
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
60
45b12307c695 Initial revision
drewp
parents:
diff changeset
61 def toggle_slider(s):
45b12307c695 Initial revision
drewp
parents:
diff changeset
62 if s.get() == 0:
45b12307c695 Initial revision
drewp
parents:
diff changeset
63 s.set(100)
45b12307c695 Initial revision
drewp
parents:
diff changeset
64 else:
45b12307c695 Initial revision
drewp
parents:
diff changeset
65 s.set(0)
45b12307c695 Initial revision
drewp
parents:
diff changeset
66
45b12307c695 Initial revision
drewp
parents:
diff changeset
67 # for lambda callbacks
45b12307c695 Initial revision
drewp
parents:
diff changeset
68 def printout(t):
45b12307c695 Initial revision
drewp
parents:
diff changeset
69 print t
58
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
70
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
71 def printevent(ev):
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
72 for k in dir(ev):
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
73 if not k.startswith('__'):
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
74 print k,getattr(ev,k)
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
75 print ""
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
76
58
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
77 def eventtoparent(ev,sequence):
102
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
78 "passes an event to the parent, screws up TixComboBoxes"
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
79
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
80 wid_class = str(ev.widget.__class__)
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
81 if wid_class == 'Tix.ComboBox' or wid_class == 'Tix.TixSubWidget':
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
82 return
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
83
58
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
84 evdict={}
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
85 for x in ['state', 'time', 'y', 'x', 'serial']:
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
86 evdict[x]=getattr(ev,x)
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
87 # evdict['button']=ev.num
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
88 par=ev.widget.winfo_parent()
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
89 if par!=".":
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
90 ev.widget.nametowidget(par).event_generate(sequence,**evdict)
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
91 #else the event made it all the way to the top, unhandled
a4d000f759b4 new event handling utils
drewp
parents: 52
diff changeset
92
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
93 def colorlabel(label):
45b12307c695 Initial revision
drewp
parents:
diff changeset
94 """color a label based on its own text"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
95 txt=label['text'] or "0"
45b12307c695 Initial revision
drewp
parents:
diff changeset
96 lev=float(txt)/100
45b12307c695 Initial revision
drewp
parents:
diff changeset
97 low=(80,80,180)
45b12307c695 Initial revision
drewp
parents:
diff changeset
98 high=(255,55,050)
45b12307c695 Initial revision
drewp
parents:
diff changeset
99 out = [int(l+lev*(h-l)) for h,l in zip(high,low)]
45b12307c695 Initial revision
drewp
parents:
diff changeset
100 col="#%02X%02X%02X" % tuple(out)
45b12307c695 Initial revision
drewp
parents:
diff changeset
101 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
102
34
411de8b46aef the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents: 30
diff changeset
103 # TODO: get everyone to use this
411de8b46aef the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents: 30
diff changeset
104 def colorfade(low, high, percent):
411de8b46aef the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents: 30
diff changeset
105 '''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
106 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
107 col="#%02X%02X%02X" % tuple(out)
411de8b46aef the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents: 30
diff changeset
108 return col
411de8b46aef the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents: 30
diff changeset
109
411de8b46aef the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents: 30
diff changeset
110 def colortotuple(anytkobj, colorname):
411de8b46aef the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents: 30
diff changeset
111 '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
112 rgb = anytkobj.winfo_rgb(colorname)
411de8b46aef the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents: 30
diff changeset
113 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
114
30
e9d2e7754fd9 sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents: 26
diff changeset
115 class Togglebutton(Button):
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
116 """works like a single radiobutton, but it's a button so the
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
117 label's on the button face, not to the side. the optional command
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
118 callback is called on button set, not on unset. takes a variable
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
119 just like a checkbutton"""
52
065896b0913c emergency commit
dmcc
parents: 51
diff changeset
120 def __init__(self,parent,variable=None,command=None,downcolor='red',**kw):
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
121
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
122 self.oldcommand = command
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
123 Button.__init__(self,parent,command=self.invoke,**kw)
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
124
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
125 self._origbkg = self.cget('bg')
52
065896b0913c emergency commit
dmcc
parents: 51
diff changeset
126 self.downcolor = downcolor
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
127
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
128 self._variable = variable
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
129 if self._variable:
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
130 self._variable.trace('w',self._varchanged)
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
131 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
132 else:
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
133 self._setstate(0)
30
e9d2e7754fd9 sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents: 26
diff changeset
134
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
135 self.bind("<Return>",self.invoke)
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
136 self.bind("<1>",self.invoke)
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
137 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
138
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
139 def _varchanged(self,*args):
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
140 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
141
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
142 def invoke(self,*ev):
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
143 if self._variable:
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
144 self._variable.set(not self.state)
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
145 else:
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
146 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
147
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
148 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
149 self.oldcommand()
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
150 return "break"
30
e9d2e7754fd9 sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents: 26
diff changeset
151
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
152 def _setstate(self,newstate):
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
153 self.state = newstate
30
e9d2e7754fd9 sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents: 26
diff changeset
154 if newstate: # set
52
065896b0913c emergency commit
dmcc
parents: 51
diff changeset
155 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
156 else: # unset
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
157 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
158 return "break"
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
159
95
d5deeed83228 FancyDoubleVar is a DoubleVar where you can temporarily disable the callbacks
drewp
parents: 90
diff changeset
160
d5deeed83228 FancyDoubleVar is a DoubleVar where you can temporarily disable the callbacks
drewp
parents: 90
diff changeset
161 class FancyDoubleVar(DoubleVar):
d5deeed83228 FancyDoubleVar is a DoubleVar where you can temporarily disable the callbacks
drewp
parents: 90
diff changeset
162 def __init__(self,master=None):
d5deeed83228 FancyDoubleVar is a DoubleVar where you can temporarily disable the callbacks
drewp
parents: 90
diff changeset
163 DoubleVar.__init__(self,master)
101
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
164 self.callbacklist = {} # cbname : mode
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
165 self.namedtraces = {} # name : cbname
95
d5deeed83228 FancyDoubleVar is a DoubleVar where you can temporarily disable the callbacks
drewp
parents: 90
diff changeset
166 def trace_variable(self,mode,callback):
97
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
167 """Define a trace callback for the variable.
95
d5deeed83228 FancyDoubleVar is a DoubleVar where you can temporarily disable the callbacks
drewp
parents: 90
diff changeset
168
97
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
169 MODE is one of "r", "w", "u" for read, write, undefine.
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
170 CALLBACK must be a function which is called when
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
171 the variable is read, written or undefined.
95
d5deeed83228 FancyDoubleVar is a DoubleVar where you can temporarily disable the callbacks
drewp
parents: 90
diff changeset
172
97
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
173 Return the name of the callback.
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
174 """
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
175 cbname = self._master._register(callback)
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
176 self._tk.call("trace", "variable", self._name, mode, cbname)
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
177
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
178 # we build a list of the trace callbacks (the py functrions and the tcl functionnames)
101
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
179 self.callbacklist[cbname] = mode
98
57319ec2bfad tracing etc seems to work
drewp
parents: 97
diff changeset
180 # print "added trace:",callback,cbname
97
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
181
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
182 return cbname
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
183 trace=trace_variable
95
d5deeed83228 FancyDoubleVar is a DoubleVar where you can temporarily disable the callbacks
drewp
parents: 90
diff changeset
184 def disable_traces(self):
97
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
185 for cb,mode in self.callbacklist.items():
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
186 # DoubleVar.trace_vdelete(self,v[0],k)
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
187 self._tk.call("trace", "vdelete", self._name, mode,cb)
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
188 # but no master delete!
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
189
95
d5deeed83228 FancyDoubleVar is a DoubleVar where you can temporarily disable the callbacks
drewp
parents: 90
diff changeset
190 def recreate_traces(self):
97
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
191 for cb,mode in self.callbacklist.items():
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
192 # self.trace_variable(v[0],v[1])
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
193 self._tk.call("trace", "variable", self._name, mode,cb)
139d6ed2fbaa partway through the fancy trace-disabling feature
drewp
parents: 95
diff changeset
194
101
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
195 def trace_named(self, name, callback):
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
196 if name in self.namedtraces:
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
197 print "FancyDoubleVar: already had a trace named %s - replacing it" % name
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
198 self.delete_named(name)
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
199
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
200 cbname = self.trace_variable('w',callback) # this will register in self.callbacklist too
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
201
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
202 self.namedtraces[name] = cbname
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
203 return cbname
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
204
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
205 def delete_named(self, name):
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
206 if name in self.namedtraces:
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
207
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
208 cbname = self.namedtraces[name]
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
209
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
210 self.trace_vdelete('w',cbname)
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
211 #self._tk.call("trace","vdelete",self._name,'w',cbname)
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
212 print "FancyDoubleVar: successfully deleted trace named %s" % name
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
213 else:
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
214 print "FancyDoubleVar: attempted to delete named %s which wasn't set to any function" % name
a995fd1a8f03 result of 7.12 performance
dmcc
parents: 98
diff changeset
215
102
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
216 def get_selection(listbox):
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
217 'Given a listbox, returns first selection as integer'
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
218 selection = int(listbox.curselection()[0]) # blech
e04f7b552bcd - scroll wheel works everywhere
dmcc
parents: 101
diff changeset
219 return selection
95
d5deeed83228 FancyDoubleVar is a DoubleVar where you can temporarily disable the callbacks
drewp
parents: 90
diff changeset
220
47
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
221 if __name__=='__main__':
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
222 root=Tk()
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
223 root.tk_focusFollowsMouse()
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
224 iv=IntVar()
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
225 def cb():
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
226 print "cb!"
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
227 t = Togglebutton(root,text="testbutton",command=cb,variable=iv)
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
228 t.pack()
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
229 Entry(root,textvariable=iv).pack()
2ae11dc56b38 did a nice job with Togglebutton
drewp
parents: 34
diff changeset
230 root.mainloop()