mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
cram creation & config
This commit is contained in:
parent
84fc02901d
commit
8fd29bed1c
5 changed files with 308 additions and 7 deletions
|
@ -38,6 +38,8 @@ class DeckBrowser(object):
|
||||||
self._onShared()
|
self._onShared()
|
||||||
elif cmd == "import":
|
elif cmd == "import":
|
||||||
self.mw.onImport()
|
self.mw.onImport()
|
||||||
|
elif cmd == "cram":
|
||||||
|
self.mw.onCram()
|
||||||
elif cmd == "drag":
|
elif cmd == "drag":
|
||||||
draggedDeckDid, ontoDeckDid = arg.split(',')
|
draggedDeckDid, ontoDeckDid = arg.split(',')
|
||||||
self._dragDeckOnto(draggedDeckDid, ontoDeckDid)
|
self._dragDeckOnto(draggedDeckDid, ontoDeckDid)
|
||||||
|
@ -220,6 +222,7 @@ Are you sure you wish to delete all of the cards in %s?""")%deck['name']):
|
||||||
links = [
|
links = [
|
||||||
["shared", _("Get Shared")],
|
["shared", _("Get Shared")],
|
||||||
["import", _("Import File")],
|
["import", _("Import File")],
|
||||||
|
["cram", _("Cram")],
|
||||||
]
|
]
|
||||||
buf = ""
|
buf = ""
|
||||||
for b in links:
|
for b in links:
|
||||||
|
|
91
aqt/dyndeckconf.py
Normal file
91
aqt/dyndeckconf.py
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
# 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, simplejson
|
||||||
|
from anki.utils import ids2str
|
||||||
|
from aqt.utils import showInfo, showWarning, openHelp, getOnlyText
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
|
class DeckConf(QDialog):
|
||||||
|
def __init__(self, mw):
|
||||||
|
QDialog.__init__(self, mw)
|
||||||
|
self.mw = mw
|
||||||
|
self.deck = self.mw.col.decks.current()
|
||||||
|
self.form = aqt.forms.dyndconf.Ui_Dialog()
|
||||||
|
self.form.setupUi(self)
|
||||||
|
self.mw.checkpoint(_("Options"))
|
||||||
|
self.setWindowModality(Qt.WindowModal)
|
||||||
|
self.connect(self.form.buttonBox,
|
||||||
|
SIGNAL("helpRequested()"),
|
||||||
|
lambda: openHelp("deckoptions"))
|
||||||
|
self.setWindowTitle(_("Options for %s") % self.deck['name'])
|
||||||
|
self.setupCombos()
|
||||||
|
self.loadConf()
|
||||||
|
self.exec_()
|
||||||
|
|
||||||
|
def setupCombos(self):
|
||||||
|
import anki.consts as cs
|
||||||
|
f = self.form
|
||||||
|
f.order.addItems(cs.dynOrderLabels().values())
|
||||||
|
|
||||||
|
def loadConf(self):
|
||||||
|
f = self.form
|
||||||
|
d = self.deck
|
||||||
|
f.search.setText(d['search'])
|
||||||
|
f.steps.setText(self.listToUser(d['delays']))
|
||||||
|
f.order.setCurrentIndex(d['order'])
|
||||||
|
f.limit.setValue(d['limit'])
|
||||||
|
f.fmult.setValue(d['fmult']*100)
|
||||||
|
|
||||||
|
def saveConf(self):
|
||||||
|
f = self.form
|
||||||
|
d = self.deck
|
||||||
|
steps = self.userToList(f.steps)
|
||||||
|
if not steps:
|
||||||
|
return
|
||||||
|
d['steps'] = steps
|
||||||
|
d['search'] = f.search.text()
|
||||||
|
d['order'] = f.order.currentIndex()
|
||||||
|
d['limit'] = f.limit.value()
|
||||||
|
d['fmult'] = f.fmult.value() / 100.0
|
||||||
|
self.mw.col.decks.save(d)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def reject(self):
|
||||||
|
self.accept()
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
if not self.saveConf():
|
||||||
|
return
|
||||||
|
self.mw.col.sched.rebuildDyn()
|
||||||
|
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
|
26
aqt/main.py
26
aqt/main.py
|
@ -672,8 +672,12 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
self.cardStats = aqt.stats.CardStats(self)
|
self.cardStats = aqt.stats.CardStats(self)
|
||||||
|
|
||||||
def onDeckConf(self):
|
def onDeckConf(self):
|
||||||
import aqt.deckconf
|
if self.col.decks.current()['dyn']:
|
||||||
aqt.deckconf.DeckConf(self)
|
import aqt.dyndeckconf
|
||||||
|
aqt.dyndeckconf.DeckConf(self)
|
||||||
|
else:
|
||||||
|
import aqt.deckconf
|
||||||
|
aqt.deckconf.DeckConf(self)
|
||||||
|
|
||||||
def onOverview(self):
|
def onOverview(self):
|
||||||
self.col.reset()
|
self.col.reset()
|
||||||
|
@ -710,6 +714,24 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
import aqt.exporting
|
import aqt.exporting
|
||||||
aqt.exporting.ExportDialog(self)
|
aqt.exporting.ExportDialog(self)
|
||||||
|
|
||||||
|
# Cramming
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
def onCram(self):
|
||||||
|
n = 1
|
||||||
|
decks = self.col.decks.allNames()
|
||||||
|
while _("Cram %d") % n in decks:
|
||||||
|
n += 1
|
||||||
|
name = _("Cram %d") % n
|
||||||
|
name = getOnlyText(_("Please name your cram deck."), default=name)
|
||||||
|
if not name:
|
||||||
|
return
|
||||||
|
if name in decks:
|
||||||
|
showWarning(_("The provided name was already in use."))
|
||||||
|
return
|
||||||
|
did = self.col.decks.newDyn(name)
|
||||||
|
self.onDeckConf()
|
||||||
|
|
||||||
# Language handling
|
# Language handling
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,6 @@ class Overview(object):
|
||||||
self.mw.moveToState("review")
|
self.mw.moveToState("review")
|
||||||
elif url == "anki":
|
elif url == "anki":
|
||||||
print "anki menu"
|
print "anki menu"
|
||||||
elif url == "cram":
|
|
||||||
return showInfo("not yet implemented")
|
|
||||||
#self.mw.col.cramGroups()
|
|
||||||
#self.mw.moveToState("review")
|
|
||||||
elif url == "opts":
|
elif url == "opts":
|
||||||
self.mw.onDeckConf()
|
self.mw.onDeckConf()
|
||||||
elif url == "decks":
|
elif url == "decks":
|
||||||
|
@ -144,7 +140,6 @@ text-align: left;
|
||||||
def _renderBottom(self):
|
def _renderBottom(self):
|
||||||
links = [
|
links = [
|
||||||
["opts", _("Options")],
|
["opts", _("Options")],
|
||||||
["cram", _("Cram")],
|
|
||||||
]
|
]
|
||||||
buf = ""
|
buf = ""
|
||||||
for b in links:
|
for b in links:
|
||||||
|
|
190
designer/dyndconf.ui
Normal file
190
designer/dyndconf.ui
Normal file
|
@ -0,0 +1,190 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>397</width>
|
||||||
|
<height>293</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QSpinBox" name="limit">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>999</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="2">
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Search for:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Learning steps:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Card limit:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QSpinBox" name="fmult">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
|
<property name="text">
|
||||||
|
<string>Display order:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="2">
|
||||||
|
<widget class="QLabel" name="label_8">
|
||||||
|
<property name="text">
|
||||||
|
<string>%</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1" colspan="2">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Example: deck:french tag:hard</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QLabel" name="label_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>Interval on fail:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="3">
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1" colspan="3">
|
||||||
|
<widget class="QLineEdit" name="steps"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" colspan="3">
|
||||||
|
<widget class="QLineEdit" name="search"/>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1" colspan="3">
|
||||||
|
<widget class="QComboBox" name="order"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>search</tabstop>
|
||||||
|
<tabstop>steps</tabstop>
|
||||||
|
<tabstop>order</tabstop>
|
||||||
|
<tabstop>limit</tabstop>
|
||||||
|
<tabstop>fmult</tabstop>
|
||||||
|
<tabstop>buttonBox</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
Loading…
Reference in a new issue