diff options
author | Guido van Rossum <guido@python.org> | 1997-04-14 13:30:24 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-04-14 13:30:24 (GMT) |
commit | 103cc6dd11c65fe817a60f1f368a34b38a7fad16 (patch) | |
tree | 697c2225426b4c8fb1ceb4367980e98d39f08b2a /Lib | |
parent | 5a56649e090a04db438815f67dce4077cec0f703 (diff) | |
download | cpython-103cc6dd11c65fe817a60f1f368a34b38a7fad16.zip cpython-103cc6dd11c65fe817a60f1f368a34b38a7fad16.tar.gz cpython-103cc6dd11c65fe817a60f1f368a34b38a7fad16.tar.bz2 |
Patch by Craig McPheeters to clean up the back-references to widgets
contained in commands created by those same widgets.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/lib-tk/Tkinter.py | 25 | ||||
-rwxr-xr-x | Lib/tkinter/Tkinter.py | 25 |
2 files changed, 46 insertions, 4 deletions
diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py index c492d8d..8d6cf7d 100644 --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -119,6 +119,19 @@ def getboolean(s): return _default_root.tk.getboolean(s) class Misc: + def __init__(self): + self._tclCommands = None + def destroy(self): + if self._tclCommands is not None: + for name in self._tclCommands: + #print '- Tkinter: deleted command', name + self.tk.deletecommand(name) + self._tclCommands = None + def deletecommand(self, name): + #print '- Tkinter: deleted command', name + self.tk.deletecommand(name) + index = self._tclCommands.index(name) + del self._tclCommands[index] def tk_strictMotif(self, boolean=None): return self.tk.getboolean(self.tk.call( 'set', 'tk_strictMotif', boolean)) @@ -184,11 +197,11 @@ class Misc: else: # XXX Disgusting hack to clean up after calling func tmp = [] - def callit(func=func, args=args, tk=self.tk, tmp=tmp): + def callit(func=func, args=args, self=self, tmp=tmp): try: apply(func, args) finally: - tk.deletecommand(tmp[0]) + self.deletecommand(tmp[0]) name = self._register(callit) tmp.append(name) return self.tk.call('after', ms, name) @@ -504,6 +517,10 @@ class Misc: except AttributeError: pass self.tk.createcommand(name, f) + if self._tclCommands is None: + self._tclCommands = [] + self._tclCommands.append(name) + #print '+ Tkinter created command', name return name register = _register def _root(self): @@ -644,6 +661,7 @@ class Wm: class Tk(Misc, Wm): _w = '.' def __init__(self, screenName=None, baseName=None, className='Tk'): + Misc.__init__(self) global _default_root self.master = None self.children = {} @@ -685,6 +703,7 @@ class Tk(Misc, Wm): def destroy(self): for c in self.children.values(): c.destroy() self.tk.call('destroy', self._w) + Misc.destroy(self) def __str__(self): return self._w def readprofile(self, baseName, className): @@ -888,6 +907,7 @@ class Widget(Misc, Pack, Place, Grid): self.master.children[self._name].destroy() self.master.children[self._name] = self def __init__(self, master, widgetName, cnf={}, kw={}, extra=()): + Misc.__init__(self) if kw: cnf = _cnfmerge((cnf, kw)) self.widgetName = widgetName @@ -935,6 +955,7 @@ class Widget(Misc, Pack, Place, Grid): if self.master.children.has_key(self._name): del self.master.children[self._name] self.tk.call('destroy', self._w) + Misc.destroy(self) def _do(self, name, args=()): return apply(self.tk.call, (self._w, name) + args) diff --git a/Lib/tkinter/Tkinter.py b/Lib/tkinter/Tkinter.py index c492d8d..8d6cf7d 100755 --- a/Lib/tkinter/Tkinter.py +++ b/Lib/tkinter/Tkinter.py @@ -119,6 +119,19 @@ def getboolean(s): return _default_root.tk.getboolean(s) class Misc: + def __init__(self): + self._tclCommands = None + def destroy(self): + if self._tclCommands is not None: + for name in self._tclCommands: + #print '- Tkinter: deleted command', name + self.tk.deletecommand(name) + self._tclCommands = None + def deletecommand(self, name): + #print '- Tkinter: deleted command', name + self.tk.deletecommand(name) + index = self._tclCommands.index(name) + del self._tclCommands[index] def tk_strictMotif(self, boolean=None): return self.tk.getboolean(self.tk.call( 'set', 'tk_strictMotif', boolean)) @@ -184,11 +197,11 @@ class Misc: else: # XXX Disgusting hack to clean up after calling func tmp = [] - def callit(func=func, args=args, tk=self.tk, tmp=tmp): + def callit(func=func, args=args, self=self, tmp=tmp): try: apply(func, args) finally: - tk.deletecommand(tmp[0]) + self.deletecommand(tmp[0]) name = self._register(callit) tmp.append(name) return self.tk.call('after', ms, name) @@ -504,6 +517,10 @@ class Misc: except AttributeError: pass self.tk.createcommand(name, f) + if self._tclCommands is None: + self._tclCommands = [] + self._tclCommands.append(name) + #print '+ Tkinter created command', name return name register = _register def _root(self): @@ -644,6 +661,7 @@ class Wm: class Tk(Misc, Wm): _w = '.' def __init__(self, screenName=None, baseName=None, className='Tk'): + Misc.__init__(self) global _default_root self.master = None self.children = {} @@ -685,6 +703,7 @@ class Tk(Misc, Wm): def destroy(self): for c in self.children.values(): c.destroy() self.tk.call('destroy', self._w) + Misc.destroy(self) def __str__(self): return self._w def readprofile(self, baseName, className): @@ -888,6 +907,7 @@ class Widget(Misc, Pack, Place, Grid): self.master.children[self._name].destroy() self.master.children[self._name] = self def __init__(self, master, widgetName, cnf={}, kw={}, extra=()): + Misc.__init__(self) if kw: cnf = _cnfmerge((cnf, kw)) self.widgetName = widgetName @@ -935,6 +955,7 @@ class Widget(Misc, Pack, Place, Grid): if self.master.children.has_key(self._name): del self.master.children[self._name] self.tk.call('destroy', self._w) + Misc.destroy(self) def _do(self, name, args=()): return apply(self.tk.call, (self._w, name) + args) |