increase cram randomization speed by a factor of 5, prevent add cards open on cram

This commit is contained in:
Damien Elmes 2009-04-23 03:46:22 +09:00
parent 2ab8b7a574
commit af2bd52003

View file

@ -685,8 +685,7 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
def onClose(self): def onClose(self):
if self.inMainWindow(): if self.inMainWindow():
cramming = self.deck is not None and self.deck.name() == "cram" self.saveAndClose(hideWelcome=self.isCramming())
self.saveAndClose(hideWelcome=cramming)
if cramming: if cramming:
self.loadRecent(0) self.loadRecent(0)
else: else:
@ -1374,6 +1373,9 @@ day = :d""", d=yesterday)
########################################################################## ##########################################################################
def onAddCard(self): def onAddCard(self):
if self.isCramming():
ui.utils.showInfo(_("Can't add cards while cramming."))
return
ui.dialogs.get("AddCards", self) ui.dialogs.get("AddCards", self)
def onEditDeck(self): def onEditDeck(self):
@ -1437,8 +1439,11 @@ day = :d""", d=yesterday)
e.exportInto(path) e.exportInto(path)
return (e, path) return (e, path)
def isCramming(self):
return self.deck is not None and self.deck.name() == "cram"
def onCram(self, cardIds=[]): def onCram(self, cardIds=[]):
if self.deck.name() == "cram": if self.isCramming():
ui.utils.showInfo( ui.utils.showInfo(
_("Already cramming. Please close this deck first.")) _("Already cramming. Please close this deck first."))
return return
@ -1458,7 +1463,7 @@ day = :d""", d=yesterday)
ui.utils.showInfo(_("No cards matched the provided tags.")) ui.utils.showInfo(_("No cards matched the provided tags."))
return return
if self.config['randomizeOnCram']: if self.config['randomizeOnCram']:
n = 5 n = 3
else: else:
n = 2 n = 2
p = ui.utils.ProgressWin(self, n, 0, _("Cram")) p = ui.utils.ProgressWin(self, n, 0, _("Cram"))
@ -1478,22 +1483,11 @@ day = :d""", d=yesterday)
self.deck.easyIntervalMax = 0.25 self.deck.easyIntervalMax = 0.25
self.deck.newCardOrder = 0 self.deck.newCardOrder = 0
self.deck.syncName = None 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() p.update()
self.deck.updateDynamicIndices() self.deck.updateDynamicIndices()
if self.config['randomizeOnCram']:
p.update(_("Randomizing..."))
self.deck.randomizeNewCards()
self.reset() self.reset()
p.finish() p.finish()