diff --git a/qt/aqt/browser/browser.py b/qt/aqt/browser/browser.py index ef607e357..86b7fb50d 100644 --- a/qt/aqt/browser/browser.py +++ b/qt/aqt/browser/browser.py @@ -40,7 +40,7 @@ from aqt.undo import UndoActionsInfo from aqt.utils import ( HelpPage, KeyboardModifiersPressed, - current_top_level_widget, + current_window, ensure_editor_saved, getTag, no_arg_trigger, @@ -112,7 +112,7 @@ class Browser(QMainWindow): def on_operation_did_execute( self, changes: OpChanges, handler: Optional[object] ) -> None: - focused = current_top_level_widget() == self + focused = current_window() == self self.table.op_executed(changes, handler, focused) self.sidebar.op_executed(changes, handler, focused) if changes.editor: @@ -135,7 +135,7 @@ class Browser(QMainWindow): self._update_context_actions() def on_focus_change(self, new: Optional[QWidget], old: Optional[QWidget]) -> None: - if current_top_level_widget() == self: + if current_window() == self: self.setUpdatesEnabled(True) self.table.redraw_cells() self.sidebar.refresh_if_needed() diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 004de77b4..296ef23f4 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -66,7 +66,7 @@ from aqt.utils import ( KeyboardModifiersPressed, askUser, checkInvalidFilename, - current_top_level_widget, + current_window, disable_help_button, getFile, getOnlyText, @@ -80,7 +80,6 @@ from aqt.utils import ( showInfo, showWarning, tooltip, - top_level_widget, tr, ) @@ -725,7 +724,7 @@ class AnkiQt(QMainWindow): self, changes: OpChanges, handler: Optional[object] ) -> None: "Notify current screen of changes." - focused = current_top_level_widget() == self + focused = current_window() == self if self.state == "review": dirty = self.reviewer.op_executed(changes, handler, focused) elif self.state == "overview": @@ -745,7 +744,7 @@ class AnkiQt(QMainWindow): self, new_focus: Optional[QWidget], _old: Optional[QWidget] ) -> None: "If main window has received focus, ensure current UI state is updated." - if new_focus and top_level_widget(new_focus) == self: + if new_focus and new_focus.window() == self: if self.state == "review": self.reviewer.refresh_if_needed() elif self.state == "overview": diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 5d5ddbcdf..3870ee55e 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -721,16 +721,9 @@ def downArrow() -> str: return "▾" -def top_level_widget(widget: QWidget) -> QWidget: - window = None - while widget := widget.parentWidget(): - window = widget - return window - - -def current_top_level_widget() -> Optional[QWidget]: +def current_window() -> Optional[QWidget]: if widget := QApplication.focusWidget(): - return top_level_widget(widget) + return widget.window() else: return None