From 95c44046335c2111d81f99f9a0633eb54a9a6fdf Mon Sep 17 00:00:00 2001 From: GiovanniL <13402461+GiovaLomba@users.noreply.github.com> Date: Mon, 6 Jan 2020 22:52:24 +0100 Subject: [PATCH 1/8] Fix: https://bugs.python.org/issue31485 Allows Misc.unbind to delete only the bound callback having the given funcid. See the issue above for more. --- Lib/tkinter/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index a3378d012fb41a..26cecf3c2496b4 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1385,11 +1385,14 @@ def bind(self, sequence=None, func=None, add=None): return self._bind(('bind', self._w), sequence, func, add) def unbind(self, sequence, funcid=None): - """Unbind for this widget for event SEQUENCE the - function identified with FUNCID.""" - self.tk.call('bind', self._w, sequence, '') + """Unbind for this widget the event SEQUENCE. if + FUNCID is given, delete the command also.""" + bound = '' if funcid: self.deletecommand(funcid) + funcs = self.tk.call('bind', self._w, sequence, None).split('\n') + bound = '\n'.join([f for f in funcs if not f.startswith(f'if {{"[{funcid}')]) + self.tk.call('bind', self._w, sequence, bound) def bind_all(self, sequence=None, func=None, add=None): """Bind to all widgets at an event SEQUENCE a call to function FUNC. From ebbdc6f2a3e4bee90502ff44483ff97865246ad9 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 11 Jan 2020 22:09:30 +0000 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst diff --git a/Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst b/Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst new file mode 100644 index 00000000000000..b8f26cba84c576 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst @@ -0,0 +1 @@ +On the tkinter library, the widget.unbind(, funcid) call unbinds all bindings for , while documentation states that when funcid is given all other bindings remains untuched. Apparently this behaviour is not offered by tkinter itself and, in case of non-empty funcid argument value be given, should be obtained by, at first, unbinding all bindings and then bind again all the ones not having the given funcid. This is basically what the proposed patch does. It takes account of the modifications done into the unbind method docstring, as described by other PSF members on the issue tracker. \ No newline at end of file From 8e0320300613dde233eb5eaec18f0d8dd438636f Mon Sep 17 00:00:00 2001 From: GiovanniL <13402461+GiovaLomba@users.noreply.github.com> Date: Wed, 15 Jan 2020 12:42:33 +0100 Subject: [PATCH 3/8] Fix: tests on Ubuntu bionic Fix `_tkinter.TclError: can't delete Tcl command` on Ubuntu bionic. Change `bound` to `keep` as suggested. --- Lib/tkinter/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 26cecf3c2496b4..15945b8bb647c2 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1387,12 +1387,12 @@ def bind(self, sequence=None, func=None, add=None): def unbind(self, sequence, funcid=None): """Unbind for this widget the event SEQUENCE. if FUNCID is given, delete the command also.""" - bound = '' + funcs = self.tk.call('bind', self._w, sequence, None) + self.tk.call('bind', self._w, sequence, '') if funcid: self.deletecommand(funcid) - funcs = self.tk.call('bind', self._w, sequence, None).split('\n') - bound = '\n'.join([f for f in funcs if not f.startswith(f'if {{"[{funcid}')]) - self.tk.call('bind', self._w, sequence, bound) + keep = '\n'.join(f for f in funcs.split('\n') if not f.startswith(f'if {{"[{funcid}')) + self.tk.call('bind', self._w, sequence, keep) def bind_all(self, sequence=None, func=None, add=None): """Bind to all widgets at an event SEQUENCE a call to function FUNC. From 05836401ac4d854f1d63a1236ed9a988ccd1e6a3 Mon Sep 17 00:00:00 2001 From: GiovanniL <13402461+GiovaLomba@users.noreply.github.com> Date: Wed, 15 Jan 2020 13:18:49 +0100 Subject: [PATCH 4/8] Update 2020-01-11-22-09-29.bpo-31485.DSvjsY.rst --- .../next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst b/Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst index b8f26cba84c576..b23b70e616257f 100644 --- a/Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst +++ b/Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst @@ -1 +1 @@ -On the tkinter library, the widget.unbind(, funcid) call unbinds all bindings for , while documentation states that when funcid is given all other bindings remains untuched. Apparently this behaviour is not offered by tkinter itself and, in case of non-empty funcid argument value be given, should be obtained by, at first, unbinding all bindings and then bind again all the ones not having the given funcid. This is basically what the proposed patch does. It takes account of the modifications done into the unbind method docstring, as described by other PSF members on the issue tracker. \ No newline at end of file +https://github.com/python/cpython/pull/17954# From 597ef390423d5d143e768d0c044ed6141be75b8e Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 16 Jan 2020 15:31:25 -0500 Subject: [PATCH 5/8] Update __init__.py Revise docstring to match behavior specified by Serhiy. Rearrange code to match. --- Lib/tkinter/__init__.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 15945b8bb647c2..06843c630a2ba1 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1385,14 +1385,20 @@ def bind(self, sequence=None, func=None, add=None): return self._bind(('bind', self._w), sequence, func, add) def unbind(self, sequence, funcid=None): - """Unbind for this widget the event SEQUENCE. if - FUNCID is given, delete the command also.""" - funcs = self.tk.call('bind', self._w, sequence, None) - self.tk.call('bind', self._w, sequence, '') - if funcid: - self.deletecommand(funcid) - keep = '\n'.join(f for f in funcs.split('\n') if not f.startswith(f'if {{"[{funcid}')) + """Unbind for this widget the event SEQUENCE. + + If FUNCID is given, only unbind the function identified with FUNCID. + and also delete that command. + """ + if funcid is None: + self.tk.call('bind', self._w, sequence, None) + else: + funcs = self.tk.call('bind', self._w, sequence, None).split('\n') + keep = '\n'.join(f for f in funcs.split('\n') + if not f.startswith(f'if {{"[{funcid}')) self.tk.call('bind', self._w, sequence, keep) + self.deletecommand(funcid) + def bind_all(self, sequence=None, func=None, add=None): """Bind to all widgets at an event SEQUENCE a call to function FUNC. From 082db44f9ef2765cc33f39a8d889704760852171 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 16 Jan 2020 15:50:16 -0500 Subject: [PATCH 6/8] Fix whitespace, delete extra '.' --- Lib/tkinter/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 06843c630a2ba1..e9e585e4c73f65 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1386,8 +1386,8 @@ def bind(self, sequence=None, func=None, add=None): def unbind(self, sequence, funcid=None): """Unbind for this widget the event SEQUENCE. - - If FUNCID is given, only unbind the function identified with FUNCID. + + If FUNCID is given, only unbind the function identified with FUNCID and also delete that command. """ if funcid is None: @@ -1398,7 +1398,6 @@ def unbind(self, sequence, funcid=None): if not f.startswith(f'if {{"[{funcid}')) self.tk.call('bind', self._w, sequence, keep) self.deletecommand(funcid) - def bind_all(self, sequence=None, func=None, add=None): """Bind to all widgets at an event SEQUENCE a call to function FUNC. From af411224eaaac5a743810494c79e923fd20ea982 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 16 Jan 2020 15:56:18 -0500 Subject: [PATCH 7/8] Leave no-funcid call as it was. --- Lib/tkinter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index e9e585e4c73f65..664f8475a9d17d 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1391,7 +1391,7 @@ def unbind(self, sequence, funcid=None): and also delete that command. """ if funcid is None: - self.tk.call('bind', self._w, sequence, None) + self.tk.call('bind', self._w, sequence, '') else: funcs = self.tk.call('bind', self._w, sequence, None).split('\n') keep = '\n'.join(f for f in funcs.split('\n') From 530e1d5e079f8cf17f3199eac683a9d9d2ec29f4 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 16 Jan 2020 16:32:02 -0500 Subject: [PATCH 8/8] Remove redundant split --- Lib/tkinter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 664f8475a9d17d..8e221c7d6d74f0 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1394,7 +1394,7 @@ def unbind(self, sequence, funcid=None): self.tk.call('bind', self._w, sequence, '') else: funcs = self.tk.call('bind', self._w, sequence, None).split('\n') - keep = '\n'.join(f for f in funcs.split('\n') + keep = '\n'.join(f for f in funcs if not f.startswith(f'if {{"[{funcid}')) self.tk.call('bind', self._w, sequence, keep) self.deletecommand(funcid) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy