Skip to content

gh-154511: Consolidate IDLE's mouse wheel handling in util - #156974

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:idle-mousewheel-util
Sep 6, 2026
Merged

gh-154511: Consolidate IDLE's mouse wheel handling in util#156974
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:idle-mousewheel-util

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

An alternative to #154512.

wheel_event moves from idlelib.tree to idlelib.util, with its test, and gains two neighbours: x11_buttons(widget), which tells whether Tk reports a wheel rotation to that widget as <Button-4>/<Button-5>, as it does on X11 before Tk 8.7, or as <MouseWheel>, and bind_wheel(widget, func), which binds whichever of them Tk sends. The editor, the tree and test_sidebar use these instead of working out the windowing system themselves.

x11_buttons takes a widget because the windowing system is a property of the display, which only a widget knows. As a module-level constant it would need a root at import time, and util must not create one: pyshell imports fix_win_hidpi from it and calls it before any Tk operation, run.py imports it in the user process, and test_idle currently runs headless. For the same reason util still imports tkinter only inside the function that needs a name from it.

wheel_event now reads the direction from the event, by number for a button and by delta for a wheel, rather than from the platform, so it stays right whichever event arrives.

The fix_ functions that util already had are tested too; they were only called, never checked, by the setUpClass of other test modules. fix_win_hidpi runs in a subprocess, as DPI awareness is process-wide and cannot be undone.

The unneeded <Button-4>/<Button-5> bindings in sidebar.py are left for a later PR, as in gh-154511.

Move wheel_event there from idlelib.tree and add x11_buttons(widget) and
bind_wheel(widget, func), used by the editor, the tree and test_sidebar.
wheel_event now reads the direction from the event, not the platform.

Move its test from test_tree, and test the fix_ functions of util too.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@terryjreedy terryjreedy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed most of the code other than the 'other' new test_util tests. On Windows,
I manually scrolled in editor, editor module browser with Editor class expanded, and settings font sample. All look normal.

@serhiy-storchaka
serhiy-storchaka merged commit 57594aa into python:main Sep 6, 2026
63 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@serhiy-storchaka
serhiy-storchaka deleted the idle-mousewheel-util branch September 6, 2026 06:15
@bedevere-app

bedevere-app Bot commented Sep 6, 2026

Copy link
Copy Markdown

GH-157021 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 6, 2026
@bedevere-app

bedevere-app Bot commented Sep 6, 2026

Copy link
Copy Markdown

GH-157022 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 6, 2026
@bedevere-app

bedevere-app Bot commented Sep 6, 2026

Copy link
Copy Markdown

GH-157023 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Sep 6, 2026
serhiy-storchaka added a commit that referenced this pull request Sep 6, 2026
…-156974) (GH-157023)

Move wheel_event there from idlelib.tree and add x11_buttons(widget) and
bind_wheel(widget, func), used by the editor, the tree and test_sidebar.
wheel_event now reads the direction from the event, not the platform.

Move its test from test_tree, and test the fix_ functions of util too.
(cherry picked from commit 57594aa)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Sep 6, 2026
…-156974) (GH-157022)

Move wheel_event there from idlelib.tree and add x11_buttons(widget) and
bind_wheel(widget, func), used by the editor, the tree and test_sidebar.
wheel_event now reads the direction from the event, not the platform.

Move its test from test_tree, and test the fix_ functions of util too.
(cherry picked from commit 57594aa)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants