From aea7eb667e2c78de3a99436e458f413b9e765226 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Fri, 22 Apr 2022 06:47:17 +0200 Subject: [PATCH] Fix progress of chained operations (#1817) * Fix progress of chained operations Especially aborting colpkg import. * Notify about missing progress dialog --- qt/aqt/importing.py | 7 ++++--- qt/aqt/operations/__init__.py | 11 +++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/qt/aqt/importing.py b/qt/aqt/importing.py index c45570486..0168d2c9c 100644 --- a/qt/aqt/importing.py +++ b/qt/aqt/importing.py @@ -14,7 +14,7 @@ import aqt.modelchooser from anki.errors import Interrupted from anki.importing.anki2 import V2ImportIntoV1 from anki.importing.apkg import AnkiPackageImporter -from aqt import AnkiQt, gui_hooks +from aqt.main import AnkiQt, gui_hooks from aqt.operations import QueryOp from aqt.qt import * from aqt.utils import ( @@ -460,12 +460,13 @@ def full_apkg_import(mw: AnkiQt, file: str) -> None: def replace_with_apkg( - mw: aqt.AnkiQt, filename: str, callback: Callable[[bool], None] + mw: AnkiQt, filename: str, callback: Callable[[bool], None] ) -> None: """Tries to replace the provided collection with the provided backup, then calls the callback. True if success. """ - dialog = mw.progress.start(immediate=True) + if not (dialog := mw.progress.start(immediate=True)): + print("No progress dialog during import; aborting will not work") timer = QTimer() timer.setSingleShot(False) timer.setInterval(100) diff --git a/qt/aqt/operations/__init__.py b/qt/aqt/operations/__init__.py index 0fd4dbad1..7d7ad8b91 100644 --- a/qt/aqt/operations/__init__.py +++ b/qt/aqt/operations/__init__.py @@ -217,6 +217,10 @@ class QueryOp(Generic[T]): def wrapped_done(future: Future) -> None: assert mw + + if self._progress: + mw.progress.finish() + mw._decrease_background_ops() # did something go wrong? if exception := future.exception(): @@ -230,11 +234,6 @@ class QueryOp(Generic[T]): # BaseException like SystemExit; rethrow it future.result() - result = future.result() - try: - self._success(result) - finally: - if self._progress: - mw.progress.finish() + self._success(future.result()) mw.taskman.run_in_background(wrapped_op, wrapped_done)