2019-02-05 04:59:03 +01:00
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
2012-12-21 08:51:59 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
|
|
|
import aqt
|
2019-03-04 02:58:34 +01:00
|
|
|
from anki.lang import _
|
2019-12-20 10:19:03 +01:00
|
|
|
from aqt.qt import *
|
|
|
|
from aqt.utils import askUser, openHelp, restoreGeom, saveGeom, showWarning
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
self.search = search
|
|
|
|
self.form = aqt.forms.dyndconf.Ui_Dialog()
|
|
|
|
self.form.setupUi(self)
|
|
|
|
if first:
|
|
|
|
label = _("Build")
|
|
|
|
else:
|
|
|
|
label = _("Rebuild")
|
2019-12-23 01:34:10 +01:00
|
|
|
self.ok = self.form.buttonBox.addButton(label, QDialogButtonBox.AcceptRole)
|
2012-12-21 08:51:59 +01:00
|
|
|
self.mw.checkpoint(_("Options"))
|
|
|
|
self.setWindowModality(Qt.WindowModal)
|
2016-05-31 10:51:40 +02:00
|
|
|
self.form.buttonBox.helpRequested.connect(lambda: openHelp("filtered"))
|
2019-12-23 01:34:10 +01:00
|
|
|
self.setWindowTitle(_("Options for %s") % self.deck["name"])
|
2014-06-18 20:47:45 +02:00
|
|
|
restoreGeom(self, "dyndeckconf")
|
2018-01-20 06:26:11 +01:00
|
|
|
self.initialSetup()
|
2012-12-21 08:51:59 +01:00
|
|
|
self.loadConf()
|
|
|
|
if search:
|
2018-01-14 04:08:38 +01:00
|
|
|
self.form.search.setText(search + " is:due")
|
|
|
|
self.form.search_2.setText(search + " is:new")
|
2012-12-21 08:51:59 +01:00
|
|
|
self.form.search.selectAll()
|
2018-01-14 10:20:01 +01:00
|
|
|
|
|
|
|
if self.mw.col.schedVer() == 1:
|
|
|
|
self.form.secondFilter.setVisible(False)
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
self.show()
|
|
|
|
self.exec_()
|
2014-06-18 20:47:45 +02:00
|
|
|
saveGeom(self, "dyndeckconf")
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2018-01-20 06:26:11 +01:00
|
|
|
def initialSetup(self):
|
2012-12-21 08:51:59 +01:00
|
|
|
import anki.consts as cs
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2016-05-12 06:45:35 +02:00
|
|
|
self.form.order.addItems(list(cs.dynOrderLabels().values()))
|
2018-01-14 04:08:38 +01:00
|
|
|
self.form.order_2.addItems(list(cs.dynOrderLabels().values()))
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2018-01-20 06:26:11 +01:00
|
|
|
self.form.resched.stateChanged.connect(self._onReschedToggled)
|
|
|
|
|
|
|
|
def _onReschedToggled(self, _state):
|
2019-12-23 01:34:10 +01:00
|
|
|
self.form.previewDelayWidget.setVisible(
|
|
|
|
not self.form.resched.isChecked() and self.mw.col.schedVer() > 1
|
|
|
|
)
|
2018-01-20 06:26:11 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def loadConf(self):
|
|
|
|
f = self.form
|
|
|
|
d = self.deck
|
2018-01-14 04:08:38 +01:00
|
|
|
|
2019-12-23 01:34:10 +01:00
|
|
|
f.resched.setChecked(d["resched"])
|
2018-01-20 06:26:11 +01:00
|
|
|
self._onReschedToggled(0)
|
2018-01-14 04:08:38 +01:00
|
|
|
|
2019-12-23 01:34:10 +01:00
|
|
|
search, limit, order = d["terms"][0]
|
2012-12-21 08:51:59 +01:00
|
|
|
f.search.setText(search)
|
2018-04-30 08:26:43 +02:00
|
|
|
|
|
|
|
if self.mw.col.schedVer() == 1:
|
2019-12-23 01:34:10 +01:00
|
|
|
if d["delays"]:
|
|
|
|
f.steps.setText(self.listToUser(d["delays"]))
|
2018-04-30 08:26:43 +02:00
|
|
|
f.stepsOn.setChecked(True)
|
|
|
|
else:
|
|
|
|
f.steps.setVisible(False)
|
|
|
|
f.stepsOn.setVisible(False)
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
f.order.setCurrentIndex(order)
|
|
|
|
f.limit.setValue(limit)
|
2018-01-20 06:26:11 +01:00
|
|
|
f.previewDelay.setValue(d.get("previewDelay", 10))
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2019-12-23 01:34:10 +01:00
|
|
|
if len(d["terms"]) > 1:
|
|
|
|
search, limit, order = d["terms"][1]
|
2018-01-14 04:08:38 +01:00
|
|
|
f.search_2.setText(search)
|
|
|
|
f.order_2.setCurrentIndex(order)
|
|
|
|
f.limit_2.setValue(limit)
|
|
|
|
f.secondFilter.setChecked(True)
|
|
|
|
f.filter2group.setVisible(True)
|
|
|
|
else:
|
|
|
|
f.order_2.setCurrentIndex(5)
|
|
|
|
f.limit_2.setValue(20)
|
|
|
|
f.secondFilter.setChecked(False)
|
|
|
|
f.filter2group.setVisible(False)
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def saveConf(self):
|
|
|
|
f = self.form
|
|
|
|
d = self.deck
|
2019-12-23 01:34:10 +01:00
|
|
|
d["resched"] = f.resched.isChecked()
|
|
|
|
d["delays"] = None
|
2018-01-14 04:08:38 +01:00
|
|
|
|
2018-04-30 08:26:43 +02:00
|
|
|
if self.mw.col.schedVer() == 1 and f.stepsOn.isChecked():
|
|
|
|
steps = self.userToList(f.steps)
|
|
|
|
if steps:
|
2019-12-23 01:34:10 +01:00
|
|
|
d["delays"] = steps
|
2018-04-30 08:26:43 +02:00
|
|
|
else:
|
2019-12-23 01:34:10 +01:00
|
|
|
d["delays"] = None
|
2018-04-30 08:26:43 +02:00
|
|
|
|
2019-12-23 01:34:10 +01:00
|
|
|
terms = [[f.search.text(), f.limit.value(), f.order.currentIndex()]]
|
2018-01-14 04:08:38 +01:00
|
|
|
|
|
|
|
if f.secondFilter.isChecked():
|
2019-12-23 01:34:10 +01:00
|
|
|
terms.append(
|
|
|
|
[f.search_2.text(), f.limit_2.value(), f.order_2.currentIndex()]
|
|
|
|
)
|
2018-01-14 04:08:38 +01:00
|
|
|
|
2019-12-23 01:34:10 +01:00
|
|
|
d["terms"] = terms
|
|
|
|
d["previewDelay"] = f.previewDelay.value()
|
2018-01-14 04:08:38 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
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():
|
2019-12-23 01:34:10 +01:00
|
|
|
if askUser(
|
|
|
|
_(
|
|
|
|
"""\
|
2012-12-21 08:51:59 +01:00
|
|
|
The provided search did not match any cards. Would you like to revise \
|
2019-12-23 01:34:10 +01:00
|
|
|
it?"""
|
|
|
|
)
|
|
|
|
):
|
2012-12-21 08:51:59 +01:00
|
|
|
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):
|
2016-05-12 06:45:35 +02:00
|
|
|
items = str(w.text()).split(" ")
|
2012-12-21 08:51:59 +01:00
|
|
|
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
|