fix timebox causing crash

When a modal was created with another window as its parent, the other
window was being returned, when it was the current window that we
actually wanted. This caused nextCard() to be called again when it
presented the timebox modal, leading to a stack overflow.

https://forums.ankiweb.net/t/anki-2-1-45-alpha/10061/71
This commit is contained in:
Damien Elmes 2021-06-01 15:16:53 +10:00
parent 50961a9196
commit e124f935a5
3 changed files with 8 additions and 16 deletions

View File

@ -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()

View File

@ -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":

View File

@ -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