summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/autocomplete_w.py
diff options
context:
space:
mode:
authorTal Einat <532281+taleinat@users.noreply.github.com>2021-05-28 06:07:21 (GMT)
committerGitHub <noreply@github.com>2021-05-28 06:07:21 (GMT)
commit4e2e5c1c4f792b4011e4c78d011baea2aee39f1b (patch)
tree134ba6c54c2571e410b11acfa9e626d7d9e74343 /Lib/idlelib/autocomplete_w.py
parent28be3191a9db2769ed05e55c6bcbccdd029656dd (diff)
downloadcpython-4e2e5c1c4f792b4011e4c78d011baea2aee39f1b.zip
cpython-4e2e5c1c4f792b4011e4c78d011baea2aee39f1b.tar.gz
cpython-4e2e5c1c4f792b4011e4c78d011baea2aee39f1b.tar.bz2
bpo-41611: IDLE: Catch TclError exceptions in AutoCompleteWindow.winconfig_event() (GH-26404)
Since the <Configure> event may occur after the completion window is gone, catch potential TclError exceptions when accessing acw.
Diffstat (limited to 'Lib/idlelib/autocomplete_w.py')
-rw-r--r--Lib/idlelib/autocomplete_w.py63
1 files changed, 36 insertions, 27 deletions
diff --git a/Lib/idlelib/autocomplete_w.py b/Lib/idlelib/autocomplete_w.py
index 4676822..2e3f9c1 100644
--- a/Lib/idlelib/autocomplete_w.py
+++ b/Lib/idlelib/autocomplete_w.py
@@ -242,37 +242,46 @@ class AutoCompleteWindow:
self.is_configuring = True
if not self.is_active():
return
- # Position the completion list window
- text = self.widget
- text.see(self.startindex)
- x, y, cx, cy = text.bbox(self.startindex)
- acw = self.autocompletewindow
- if platform.system().startswith('Windows'):
- # On Windows an update() call is needed for the completion list
- # window to be created, so that we can fetch its width and
- # height. However, this is not needed on other platforms (tested
- # on Ubuntu and macOS) but at one point began causing freezes on
- # macOS. See issues 37849 and 41611.
- acw.update()
- acw_width, acw_height = acw.winfo_width(), acw.winfo_height()
- text_width, text_height = text.winfo_width(), text.winfo_height()
- new_x = text.winfo_rootx() + min(x, max(0, text_width - acw_width))
- new_y = text.winfo_rooty() + y
- if (text_height - (y + cy) >= acw_height # enough height below
- or y < acw_height): # not enough height above
- # place acw below current line
- new_y += cy
- else:
- # place acw above current line
- new_y -= acw_height
- acw.wm_geometry("+%d+%d" % (new_x, new_y))
- acw.update_idletasks()
+
+ # Since the <Configure> event may occur after the completion window is gone,
+ # catch potential TclError exceptions when accessing acw. See: bpo-41611.
+ try:
+ # Position the completion list window
+ text = self.widget
+ text.see(self.startindex)
+ x, y, cx, cy = text.bbox(self.startindex)
+ acw = self.autocompletewindow
+ if platform.system().startswith('Windows'):
+ # On Windows an update() call is needed for the completion
+ # list window to be created, so that we can fetch its width
+ # and height. However, this is not needed on other platforms
+ # (tested on Ubuntu and macOS) but at one point began
+ # causing freezes on macOS. See issues 37849 and 41611.
+ acw.update()
+ acw_width, acw_height = acw.winfo_width(), acw.winfo_height()
+ text_width, text_height = text.winfo_width(), text.winfo_height()
+ new_x = text.winfo_rootx() + min(x, max(0, text_width - acw_width))
+ new_y = text.winfo_rooty() + y
+ if (text_height - (y + cy) >= acw_height # enough height below
+ or y < acw_height): # not enough height above
+ # place acw below current line
+ new_y += cy
+ else:
+ # place acw above current line
+ new_y -= acw_height
+ acw.wm_geometry("+%d+%d" % (new_x, new_y))
+ acw.update_idletasks()
+ except TclError:
+ pass
if platform.system().startswith('Windows'):
- # See issue 15786. When on Windows platform, Tk will misbehave
+ # See issue 15786. When on Windows platform, Tk will misbehave
# to call winconfig_event multiple times, we need to prevent this,
# otherwise mouse button double click will not be able to used.
- acw.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
+ try:
+ acw.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
+ except TclError:
+ pass
self.winconfigid = None
self.is_configuring = False