MCPcopy Index your code
hub / github.com/python/cpython / VarTrace

Class VarTrace

Lib/idlelib/configdialog.py:2217–2275  ·  view source on GitHub ↗

Maintain Tk variables trace state.

Source from the content-addressed store, hash-verified

2215
2216
2217class VarTrace:
2218 """Maintain Tk variables trace state."""
2219
2220 def __init__(self):
2221 """Store Tk variables and callbacks.
2222
2223 untraced: List of tuples (var, callback)
2224 that do not have the callback attached
2225 to the Tk var.
2226 traced: List of tuples (var, callback) where
2227 that callback has been attached to the var.
2228 """
2229 self.untraced = []
2230 self.traced = []
2231
2232 def clear(self):
2233 "Clear lists (for tests)."
2234 # Call after all tests in a module to avoid memory leaks.
2235 self.untraced.clear()
2236 self.traced.clear()
2237
2238 def add(self, var, callback):
2239 """Add (var, callback) tuple to untraced list.
2240
2241 Args:
2242 var: Tk variable instance.
2243 callback: Either function name to be used as a callback
2244 or a tuple with IdleConf config-type, section, and
2245 option names used in the default callback.
2246
2247 Return:
2248 Tk variable instance.
2249 """
2250 if isinstance(callback, tuple):
2251 callback = self.make_callback(var, callback)
2252 self.untraced.append((var, callback))
2253 return var
2254
2255 @staticmethod
2256 def make_callback(var, config):
2257 "Return default callback function to add values to changes instance."
2258 def default_callback(*params):
2259 "Add config values to changes instance."
2260 changes.add_option(*config, var.get())
2261 return default_callback
2262
2263 def attach(self):
2264 "Attach callback to all vars that are not traced."
2265 while self.untraced:
2266 var, callback = self.untraced.pop()
2267 var.trace_add('write', callback)
2268 self.traced.append((var, callback))
2269
2270 def detach(self):
2271 "Remove callback from traced vars."
2272 while self.traced:
2273 var, callback = self.traced.pop()
2274 var.trace_remove('write', var.trace_info()[0][1])

Callers 1

configdialog.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…