Skip to content

fix(canvas): eliminate screenChanged disconnect RuntimeWarning#116

Merged
nelsonduarte merged 1 commit into
mainfrom
fix/screen-changed-disconnect-warning
Jul 11, 2026
Merged

fix(canvas): eliminate screenChanged disconnect RuntimeWarning#116
nelsonduarte merged 1 commit into
mainfrom
fix/screen-changed-disconnect-warning

Conversation

@nelsonduarte

Copy link
Copy Markdown
Owner

Summary

PR-J (R8/D1 DPR change handler) added a disconnect-then-connect pattern in showEvent for both the viewer canvas and editor canvas. On PySide6 6.11, calling disconnect on a signal that was never connected (first show, or re-show after teardown) emits:

RuntimeWarning: libpyside: Failed to disconnect (...) from signal "screenChanged(QScreen*)".

contextlib.suppress(TypeError, RuntimeError) doesn't silence a warning — Python warnings and exceptions are separate.

Fix

Instead of blindly disconnecting on every show, both canvases now track the currently-connected window in self._screen_signal_window:

  • Same window (typical re-show) → no-op
  • Different window (widget reparented) → disconnect from previous, connect to new
  • First show → connect only

Applied identically in _SelectCanvas.showEvent (app/viewer/canvas.py) and PdfEditCanvas.showEvent (app/editor/canvas.py). Kept inline (~10 lines each) rather than extracting a helper — factoring across viewer + editor packages had marginal gain.

Tests

tests/test_screen_changed_binding.py — 8 source-level regressions:

  • Tracker attribute present in both canvases
  • Tracker initialised in both __init__ methods
  • No bare disconnect-before-connect anti-pattern
  • Short-circuit on win is prev_win

Also verified that the existing R8/D1 tests (test_round8_fixes.py::test_{viewer,editor}_canvas_handles_screen_changed) still pass — no regression on the DPR change handling behaviour.

Validation

  • 1 atomic commit
  • 8 new tests pass
  • No APP_VERSION bump
  • No new dependencies
  • Manual QA: launch the app, open a PDF, cycle windows (F5 into presentation and back) — no more warning in stderr

Not related to PR #115

PR #115 (presentation mode HUD icons) touches the same files but different lines. Merge order doesn't matter; either can go first.

…connect warning

PR-J's DPR change handler called disconnect+connect on every showEvent,
which raised a RuntimeWarning ("Failed to disconnect from signal
screenChanged") on the first show and any re-show where the signal
was never actually connected. PySide6 6.11 emits a RuntimeWarning
(not an exception) for the "signal was never connected" case, so
contextlib.suppress(TypeError, RuntimeError) could not silence it.

Now showEvent tracks the previously-connected window in
_screen_signal_window and only disconnects when the window actually
changes (e.g., widget was reparented to a different top-level).
First show, same-window re-show, and reparent are all handled
without the warning.

Applied identically to _SelectCanvas (viewer) and PdfEditCanvas (editor).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@nelsonduarte nelsonduarte added the bug Something isn't working label Jul 11, 2026
@nelsonduarte nelsonduarte merged commit 69e5a06 into main Jul 11, 2026
4 checks passed
@nelsonduarte nelsonduarte deleted the fix/screen-changed-disconnect-warning branch July 11, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant