mirror of
https://github.com/ankitects/anki.git
synced 2025-12-10 21:36:55 -05:00
random on cram, add progress dialog, fix error msg, welcome screen tweak
This commit is contained in:
parent
d337404bcb
commit
2e2e756436
3 changed files with 60 additions and 6 deletions
|
|
@ -76,6 +76,7 @@ class Config(dict):
|
||||||
'showStudyStats': True,
|
'showStudyStats': True,
|
||||||
'showCardTimer': True,
|
'showCardTimer': True,
|
||||||
'extraNewCards': 5,
|
'extraNewCards': 5,
|
||||||
|
'randomizeOnCram': True,
|
||||||
'created': time.time(),
|
'created': time.time(),
|
||||||
'id': genID(),
|
'id': genID(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,14 +143,15 @@ If it does not fix the problem, please copy the following<br>
|
||||||
into a bug report:<br><br>
|
into a bug report:<br><br>
|
||||||
""")
|
""")
|
||||||
pluginText = _("""\
|
pluginText = _("""\
|
||||||
An error occurred in a plugin. Please contact the plugin author.
|
An error occurred in a plugin. Please contact the plugin author.<br>
|
||||||
Please do not file a bug report with Anki.\n\n""")
|
Please do not file a bug report with Anki.<br><br>""")
|
||||||
if "plugin" in self.pool:
|
if "plugin" in self.pool:
|
||||||
txt = pluginText
|
txt = pluginText
|
||||||
else:
|
else:
|
||||||
txt = stdText
|
txt = stdText
|
||||||
if self.pool:
|
if self.pool:
|
||||||
ui.utils.showText(txt + self.pool[0:10000])
|
ui.utils.showText(txt + self.pool[0:10000].replace(
|
||||||
|
"\n", "<br>"))
|
||||||
self.pool = ""
|
self.pool = ""
|
||||||
self.timer = None
|
self.timer = None
|
||||||
pipe = ErrorPipe(self)
|
pipe = ErrorPipe(self)
|
||||||
|
|
@ -1050,9 +1051,9 @@ day = :d""", d=yesterday)
|
||||||
</table>""" % h
|
</table>""" % h
|
||||||
stats2 = """\
|
stats2 = """\
|
||||||
<table>
|
<table>
|
||||||
<tr><td width=120>Reviews due today:</td><td align=right><b>%(ret)s</b></td></tr>
|
<tr><td width=120>Reviews due:</td><td align=right><b>%(ret)s</b></td></tr>
|
||||||
<tr><td>New due today:</td><td align=right><b>%(new)s</b></td></tr>
|
<tr><td>New today:</td><td align=right><b>%(new)s</b></td></tr>
|
||||||
<tr><td>New due total:</td><td align=right>%(newof)s</td></tr>
|
<tr><td>New total:</td><td align=right>%(newof)s</td></tr>
|
||||||
</table>""" % h
|
</table>""" % h
|
||||||
if (not dyest and not dtoday) or not self.config['showStudyStats']:
|
if (not dyest and not dtoday) or not self.config['showStudyStats']:
|
||||||
stats1 = ""
|
stats1 = ""
|
||||||
|
|
@ -1358,6 +1359,12 @@ day = :d""", d=yesterday)
|
||||||
s = unicode(s)
|
s = unicode(s)
|
||||||
self.deck.save()
|
self.deck.save()
|
||||||
# open tmp deck
|
# 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")
|
ndir = tempfile.mkdtemp(prefix="anki-cram")
|
||||||
path = os.path.join(ndir, "cram.anki")
|
path = os.path.join(ndir, "cram.anki")
|
||||||
from anki.exporting import AnkiExporter
|
from anki.exporting import AnkiExporter
|
||||||
|
|
@ -1368,7 +1375,9 @@ day = :d""", d=yesterday)
|
||||||
e.exportInto(path)
|
e.exportInto(path)
|
||||||
if not e.exportedCards:
|
if not e.exportedCards:
|
||||||
ui.utils.showInfo(_("No cards matched the provided tags."))
|
ui.utils.showInfo(_("No cards matched the provided tags."))
|
||||||
|
p.finish()
|
||||||
return
|
return
|
||||||
|
p.update(_("Loading deck..."))
|
||||||
self.deck.close()
|
self.deck.close()
|
||||||
self.deck = None
|
self.deck = None
|
||||||
self.loadDeck(path)
|
self.loadDeck(path)
|
||||||
|
|
@ -1384,7 +1393,23 @@ 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()
|
||||||
self.reset()
|
self.reset()
|
||||||
|
p.finish()
|
||||||
|
|
||||||
# Reviewing and learning ahead
|
# Reviewing and learning ahead
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
||||||
|
|
@ -185,3 +185,31 @@ def mungeQA(deck, txt):
|
||||||
return 'img src="%s"' % src
|
return 'img src="%s"' % src
|
||||||
txt = re.sub('img src="(.*?)"', quote, txt)
|
txt = re.sub('img src="(.*?)"', quote, txt)
|
||||||
return 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()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue