def run_in_background(self, *, initiator: object | None = None) -> None: from aqt import mw assert mw mw._increase_background_ops() def wrapped_op() -> ResultWithChanges: assert mw return self._op(mw.col) def wrapped_done(future: Future) -> None: assert mw mw._decrease_background_ops() # did something go wrong? if exception := future.exception(): if isinstance(exception, Exception): if self._failure: self._failure(exception) else: show_exception(parent=self._parent, exception=exception) return else: # BaseException like SystemExit; rethrow it future.result() result = future.result() try: if self._success: self._success(result) finally: mw.update_undo_actions() mw.autosave() # fire change hooks self._fire_change_hooks_after_op_performed(result, initiator)
def _legacy_undo(*, parent: QWidget) -> None: from aqt import mw assert mw assert mw.col reviewing = mw.state == "review" just_refresh_reviewer = False result = mw.col.undo_legacy() if result is None: # should not happen showInfo("nothing to undo", parent=parent) mw.update_undo_actions() return elif isinstance(result, LegacyReviewUndo): name = tr.scheduling_review() if reviewing: # push the undone card to the top of the queue cid = result.card.id card = mw.col.get_card(cid) mw.reviewer.cardQueue.append(card) gui_hooks.review_did_undo(cid) just_refresh_reviewer = True elif isinstance(result, LegacyCheckpoint): name = result.name else: assert_exhaustive(result) assert False if just_refresh_reviewer: mw.reviewer.nextCard() else: # full queue+gui reset required mw.reset() tooltip(tr.undo_action_undone(action=name), parent=parent) gui_hooks.state_did_revert(name) mw.update_undo_actions()