mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
Fix problem detected by Greg McFarlane -- callbacks passed to
bind_class() and bind_all() are destroyed when the widget to which they were passed is destroyed.
This commit is contained in:
parent
d1f4984a9b
commit
5ac00ac140
1 changed files with 16 additions and 10 deletions
|
@ -121,6 +121,7 @@ def getboolean(s):
|
||||||
|
|
||||||
# Methods defined on both toplevel and interior widgets
|
# Methods defined on both toplevel and interior widgets
|
||||||
class Misc:
|
class Misc:
|
||||||
|
# XXX font command?
|
||||||
_tclCommands = None
|
_tclCommands = None
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
if self._tclCommands is not None:
|
if self._tclCommands is not None:
|
||||||
|
@ -131,8 +132,10 @@ class Misc:
|
||||||
def deletecommand(self, name):
|
def deletecommand(self, name):
|
||||||
#print '- Tkinter: deleted command', name
|
#print '- Tkinter: deleted command', name
|
||||||
self.tk.deletecommand(name)
|
self.tk.deletecommand(name)
|
||||||
index = self._tclCommands.index(name)
|
try:
|
||||||
del self._tclCommands[index]
|
self._tclCommands.remove(name)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
def tk_strictMotif(self, boolean=None):
|
def tk_strictMotif(self, boolean=None):
|
||||||
return self.tk.getboolean(self.tk.call(
|
return self.tk.getboolean(self.tk.call(
|
||||||
'set', 'tk_strictMotif', boolean))
|
'set', 'tk_strictMotif', boolean))
|
||||||
|
@ -435,12 +438,13 @@ class Misc:
|
||||||
self.tk.call('bindtags', self._w))
|
self.tk.call('bindtags', self._w))
|
||||||
else:
|
else:
|
||||||
self.tk.call('bindtags', self._w, tagList)
|
self.tk.call('bindtags', self._w, tagList)
|
||||||
def _bind(self, what, sequence, func, add):
|
def _bind(self, what, sequence, func, add, needcleanup=1):
|
||||||
if func:
|
if func:
|
||||||
cmd = ("%sset _tkinter_break [%s %s]\n"
|
cmd = ("%sset _tkinter_break [%s %s]\n"
|
||||||
'if {"$_tkinter_break" == "break"} break\n') \
|
'if {"$_tkinter_break" == "break"} break\n') \
|
||||||
% (add and '+' or '',
|
% (add and '+' or '',
|
||||||
self._register(func, self._substitute),
|
self._register(func, self._substitute,
|
||||||
|
needcleanup),
|
||||||
_string.join(self._subst_format))
|
_string.join(self._subst_format))
|
||||||
apply(self.tk.call, what + (sequence, cmd))
|
apply(self.tk.call, what + (sequence, cmd))
|
||||||
elif func == '':
|
elif func == '':
|
||||||
|
@ -452,11 +456,11 @@ class Misc:
|
||||||
def unbind(self, sequence):
|
def unbind(self, sequence):
|
||||||
self.tk.call('bind', self._w, sequence, '')
|
self.tk.call('bind', self._w, sequence, '')
|
||||||
def bind_all(self, sequence=None, func=None, add=None):
|
def bind_all(self, sequence=None, func=None, add=None):
|
||||||
return self._bind(('bind', 'all'), sequence, func, add)
|
return self._bind(('bind', 'all'), sequence, func, add, 0)
|
||||||
def unbind_all(self, sequence):
|
def unbind_all(self, sequence):
|
||||||
self.tk.call('bind', 'all' , sequence, '')
|
self.tk.call('bind', 'all' , sequence, '')
|
||||||
def bind_class(self, className, sequence=None, func=None, add=None):
|
def bind_class(self, className, sequence=None, func=None, add=None):
|
||||||
return self._bind(('bind', className), sequence, func, add)
|
return self._bind(('bind', className), sequence, func, add, 0)
|
||||||
def unbind_class(self, className, sequence):
|
def unbind_class(self, className, sequence):
|
||||||
self.tk.call('bind', className , sequence, '')
|
self.tk.call('bind', className , sequence, '')
|
||||||
def mainloop(self, n=0):
|
def mainloop(self, n=0):
|
||||||
|
@ -506,7 +510,7 @@ class Misc:
|
||||||
w = w.children[name]
|
w = w.children[name]
|
||||||
name = tail
|
name = tail
|
||||||
return w
|
return w
|
||||||
def _register(self, func, subst=None):
|
def _register(self, func, subst=None, needcleanup=1):
|
||||||
f = CallWrapper(func, subst, self).__call__
|
f = CallWrapper(func, subst, self).__call__
|
||||||
name = `id(f)`
|
name = `id(f)`
|
||||||
try:
|
try:
|
||||||
|
@ -518,9 +522,10 @@ class Misc:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
self.tk.createcommand(name, f)
|
self.tk.createcommand(name, f)
|
||||||
if self._tclCommands is None:
|
if needcleanup:
|
||||||
self._tclCommands = []
|
if self._tclCommands is None:
|
||||||
self._tclCommands.append(name)
|
self._tclCommands = []
|
||||||
|
self._tclCommands.append(name)
|
||||||
#print '+ Tkinter created command', name
|
#print '+ Tkinter created command', name
|
||||||
return name
|
return name
|
||||||
register = _register
|
register = _register
|
||||||
|
@ -1737,6 +1742,7 @@ class PhotoImage(Image):
|
||||||
# XXX config
|
# XXX config
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return self.tk.call(self.name, 'cget', '-' + key)
|
return self.tk.call(self.name, 'cget', '-' + key)
|
||||||
|
# XXX copy -from, -to, ...?
|
||||||
def copy(self):
|
def copy(self):
|
||||||
destImage = PhotoImage()
|
destImage = PhotoImage()
|
||||||
self.tk.call(destImage, 'copy', self.name)
|
self.tk.call(destImage, 'copy', self.name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue