Return the name of the Tcl command defined by _bind(). This can

optionally be passed to unbind() (or you can apss it to
deletecommand()).
This commit is contained in:
Guido van Rossum 1998-03-27 21:26:51 +00:00
parent 982d91fb51
commit 117a5a8138
1 changed files with 13 additions and 5 deletions

View File

@ -456,21 +456,25 @@ class Misc:
self.tk.call('bindtags', self._w, tagList) self.tk.call('bindtags', self._w, tagList)
def _bind(self, what, sequence, func, add, needcleanup=1): def _bind(self, what, sequence, func, add, needcleanup=1):
if func: if func:
funcid = self._register(func, self._substitute,
needcleanup)
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, funcid,
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))
return funcid
elif func == '': elif func == '':
apply(self.tk.call, what + (sequence, func)) apply(self.tk.call, what + (sequence, func))
else: else:
return apply(self.tk.call, what + (sequence,)) return apply(self.tk.call, what + (sequence,))
def bind(self, sequence=None, func=None, add=None): def bind(self, sequence=None, func=None, add=None):
return self._bind(('bind', self._w), sequence, func, add) return self._bind(('bind', self._w), sequence, func, add)
def unbind(self, sequence): def unbind(self, sequence, funcid=None):
self.tk.call('bind', self._w, sequence, '') self.tk.call('bind', self._w, sequence, '')
if funcid:
self.deletecommand(funcid)
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, 0) return self._bind(('bind', 'all'), sequence, func, add, 0)
def unbind_all(self, sequence): def unbind_all(self, sequence):
@ -1130,8 +1134,10 @@ class Canvas(Widget):
self.addtag(newtag, 'withtag', tagOrId) self.addtag(newtag, 'withtag', tagOrId)
def bbox(self, *args): def bbox(self, *args):
return self._getints(self._do('bbox', args)) or None return self._getints(self._do('bbox', args)) or None
def tag_unbind(self, tagOrId, sequence): def tag_unbind(self, tagOrId, sequence, funcid=None):
self.tk.call(self._w, 'bind', tagOrId, sequence, '') self.tk.call(self._w, 'bind', tagOrId, sequence, '')
if funcid:
self.deletecommand(funcid)
def tag_bind(self, tagOrId, sequence=None, func=None, add=None): def tag_bind(self, tagOrId, sequence=None, func=None, add=None):
return self._bind((self._w, 'bind', tagOrId), return self._bind((self._w, 'bind', tagOrId),
sequence, func, add) sequence, func, add)
@ -1594,8 +1600,10 @@ class Text(Widget):
def tag_add(self, tagName, index1, index2=None): def tag_add(self, tagName, index1, index2=None):
self.tk.call( self.tk.call(
self._w, 'tag', 'add', tagName, index1, index2) self._w, 'tag', 'add', tagName, index1, index2)
def tag_unbind(self, tagName, sequence): def tag_unbind(self, tagName, sequence, funcid=None):
self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '') self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '')
if funcid:
self.deletecommand(funcid)
def tag_bind(self, tagName, sequence, func, add=None): def tag_bind(self, tagName, sequence, func, add=None):
return self._bind((self._w, 'tag', 'bind', tagName), return self._bind((self._w, 'tag', 'bind', tagName),
sequence, func, add) sequence, func, add)