mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
cramming support
This commit is contained in:
parent
17798b03f4
commit
cac5fd2347
2 changed files with 50 additions and 4 deletions
|
@ -15,7 +15,7 @@ from PyQt4.QtGui import *
|
||||||
from anki import DeckStorage
|
from anki import DeckStorage
|
||||||
from anki.errors import *
|
from anki.errors import *
|
||||||
from anki.sound import hasSound, playFromText
|
from anki.sound import hasSound, playFromText
|
||||||
from anki.utils import addTags, deleteTags
|
from anki.utils import addTags, deleteTags, parseTags
|
||||||
from anki.media import rebuildMediaDir
|
from anki.media import rebuildMediaDir
|
||||||
from anki.db import OperationalError
|
from anki.db import OperationalError
|
||||||
from anki.stdmodels import BasicModel
|
from anki.stdmodels import BasicModel
|
||||||
|
@ -585,16 +585,19 @@ class AnkiQt(QMainWindow):
|
||||||
|
|
||||||
def saveAndClose(self, exit=False):
|
def saveAndClose(self, exit=False):
|
||||||
"(Auto)save and close. Prompt if necessary. True if okay to proceed."
|
"(Auto)save and close. Prompt if necessary. True if okay to proceed."
|
||||||
|
cramming = False
|
||||||
if self.deck is not None:
|
if self.deck is not None:
|
||||||
|
oldName = self.deck.name()
|
||||||
|
cramming = oldName == "cram"
|
||||||
# sync (saving automatically)
|
# sync (saving automatically)
|
||||||
if self.config['syncOnClose'] and self.deck.syncName:
|
if self.config['syncOnClose'] and self.deck.syncName and not cramming:
|
||||||
self.syncDeck(False, reload=False)
|
self.syncDeck(False, reload=False)
|
||||||
while self.deckPath:
|
while self.deckPath:
|
||||||
self.app.processEvents()
|
self.app.processEvents()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
return True
|
return True
|
||||||
# save
|
# save
|
||||||
if self.deck.modifiedSinceSave():
|
if self.deck.modifiedSinceSave() and not cramming:
|
||||||
if self.config['saveOnClose'] or self.config['syncOnClose']:
|
if self.config['saveOnClose'] or self.config['syncOnClose']:
|
||||||
self.saveDeck()
|
self.saveDeck()
|
||||||
else:
|
else:
|
||||||
|
@ -609,7 +612,10 @@ class AnkiQt(QMainWindow):
|
||||||
self.deck.rollback()
|
self.deck.rollback()
|
||||||
self.deck = None
|
self.deck = None
|
||||||
if not exit:
|
if not exit:
|
||||||
self.moveToState("noDeck")
|
if cramming:
|
||||||
|
self.loadRecent(0)
|
||||||
|
else:
|
||||||
|
self.moveToState("noDeck")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def onNew(self):
|
def onNew(self):
|
||||||
|
@ -985,6 +991,38 @@ class AnkiQt(QMainWindow):
|
||||||
def onExport(self):
|
def onExport(self):
|
||||||
ui.exporting.ExportDialog(self)
|
ui.exporting.ExportDialog(self)
|
||||||
|
|
||||||
|
# Cramming
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
def onCram(self):
|
||||||
|
(s, ret) = QInputDialog.getText(self, _("Anki"), _("Tags to cram:"))
|
||||||
|
if not ret:
|
||||||
|
return
|
||||||
|
s = unicode(s)
|
||||||
|
self.deck.save()
|
||||||
|
# open tmp deck
|
||||||
|
import tempfile
|
||||||
|
dir = tempfile.mkdtemp(prefix="anki-cram")
|
||||||
|
path = os.path.join(dir, "cram.anki")
|
||||||
|
from anki.exporting import AnkiExporter
|
||||||
|
e = AnkiExporter(self.deck)
|
||||||
|
if s:
|
||||||
|
e.limitTags = parseTags(s)
|
||||||
|
e.exportInto(path)
|
||||||
|
# load
|
||||||
|
self.loadDeck(path)
|
||||||
|
self.config['recentDeckPaths'].pop(0)
|
||||||
|
self.deck.newCardsPerDay = 999999
|
||||||
|
self.deck.delay0 = 300
|
||||||
|
self.deck.delay1 = 600
|
||||||
|
self.deck.hardIntervalMin = 0.01388
|
||||||
|
self.deck.hardIntervalMax = 0.02083
|
||||||
|
self.deck.midIntervalMin = 0.0416
|
||||||
|
self.deck.midIntervalMax = 0.0486
|
||||||
|
self.deck.easyIntervalMin = 0.2083
|
||||||
|
self.deck.easyIntervalMax = 0.25
|
||||||
|
self.rebuildQueue()
|
||||||
|
|
||||||
# Language handling
|
# Language handling
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -1180,6 +1218,7 @@ class AnkiQt(QMainWindow):
|
||||||
self.connect(m.actionOptimizeDatabase, s, self.onOptimizeDB)
|
self.connect(m.actionOptimizeDatabase, s, self.onOptimizeDB)
|
||||||
self.connect(m.actionMergeModels, s, self.onMergeModels)
|
self.connect(m.actionMergeModels, s, self.onMergeModels)
|
||||||
self.connect(m.actionCheckMediaDatabase, s, self.onCheckMediaDB)
|
self.connect(m.actionCheckMediaDatabase, s, self.onCheckMediaDB)
|
||||||
|
self.connect(m.actionCram, s, self.onCram)
|
||||||
|
|
||||||
def enableDeckMenuItems(self, enabled=True):
|
def enableDeckMenuItems(self, enabled=True):
|
||||||
"setEnabled deck-related items."
|
"setEnabled deck-related items."
|
||||||
|
|
|
@ -450,6 +450,8 @@
|
||||||
<addaction name="actionCstats" />
|
<addaction name="actionCstats" />
|
||||||
<addaction name="separator" />
|
<addaction name="separator" />
|
||||||
<addaction name="menu_Lookup" />
|
<addaction name="menu_Lookup" />
|
||||||
|
<addaction name="separator" />
|
||||||
|
<addaction name="actionCram" />
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuAdvanced" >
|
<widget class="QMenu" name="menuAdvanced" >
|
||||||
<property name="title" >
|
<property name="title" >
|
||||||
|
@ -924,6 +926,11 @@
|
||||||
<string>Open Online..</string>
|
<string>Open Online..</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionCram" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>C&ram..</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../icons.qrc" />
|
<include location="../icons.qrc" />
|
||||||
|
|
Loading…
Reference in a new issue