From 4ef2ad64d706c2fbc0631668f00bdd8266f5ace3 Mon Sep 17 00:00:00 2001 From: Dawn Date: Sun, 9 Aug 2026 10:08:23 +0200 Subject: [PATCH] style: clear the basedpyright gate for the new-code lines Narrow QApplication.instance() before use, wrap the theme QSettings read in str(), hand QPropertyAnimation a real QByteArray, and declare the lazily-set watch-mode attributes on the class. Co-Authored-By: Claude Fable 5 --- src/aare/gui/main_window.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/aare/gui/main_window.py b/src/aare/gui/main_window.py index a6eea740..502034b6 100644 --- a/src/aare/gui/main_window.py +++ b/src/aare/gui/main_window.py @@ -15,7 +15,17 @@ from aarecommon.models.models import ( SessionsStateEnum, TokenData, ) -from PySide6.QtCore import QEvent, QObject, QPropertyAnimation, QSettings, Qt, QTimer, Signal, Slot +from PySide6.QtCore import ( + QByteArray, + QEvent, + QObject, + QPropertyAnimation, + QSettings, + Qt, + QTimer, + Signal, + Slot, +) from PySide6.QtGui import ( QAction, QActionGroup, @@ -149,6 +159,8 @@ class MainWindow(QMainWindow): # declared for the basedpyright gate. _session_operations_enabled: bool | None = None _default_dock_split_done: bool = False + _pre_watch_dock_state: QByteArray | None = None + _pre_watch_visibility: list[tuple[QWidget, bool]] | None = None def __init__( self, @@ -218,7 +230,9 @@ class MainWindow(QMainWindow): # App-level, not window-level: dialogs and pop-outs get it too. self._clickable_cursor_filter = ClickableCursorFilter(self) - QApplication.instance().installEventFilter(self._clickable_cursor_filter) + app = QApplication.instance() + assert app is not None + app.installEventFilter(self._clickable_cursor_filter) # Wheel safety: sliders/spin boxes/combos only react to the wheel # while the right mouse button is held; a bare wheel just scrolls @@ -1737,6 +1751,7 @@ class MainWindow(QMainWindow): # Native primitives QSS can't recolor (spin/combo arrow glyphs) draw # from the app palette — flip its text roles with the theme. app = QApplication.instance() + assert isinstance(app, QApplication) # palette() lives on QApplication if not hasattr(self, "_default_palette"): self._default_palette = app.palette() if self._theme_mode == THEME_PORTRAIT: @@ -1763,7 +1778,7 @@ class MainWindow(QMainWindow): overlay.show() effect = QGraphicsOpacityEffect(overlay) overlay.setGraphicsEffect(effect) - fade = QPropertyAnimation(effect, b"opacity", overlay) + fade = QPropertyAnimation(effect, QByteArray(b"opacity"), overlay) fade.setDuration(THEME_FADE_MS) fade.setStartValue(1.0) fade.setEndValue(0.0) @@ -1772,7 +1787,8 @@ class MainWindow(QMainWindow): def _restore_theme_settings(self) -> None: settings = QSettings("PSI", "AareGUI") - self._theme_mode = settings.value("appearance/theme", THEME_ORIGINAL, type=str) + # str() wrap: settings.value is typed object even with type=str. + self._theme_mode = str(settings.value("appearance/theme", THEME_ORIGINAL, type=str)) def _save_theme_settings(self) -> None: settings = QSettings("PSI", "AareGUI") @@ -2439,7 +2455,7 @@ class MainWindow(QMainWindow): *self.findChildren(PopoutWindow), ] if owned: - for widget, was_visible in getattr(self, "_pre_watch_visibility", []): + for widget, was_visible in self._pre_watch_visibility or []: widget.setVisible(was_visible) # Docks restore via restoreState, not per-dock setVisible: a dock # TABBED BEHIND another is isHidden() at snapshot time, so a @@ -2447,7 +2463,7 @@ class MainWindow(QMainWindow): # (the vanished Sample List). restoreState also brings back # tab order, the active tab and dock sizes. Needs objectNames # on every dock. - state = getattr(self, "_pre_watch_dock_state", None) + state = self._pre_watch_dock_state if state is not None: self.restoreState(state) else: