Example #1
0
    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)
Example #2
0
 def changeDueSelected(self,
                       cids,
                       start=1,
                       step=0,
                       shuffle=False,
                       shift=False):
     mw.checkpoint(_("Rescheduled"))
     mw.progress.start()
     for cid in cids:
         card = mw.col.getCard(cid)
         if shuffle:
             due = random.randint(start, start + step)
             self.changeDue(card, due)
         else:
             self.changeDue(card, start)
         if shift: start += step
     mw.autosave()
     mw.progress.finish()
Example #3
0
 def reschedSelected(self, cids, imin, imax, logging=True, lbal=False):
     "wrapper, access to util function"
     mw.progress.start()
     customReschedCards(cids, imin, imax, logging, lbal)
     mw.autosave()
     mw.progress.finish()
Example #4
0
 def forgetSelected(self, cids, logging=True):
     "wrapper, access to util function"
     mw.progress.start()
     customForgetCards(cids, logging)
     mw.autosave()
     mw.progress.finish()
Example #5
0
 def _finished(self, card, msg):
     #for warrior mode last_card preview
     mw.reviewer._answeredIds.append(card.id)
     mw.autosave()
     mw.reset()
     tooltipHint(msg, 1200)