Anonymous avatar Anonymous committed ecaa431

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.

Comments (0)

Files changed (1)

Lib/lib-tk/Tkinter.py

 
 # Methods defined on both toplevel and interior widgets
 class Misc:
+	# XXX font command?
 	_tclCommands = None
 	def destroy(self):
 		if self._tclCommands is not None:
 	def deletecommand(self, name):
 		#print '- Tkinter: deleted command', name
 		self.tk.deletecommand(name)
-		index = self._tclCommands.index(name)
-		del self._tclCommands[index]
+		try:
+			self._tclCommands.remove(name)
+		except ValueError:
+			pass
 	def tk_strictMotif(self, boolean=None):
 		return self.tk.getboolean(self.tk.call(
 			'set', 'tk_strictMotif', boolean))
 				self.tk.call('bindtags', self._w))
 		else:
 			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:
 			cmd = ("%sset _tkinter_break [%s %s]\n"
 			       'if {"$_tkinter_break" == "break"} break\n') \
 			       % (add and '+' or '',
-				  self._register(func, self._substitute),
+				  self._register(func, self._substitute,
+						 needcleanup),
 				  _string.join(self._subst_format))
 			apply(self.tk.call, what + (sequence, cmd))
 		elif func == '':
 	def unbind(self, sequence):
 		self.tk.call('bind', self._w, sequence, '')
 	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):
 		self.tk.call('bind', 'all' , sequence, '')
 	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):
 		self.tk.call('bind', className , sequence, '')
 	def mainloop(self, n=0):
 			w = w.children[name]
 			name = tail
 		return w
-	def _register(self, func, subst=None):
+	def _register(self, func, subst=None, needcleanup=1):
 		f = CallWrapper(func, subst, self).__call__
 		name = `id(f)`
 		try:
 		except AttributeError:
 			pass
 		self.tk.createcommand(name, f)
-		if self._tclCommands is None:
-			self._tclCommands = []
-		self._tclCommands.append(name)
+		if needcleanup:
+			if self._tclCommands is None:
+				self._tclCommands = []
+       			self._tclCommands.append(name)
 		#print '+ Tkinter created command', name
 		return name
 	register = _register
 	# XXX config
 	def __getitem__(self, key):
 		return self.tk.call(self.name, 'cget', '-' + key)
+	# XXX copy -from, -to, ...?
 	def copy(self):
 		destImage = PhotoImage()
 		self.tk.call(destImage, 'copy', self.name)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.