diff --git a/ankiqt/config.py b/ankiqt/config.py index 81eaef646..fea582f5a 100644 --- a/ankiqt/config.py +++ b/ankiqt/config.py @@ -76,6 +76,7 @@ class Config(dict): 'showStudyStats': True, 'showCardTimer': True, 'extraNewCards': 5, + 'randomizeOnCram': True, 'created': time.time(), 'id': genID(), } diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index dcadfc353..0ebeb90d4 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -143,14 +143,15 @@ If it does not fix the problem, please copy the following
into a bug report:

""") pluginText = _("""\ -An error occurred in a plugin. Please contact the plugin author. -Please do not file a bug report with Anki.\n\n""") +An error occurred in a plugin. Please contact the plugin author.
+Please do not file a bug report with Anki.

""") if "plugin" in self.pool: txt = pluginText else: txt = stdText if self.pool: - ui.utils.showText(txt + self.pool[0:10000]) + ui.utils.showText(txt + self.pool[0:10000].replace( + "\n", "
")) self.pool = "" self.timer = None pipe = ErrorPipe(self) @@ -1050,9 +1051,9 @@ day = :d""", d=yesterday) """ % h stats2 = """\ - - - + + +
Reviews due today:%(ret)s
New due today:%(new)s
New due total:%(newof)s
Reviews due:%(ret)s
New today:%(new)s
New total:%(newof)s
""" % h if (not dyest and not dtoday) or not self.config['showStudyStats']: stats1 = "" @@ -1358,6 +1359,12 @@ day = :d""", d=yesterday) s = unicode(s) self.deck.save() # open tmp deck + if self.config['randomizeOnCram']: + n = 5 + else: + n = 3 + p = ui.utils.ProgressWin(self, _("Cram"), 0, n) + p.update(_("Copying cards...")) ndir = tempfile.mkdtemp(prefix="anki-cram") path = os.path.join(ndir, "cram.anki") from anki.exporting import AnkiExporter @@ -1368,7 +1375,9 @@ day = :d""", d=yesterday) e.exportInto(path) if not e.exportedCards: ui.utils.showInfo(_("No cards matched the provided tags.")) + p.finish() return + p.update(_("Loading deck...")) self.deck.close() self.deck = None self.loadDeck(path) @@ -1384,7 +1393,23 @@ day = :d""", d=yesterday) self.deck.easyIntervalMax = 0.25 self.deck.newCardOrder = 0 self.deck.syncName = None + if self.config['randomizeOnCram']: + p.update(_("Randomizing...")) + self.deck.s.statement( + "create temporary table idmap (old, new, primary key (old))") + self.deck.s.statement( + "insert into idmap select id, random() from facts") + self.deck.s.statement( + "update facts set id = (select new from idmap where old = id)") + p.update() + self.deck.s.statement( + "update cards set factId = (select new from idmap where old = factId)") + p.update() + self.deck.s.statement( + "update fields set factId = (select new from idmap where old = factId)") + p.update() self.reset() + p.finish() # Reviewing and learning ahead ########################################################################## diff --git a/ankiqt/ui/utils.py b/ankiqt/ui/utils.py index f01c18209..37f0829be 100644 --- a/ankiqt/ui/utils.py +++ b/ankiqt/ui/utils.py @@ -185,3 +185,31 @@ def mungeQA(deck, txt): return 'img src="%s"' % src txt = re.sub('img src="(.*?)"', quote, txt) return txt + +class ProgressWin(object): + + def __init__(self, parent, title, min, max): + self.diag = QProgressDialog("", "", min, max, parent) + self.diag.setWindowTitle(title) + self.diag.setCancelButton(None) + self.diag.setAutoClose(False) + self.diag.setAutoReset(False) + self.diag.setMinimumDuration(0) + self.diag.show() + self.counter = min + self.app = QApplication.instance() + self.app.processEvents() + self.min = min + self.max = max + + def update(self, label=None, val=None): + if label: + self.diag.setLabelText(label) + if val is None: + val = self.counter + self.counter += 1 + self.diag.setValue(val) + self.app.processEvents() + + def finish(self): + self.diag.cancel()