diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-02-02 13:13:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-02 13:13:00 (GMT) |
commit | e995c585e751f8ea80bfda70d4f70bbf1912660d (patch) | |
tree | 2225fc04fd5e688dc069dc80b4f0cc719cbf6a79 | |
parent | 1eb791ce4f69cd23153a9fa428b0c4c9ef227a89 (diff) | |
download | cpython-e995c585e751f8ea80bfda70d4f70bbf1912660d.zip cpython-e995c585e751f8ea80bfda70d4f70bbf1912660d.tar.gz cpython-e995c585e751f8ea80bfda70d4f70bbf1912660d.tar.bz2 |
[3.11] gh-103820: IDLE: Do not interpret buttons 4/5 as scrolling on non-X11 (GH-103821) (GH-114902)
Also fix test_mousewheel: do not skip a check which was broken due to incorrect
delta on Aqua and XQuartz, and probably not because of `.update_idletasks()`.
(cherry picked from commit d25d4ee60cc789a8b9c222859bb720ade1ab2e30)
Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
-rw-r--r-- | Lib/idlelib/editor.py | 5 | ||||
-rw-r--r-- | Lib/idlelib/idle_test/test_sidebar.py | 22 | ||||
-rw-r--r-- | Lib/idlelib/tree.py | 10 | ||||
-rw-r--r-- | Misc/NEWS.d/next/IDLE/2023-04-25-03-01-23.gh-issue-103820.LCSpza.rst | 2 |
4 files changed, 25 insertions, 14 deletions
diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index 6ad383f..8ee8eba 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -166,8 +166,9 @@ class EditorWindow: text.bind("<3>",self.right_menu_event) text.bind('<MouseWheel>', wheel_event) - text.bind('<Button-4>', wheel_event) - text.bind('<Button-5>', wheel_event) + if text._windowingsystem == 'x11': + text.bind('<Button-4>', wheel_event) + text.bind('<Button-5>', wheel_event) text.bind('<Configure>', self.handle_winconfig) text.bind("<<cut>>", self.cut) text.bind("<<copy>>", self.copy) diff --git a/Lib/idlelib/idle_test/test_sidebar.py b/Lib/idlelib/idle_test/test_sidebar.py index fb52b3a..605e7a8 100644 --- a/Lib/idlelib/idle_test/test_sidebar.py +++ b/Lib/idlelib/idle_test/test_sidebar.py @@ -690,16 +690,22 @@ class ShellSidebarTest(unittest.TestCase): last_lineno = get_end_linenumber(text) self.assertIsNotNone(text.dlineinfo(text.index(f'{last_lineno}.0'))) - # Scroll up using the <MouseWheel> event. - # The meaning of delta is platform-dependent. - delta = -1 if sys.platform == 'darwin' else 120 - sidebar.canvas.event_generate('<MouseWheel>', x=0, y=0, delta=delta) + # Delta for <MouseWheel>, whose meaning is platform-dependent. + delta = 1 if sidebar.canvas._windowingsystem == 'aqua' else 120 + + # Scroll up. + if sidebar.canvas._windowingsystem == 'x11': + sidebar.canvas.event_generate('<Button-4>', x=0, y=0) + else: + sidebar.canvas.event_generate('<MouseWheel>', x=0, y=0, delta=delta) yield - if sys.platform != 'darwin': # .update_idletasks() does not work. - self.assertIsNone(text.dlineinfo(text.index(f'{last_lineno}.0'))) + self.assertIsNone(text.dlineinfo(text.index(f'{last_lineno}.0'))) - # Scroll back down using the <Button-5> event. - sidebar.canvas.event_generate('<Button-5>', x=0, y=0) + # Scroll back down. + if sidebar.canvas._windowingsystem == 'x11': + sidebar.canvas.event_generate('<Button-5>', x=0, y=0) + else: + sidebar.canvas.event_generate('<MouseWheel>', x=0, y=0, delta=-delta) yield self.assertIsNotNone(text.dlineinfo(text.index(f'{last_lineno}.0'))) diff --git a/Lib/idlelib/tree.py b/Lib/idlelib/tree.py index 9c2eb47..0726d7e 100644 --- a/Lib/idlelib/tree.py +++ b/Lib/idlelib/tree.py @@ -285,8 +285,9 @@ class TreeNode: self.label.bind("<1>", self.select_or_edit) self.label.bind("<Double-1>", self.flip) self.label.bind("<MouseWheel>", lambda e: wheel_event(e, self.canvas)) - self.label.bind("<Button-4>", lambda e: wheel_event(e, self.canvas)) - self.label.bind("<Button-5>", lambda e: wheel_event(e, self.canvas)) + if self.label._windowingsystem == 'x11': + self.label.bind("<Button-4>", lambda e: wheel_event(e, self.canvas)) + self.label.bind("<Button-5>", lambda e: wheel_event(e, self.canvas)) self.text_id = id def select_or_edit(self, event=None): @@ -460,8 +461,9 @@ class ScrolledCanvas: self.canvas.bind("<Key-Up>", self.unit_up) self.canvas.bind("<Key-Down>", self.unit_down) self.canvas.bind("<MouseWheel>", wheel_event) - self.canvas.bind("<Button-4>", wheel_event) - self.canvas.bind("<Button-5>", wheel_event) + if self.canvas._windowingsystem == 'x11': + self.canvas.bind("<Button-4>", wheel_event) + self.canvas.bind("<Button-5>", wheel_event) #if isinstance(master, Toplevel) or isinstance(master, Tk): self.canvas.bind("<Alt-Key-2>", self.zoom_height) self.canvas.focus_set() diff --git a/Misc/NEWS.d/next/IDLE/2023-04-25-03-01-23.gh-issue-103820.LCSpza.rst b/Misc/NEWS.d/next/IDLE/2023-04-25-03-01-23.gh-issue-103820.LCSpza.rst new file mode 100644 index 0000000..b9d7faf --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2023-04-25-03-01-23.gh-issue-103820.LCSpza.rst @@ -0,0 +1,2 @@ +Revise IDLE bindings so that events from mouse button 4/5 on non-X11 +windowing systems (i.e. Win32 and Aqua) are not mistaken for scrolling. |