Skip to content

gh-154511: IDLE - Update mousewheel event handling - #154512

Closed
terryjreedy wants to merge 4 commits into
python:mainfrom
terryjreedy:x11wheel
Closed

gh-154511: IDLE - Update mousewheel event handling #154512
terryjreedy wants to merge 4 commits into
python:mainfrom
terryjreedy:x11wheel

Conversation

@terryjreedy

@terryjreedyterryjreedy commented Jul 22, 2026

Copy link
Copy Markdown
Member

Move x11_buttons boolean and wheel_event function
to util.py. Move test to test_util.
@terryjreedy

terryjreedy commented Jul 22, 2026

Copy link
Copy Markdown
MemberAuthor

Quick manual checks on linux and macOS would be nice: load a non-trivial file such as editor.py and scroll up and down. Scrolling in a sidebar should not be affected by this PR. Open a module browser and expand enough to scroll both over the items and in the blank space. @StanFromIreland I forget whether you have mac or only linux.

EDIT: I have done the above on Windows and the unittest is system independent, as it patches the x11 indicator (which Serhiy wrote and tested on x11.)

@StanFromIreland

Copy link
Copy Markdown
Member

@StanFromIreland I forget whether you have mac or only linux.

Only Linux, maybe ask a Mac expert to test it on a Mac.

Comment threadLib/idlelib/util.py Outdated
@terryjreedy

Copy link
Copy Markdown
MemberAuthor

@ronaldoussoren@ned-deily Could one of you quickly test that scrolling still works on macOS in editor and module browser?

@terryjreedy

terryjreedy commented Jul 23, 2026

Copy link
Copy Markdown
MemberAuthor

Failures are mysteries to me.
test_idle worker non-zero exit code�[0m (Exit code -5 (SIGTRAP)) macOS
?? no detail
test_idle worker non-zero exit code�[0m (Exit code -11 (SIGSEGV)) macOS intel and macOS free threading
File "/Users/runner/work/cpython/cpython/Lib/tkinter/init.py", line 1579 in update
File "/Users/runner/work/cpython/cpython/Lib/test/support/init.py", line 306 in _is_gui_available
File "/Users/runner/work/cpython/cpython/Lib/test/support/init.py", line 346 in requires
File "/Users/runner/work/cpython/cpython/Lib/idlelib/idle_test/test_configdialog.py", line 7 in
?? How does patch affect tkinter.init when running test_configdialog??

UBSan has repeated failures like this:
Traceback (most recent call last):
File "/home/runner/work/cpython/cpython/Lib/unittest/loader.py", line 433, in _find_test_path
module = self._get_module_from_name(name)
File "/home/runner/work/cpython/cpython/Lib/unittest/loader.py", line 374, in _get_module_from_name
import(name)
~~~~~~~~~~^^^^^^
File "/home/runner/work/cpython/cpython/Lib/idlelib/idle_test/test_browser.py", line 3, in
from idlelib import browser
File "/home/runner/work/cpython/cpython/Lib/idlelib/browser.py", line 16, in
from idlelib import pyshell
File "/home/runner/work/cpython/cpython/Lib/idlelib/pyshell.py", line 39, in
from idlelib.editor import EditorWindow
File "/home/runner/work/cpython/cpython/Lib/idlelib/editor.py", line 29, in
from idlelib.util import py_extensions
File "/home/runner/work/cpython/cpython/Lib/idlelib/util.py", line 73, in
root = tkinter.Tk() # Use this as process root?
File "/home/runner/work/cpython/cpython/Lib/tkinter/init.py", line 2687, in init
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_tkinter.TclError: no display name and no $DISPLAY environment variable
Failed to import test module: idlelib.idle_test.test_debugobj

with different idle_test.test_x for each failure
Hypothesis has failures like this also.
?? Why does this particular (and new) Tk() call fail?? and just on some tests.

Re-running some

Comment threadLib/idlelib/util.py
Comment threadLib/idlelib/util.py
Comment threadLib/idlelib/tree.py
@serhiy-storchaka

Copy link
Copy Markdown
Member

I pushed an alternative, #156974, with the same goals.

The import-time tkinter.Tk() in util has three consequences:

  • pyshell imports fix_win_hidpi from util and calls it, but the import now creates a root first, so SetProcessDpiAwareness fails with E_ACCESSDENIED — swallowed by the function's except — and the Windows HiDPI fix silently stops working. turtledemo does the same thing.
  • run.py imports util, so the user process would create and destroy a Tk root on every Run. That process should not need tkinter at all — it already has to unload the submodules idlelib drags in (scrub_tkinter_submodules, IDLE: user code 'import tkinter; tkinter.font' should fail #69693) — and a root is a connection to the window server, not merely an import.
  • import idlelib.util raises TclError without a display, so test_browser, test_iomenu, test_editor … would error instead of skipping. test_idle runs headless today: 307 tests, 83 skips.

Two smaller things:

  • wheel_event should take the direction from the event rather than the platform: a <Button-4> event arriving while x11_buttons is false reads delta == 0 and scrolls down. num is 4 or 5 for a button and '??' for a wheel.
  • Assigning util.x11_buttons in the test exercises the flag, not the code path, and requires('gui') at module level gives up the tests that need no display.

Nits: <Mousewheel missing its >, "generally=", "test delagation", the leftover coverage %, the walrus in (widget2 := _Widget()), the unrelated blank line removed after class TreeNode:, no NEWS entry.

In #156974, x11_buttons(widget) is a function and bind_wheel(widget, func) hides the choice from the call sites; util imports tkinter only inside the function that needs it, so importing util pulls in no tkinter at all. Happy to close mine if you would rather fix this one.

@terryjreedy

Copy link
Copy Markdown
MemberAuthor

Before me, run.py was written to avoid disturbing tk, so it calls tkinter.Tcl().update () inside of handle_tk_events, called within the main loop when there is no request. I believe this is there to advance user tkinter code without a Tk().mainloop(). In any case, creating a Tk upon util import is bad. Serhiy's alternative has other advantages, including passing CI. So closing this.

@terryjreedy
terryjreedy deleted the x11wheel branch September 6, 2026 01:27
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@terryjreedy@StanFromIreland@serhiy-storchaka