From d5707a63881c14e45eca8aaebd48ca7a305bdeb7 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 16 Jan 2020 11:26:22 +1000 Subject: [PATCH] don't change current deck if custom study fails to create just a quick fix for now https://anki.tenderapp.com/discussions/ankidesktop/37834-bug-custom-study-session-created-even-when-there-are-no-cards-that-match-selected-criteria --- qt/aqt/customstudy.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qt/aqt/customstudy.py b/qt/aqt/customstudy.py index d41a35445..dce9b9dde 100644 --- a/qt/aqt/customstudy.py +++ b/qt/aqt/customstudy.py @@ -22,12 +22,13 @@ TYPE_ALL = 3 class CustomStudy(QDialog): - def __init__(self, mw): + def __init__(self, mw) -> None: QDialog.__init__(self, mw) self.mw = mw self.deck = self.mw.col.decks.current() self.conf = self.mw.col.decks.getConf(self.deck["conf"]) self.form = f = aqt.forms.customstudy.Ui_Dialog() + self.created_custom_study = False f.setupUi(self) self.setWindowModality(Qt.WindowModal) self.setupSignals() @@ -179,11 +180,19 @@ class CustomStudy(QDialog): # add deck limit dyn["terms"][0][0] = 'deck:"%s" %s ' % (self.deck["name"], dyn["terms"][0][0]) # generate cards + self.created_custom_study = True if not self.mw.col.sched.rebuildDyn(): return showWarning(_("No cards matched the criteria you provided.")) self.mw.moveToState("overview") QDialog.accept(self) + def reject(self) -> None: + if self.created_custom_study: + # set the original deck back to current + self.mw.col.decks.select(self.deck['id']) + # fixme: clean up the empty custom study deck + QDialog.reject(self) + def _getTags(self): from aqt.taglimit import TagLimit