Anki/aqt/dyndeckconf.py
Damien Elmes 3e45c56f3a improve filtered decks
- add a custom study option to the deck overview. it combines the
  ability to increase the daily limits with the ability to create filtered
  decks based on presets
- removed the presets from the filtered deck dialog.
- moved the filter/cram button on the decks/overview screen to the tools menu
- filtered decks no longer show their search terms (easily findable by
  clicking options), and instead show a brief explanation of how they work.
- the filter by tags preset now presents a dialog like anki 1.2's active tags
  dialog. decks will remember their previously selected tags.
- the custom study option creates a deck called "Custom Study Session", which
  will automatically get reused if you custom study in a different deck. you
  can rename it if you want to keep it.
- filtered decks now show in the deck list as blue
2012-10-26 01:58:46 +09:00

113 lines
3.5 KiB
Python

# Copyright: Damien Elmes <anki@ichi2.net>
# -*- coding: utf-8 -*-
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from aqt.qt import *
import aqt
from anki.utils import ids2str, isWin, isMac
from aqt.utils import showInfo, showWarning, openHelp, getOnlyText, askUser
from operator import itemgetter
class DeckConf(QDialog):
def __init__(self, mw, first=False, search="", deck=None):
QDialog.__init__(self, mw)
self.mw = mw
self.deck = deck or self.mw.col.decks.current()
# context-sensitive extras like deck:foo
self.search = search
self.form = aqt.forms.dyndconf.Ui_Dialog()
self.form.setupUi(self)
if first:
label = _("Build")
else:
label = _("Rebuild")
self.ok = self.form.buttonBox.addButton(
label, QDialogButtonBox.AcceptRole)
self.mw.checkpoint(_("Options"))
self.setWindowModality(Qt.WindowModal)
self.connect(self.form.buttonBox,
SIGNAL("helpRequested()"),
lambda: openHelp("filtered"))
self.setWindowTitle(_("Options for %s") % self.deck['name'])
self.setupOrder()
self.loadConf()
self.show()
self.exec_()
def setupOrder(self):
import anki.consts as cs
self.form.order.addItems(cs.dynOrderLabels().values())
def loadConf(self):
f = self.form
d = self.deck
search, limit, order = d['terms'][0]
f.search.setText(search)
if d['delays']:
f.steps.setText(self.listToUser(d['delays']))
f.stepsOn.setChecked(True)
else:
f.steps.setText("1 10")
f.stepsOn.setChecked(False)
f.resched.setChecked(d['resched'])
f.order.setCurrentIndex(order)
f.limit.setValue(limit)
def saveConf(self):
f = self.form
d = self.deck
d['delays'] = None
if f.stepsOn.isChecked():
steps = self.userToList(f.steps)
if steps:
d['delays'] = steps
else:
d['delays'] = None
d['terms'][0] = [f.search.text(),
f.limit.value(),
f.order.currentIndex()]
d['resched'] = f.resched.isChecked()
self.mw.col.decks.save(d)
return True
def reject(self):
self.ok = False
QDialog.reject(self)
def accept(self):
if not self.saveConf():
return
if not self.mw.col.sched.rebuildDyn():
if askUser(_("""\
The provided search did not match any cards. Would you like to revise \
it?""")):
return
self.mw.reset()
QDialog.accept(self)
# Step load/save - fixme: share with std options screen
########################################################
def listToUser(self, l):
return " ".join([str(x) for x in l])
def userToList(self, w, minSize=1):
items = unicode(w.text()).split(" ")
ret = []
for i in items:
if not i:
continue
try:
i = float(i)
assert i > 0
if i == int(i):
i = int(i)
ret.append(i)
except:
# invalid, don't update
showWarning(_("Steps must be numbers."))
return
if len(ret) < minSize:
showWarning(_("At least one step is required."))
return
return ret