Skip to content

gh-103820: IDLE: Do not interpret buttons 4/5 as scrolling on non-X11 #103821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
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)
Expand Down
22 changes: 14 additions & 8 deletions Lib/idlelib/idle_test/test_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,16 +690,22 @@ def test_mousewheel(self):
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')))

Expand Down
10 changes: 6 additions & 4 deletions Lib/idlelib/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ def drawtext(self):
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):
Expand Down Expand Up @@ -460,8 +461,9 @@ def __init__(self, master, **opts):
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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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.