From 79932aad41e9ec24677d2e0551333a0d4c8bc728 Mon Sep 17 00:00:00 2001 From: Abdo Date: Tue, 19 Aug 2025 20:02:51 +0300 Subject: [PATCH] Fix sync errors not being reported in some cases (#4281) * Set parent of sync error dialog * Explicitly mention parent arg in show_info() functions --- qt/aqt/sync.py | 2 +- qt/aqt/utils.py | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/qt/aqt/sync.py b/qt/aqt/sync.py index 94ce0c8c1..9b29ada20 100644 --- a/qt/aqt/sync.py +++ b/qt/aqt/sync.py @@ -73,7 +73,7 @@ def handle_sync_error(mw: aqt.main.AnkiQt, err: Exception) -> None: elif isinstance(err, Interrupted): # no message to show return - show_warning(str(err)) + show_warning(str(err), parent=mw) def on_normal_sync_timer(mw: aqt.main.AnkiQt) -> None: diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 64d057082..43efc513f 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -226,29 +226,45 @@ def ask_user_dialog( ) -def show_info(text: str, callback: Callable | None = None, **kwargs: Any) -> MessageBox: +def show_info( + text: str, + callback: Callable | None = None, + parent: QWidget | None = None, + **kwargs: Any, +) -> MessageBox: "Show a small info window with an OK button." if "icon" not in kwargs: kwargs["icon"] = QMessageBox.Icon.Information return MessageBox( text, callback=(lambda _: callback()) if callback is not None else None, + parent=parent, **kwargs, ) def show_warning( - text: str, callback: Callable | None = None, **kwargs: Any + text: str, + callback: Callable | None = None, + parent: QWidget | None = None, + **kwargs: Any, ) -> MessageBox: "Show a small warning window with an OK button." - return show_info(text, icon=QMessageBox.Icon.Warning, callback=callback, **kwargs) + return show_info( + text, icon=QMessageBox.Icon.Warning, callback=callback, parent=parent, **kwargs + ) def show_critical( - text: str, callback: Callable | None = None, **kwargs: Any + text: str, + callback: Callable | None = None, + parent: QWidget | None = None, + **kwargs: Any, ) -> MessageBox: "Show a small critical error window with an OK button." - return show_info(text, icon=QMessageBox.Icon.Critical, callback=callback, **kwargs) + return show_info( + text, icon=QMessageBox.Icon.Critical, callback=callback, parent=parent, **kwargs + ) def showWarning(