comparison light8/uihelpers.py @ 97:139d6ed2fbaa

partway through the fancy trace-disabling feature
author drewp
date Sat, 13 Jul 2002 04:04:33 +0000
parents d5deeed83228
children 57319ec2bfad
comparison
equal deleted inserted replaced
96:d1a1ded20ec7 97:139d6ed2fbaa
157 class FancyDoubleVar(DoubleVar): 157 class FancyDoubleVar(DoubleVar):
158 def __init__(self,master=None): 158 def __init__(self,master=None):
159 DoubleVar.__init__(self,master) 159 DoubleVar.__init__(self,master)
160 self.callbacklist = {} 160 self.callbacklist = {}
161 def trace_variable(self,mode,callback): 161 def trace_variable(self,mode,callback):
162 162 """Define a trace callback for the variable.
163
164 MODE is one of "r", "w", "u" for read, write, undefine.
165 CALLBACK must be a function which is called when
166 the variable is read, written or undefined.
167
168 Return the name of the callback.
169 """
170 cbname = self._master._register(callback)
171 self._tk.call("trace", "variable", self._name, mode, cbname)
172
163 # we build a list of the trace callbacks (the py functrions and the tcl functionnames) 173 # we build a list of the trace callbacks (the py functrions and the tcl functionnames)
164 id=DoubleVar.trace_variable(self,mode,callback) 174 self.callbacklist[cbname]= mode
165 175 print "added trace:",callback,cbname
166 self.callbacklist[id]= [mode,callback] 176
167 177 return cbname
168 return id 178 trace=trace_variable
169
170 def disable_traces(self): 179 def disable_traces(self):
171 for k,v in self.callbacklist.items(): 180 for cb,mode in self.callbacklist.items():
172 self.trace_vdelete(v[0],k) 181 # DoubleVar.trace_vdelete(self,v[0],k)
182 self._tk.call("trace", "vdelete", self._name, mode,cb)
183 # but no master delete!
184
173 def recreate_traces(self): 185 def recreate_traces(self):
174 for k,v in self.callbacklist.items(): 186 for cb,mode in self.callbacklist.items():
175 self.trace_variable(v[0],v[1]) 187 # self.trace_variable(v[0],v[1])
188 self._tk.call("trace", "variable", self._name, mode,cb)
189
176 190
177 if __name__=='__main__': 191 if __name__=='__main__':
178 root=Tk() 192 root=Tk()
179 root.tk_focusFollowsMouse() 193 root.tk_focusFollowsMouse()
180 iv=IntVar() 194 iv=IntVar()