Terry J. Reedy added the comment: This issue is really about managing the set of var,callback pairs. The idea of wrapping vars just clouded the issue.
class VarTrace: def __init__(self): self.tracers = [] # or set if need to delete def add(self, var, callback): if isinstance(callback, tuple): callback = self.make_callback(var, callback) self.vartrace.add((var, callback)) return var def make_callback(self, var, args): # Used for 6 vars. def var_callback(*params): changes.add_item(*args, var.get()) return var_callback def attach(self): for var, callback in self.tracers: var.trace_add('write', callback) def remove(cls): # detach? for var, _ in self.tracers: var.trace_remove('write', var.trace_info()[0][1]) # doc this # A functionalist would define a function that returns a sequence of closures. tracers = VarTrace() # write tests, then patch creation of tested vars, retest, patch rest. - self.font_name = StringVar(parent) + self.font_name = tracers.add(StringVar(parent), var_changed_font) ---------- nosy: +csabella title: IDLE: configdialog -- factor out Variable subclass -> IDLE: configdialog -- factor out Tracer subclass _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30853> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com