diff --git a/aqt/clayout.py b/aqt/clayout.py
index 4d8464b46..3af4424e1 100644
--- a/aqt/clayout.py
+++ b/aqt/clayout.py
@@ -9,8 +9,9 @@ from anki.consts import *
import aqt
from anki.sound import playFromText, clearAudioQueue
from aqt.utils import saveGeom, restoreGeom, getBase, mungeQA, \
- saveSplitter, restoreSplitter, showInfo, isMac, isWin, askUser
-from anki.hooks import runFilter
+ saveSplitter, restoreSplitter, showInfo, isMac, isWin, askUser, \
+ getText
+import aqt.templates
class ResizingTextEdit(QTextEdit):
def sizeHint(self):
@@ -30,11 +31,10 @@ class CardLayout(QDialog):
self.model = fact.model()
self.form = aqt.forms.clayout.Ui_Dialog()
self.form.setupUi(self)
+ self.setWindowTitle(_("%s Layout") % self.model.name)
self.plastiqueStyle = None
if isMac or isWin:
self.plastiqueStyle = QStyleFactory.create("plastique")
- # FIXME: add editing
- self.form.editTemplates.hide()
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
self.onHelp)
self.setupCards()
@@ -52,6 +52,12 @@ class CardLayout(QDialog):
def reload(self):
self.cards = self.deck.previewCards(self.fact, self.type)
+ if not self.cards:
+ self.accept()
+ showInfo(_(
+ "The current fact was deleted."))
+ self
+ return
self.fillCardList()
self.fillFieldList()
self.fieldChanged()
@@ -84,11 +90,9 @@ class CardLayout(QDialog):
w = ResizingTextEdit(self)
setattr(f, e, w)
f.templateLayout.addWidget(w, r[0], r[1])
- self.connect(f.cardList, SIGNAL("activated(int)"),
- self.cardChanged)
- # self.connect(f.editTemplates, SIGNAL("clicked())"),
- # self.onEdit)
c = self.connect
+ c(f.cardList, SIGNAL("activated(int)"), self.cardChanged)
+ c(f.editTemplates, SIGNAL("clicked()"), self.onEdit)
c(f.cardQuestion, SIGNAL("textChanged()"), self.formatChanged)
c(f.cardAnswer, SIGNAL("textChanged()"), self.formatChanged)
c(f.alignment, SIGNAL("activated(int)"), self.saveCard)
@@ -124,10 +128,9 @@ class CardLayout(QDialog):
fmt = fmt.replace("}}\n", "}}
")
return fmt
- # def onEdit(self):
- # ui.modelproperties.ModelProperties(
- # self, self.deck, self.model, self.mw,
- # onFinish=self.updateModelsList)
+ def onEdit(self):
+ aqt.templates.Templates(self.mw, self.model, self)
+ self.reload()
def formatChanged(self):
if self.updatingCards:
@@ -172,7 +175,6 @@ class CardLayout(QDialog):
cards.append(c.template()['name'])
self.form.cardList.addItems(
QStringList(cards))
- self.form.editTemplates.setEnabled(False)
self.form.cardList.setCurrentIndex(idx)
self.cardChanged(idx)
self.form.cardList.setFocus()
@@ -232,10 +234,14 @@ class CardLayout(QDialog):
return "
"
return ""
+ def accept(self):
+ self.reject()
+
def reject(self):
self.model.flush()
saveGeom(self, "CardLayout")
saveSplitter(self.form.splitter, "clayout")
+ self.mw.reset()
return QDialog.reject(self)
self.fact.model.setModified()
diff --git a/aqt/main.py b/aqt/main.py
index 0bc2312e2..658c9bb02 100755
--- a/aqt/main.py
+++ b/aqt/main.py
@@ -677,6 +677,9 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
def onDonate(self):
QDesktopServices.openUrl(QUrl(aqt.appDonate))
+ def onDocumentation(self):
+ QDesktopServices.openUrl(QUrl(aqt.appHelpSite))
+
# Importing & exporting
##########################################################################
@@ -785,6 +788,7 @@ Please choose a new deck name:"""))
self.connect(m.actionStudyOptions, s, self.onStudyOptions)
self.connect(m.actionOverview, s, self.onOverview)
self.connect(m.actionGroups, s, self.onGroups)
+ self.connect(m.actionDocumentation, s, self.onDocumentation)
self.connect(m.actionDonate, s, self.onDonate)
self.connect(m.actionBuryFact, s, self.onBuryFact)
diff --git a/aqt/models.py b/aqt/models.py
index 5bd4c070a..e189a41f4 100644
--- a/aqt/models.py
+++ b/aqt/models.py
@@ -3,7 +3,7 @@
from PyQt4.QtGui import *
from PyQt4.QtCore import *
-from aqt.utils import showInfo, askUser
+from aqt.utils import showInfo, askUser, getText
import aqt.modelchooser, aqt.clayout
class Models(QDialog):
@@ -13,13 +13,11 @@ class Models(QDialog):
QDialog.__init__(self, self.parent, Qt.Window)
self.deck = mw.deck
self.mw.checkpoint(_("Models"))
- #self.m = model
self.form = aqt.forms.models.Ui_Dialog()
self.form.setupUi(self)
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
- lambda: openHelp("Models"))
+ lambda: aqt.openHelp("Models"))
self.setupModels()
- self.setupCards()
self.exec_()
# Models
@@ -27,14 +25,29 @@ class Models(QDialog):
def setupModels(self):
self.model = None
- c = self.connect; f = self.form; s = SIGNAL("clicked()")
- c(f.modelsAdd, s, self.onAdd)
- c(f.modelsLayout, s, self.onLayout)
- c(f.modelsDelete, s, self.onDelete)
- self.connect(self.form.modelsList, SIGNAL("currentRowChanged(int)"),
- self.modelChanged)
+ c = self.connect; f = self.form; box = f.buttonBox
+ s = SIGNAL("clicked()")
+ t = QDialogButtonBox.ActionRole
+ b = box.addButton(_("Layout..."), t)
+ c(b, s, self.onLayout)
+ b.setDefault(True)
+ b = box.addButton(_("Add"), t)
+ c(b, s, self.onAdd)
+ b = box.addButton(_("Rename"), t)
+ c(b, s, self.onRename)
+ b = box.addButton(_("Delete"), t)
+ c(b, s, self.onDelete)
+ c(f.modelsList, SIGNAL("currentRowChanged(int)"), self.modelChanged)
+ c(f.modelsList, SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
+ self.onRename)
+ self.updateModelsList()
+ f.modelsList.setCurrentRow(0)
+
+ def onRename(self):
+ txt = getText(_("New name?"), default=self.model.name)
+ if txt[0]:
+ self.model.name = txt[0]
self.updateModelsList()
- self.form.modelsList.setCurrentRow(0)
def updateModelsList(self):
row = self.form.modelsList.currentRow()
@@ -54,7 +67,6 @@ class Models(QDialog):
self.saveModel()
idx = self.form.modelsList.currentRow()
self.model = self.models[idx]
- self.updateCards()
def onAdd(self):
m = aqt.modelchooser.AddModel(self.mw, self).get()
@@ -98,90 +110,6 @@ class Models(QDialog):
def saveModel(self):
self.model.flush()
- # Cards
- ##########################################################################
-
- def setupCards(self):
- f = self.form; c = self.connect; s = SIGNAL("clicked()")
- c(f.cardList, SIGNAL("currentRowChanged(int)"),
- self.cardRowChanged)
- c(f.cardList, SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
- self.renameCard)
- c(f.cardAdd, s, self.addCard)
- c(f.cardDelete, s, self.deleteCard)
- c(f.cardUp, s, self.moveCardUp)
- c(f.cardDown, s, self.moveCardDown)
- self.updateCards()
-
- def renameCard(self, item):
- txt = ui.utils.getText(_("New name?"), parent=self)
- if txt[0]:
- self.template['name'] = txt[0]
-
- def updateCards(self, row = None):
- row = self.form.cardList.currentRow() or 0
- if row == -1:
- row = 0
- self.form.cardList.clear()
- for card in self.model.templates:
- item = QListWidgetItem(card['name'])
- self.form.cardList.addItem(item)
- count = self.form.cardList.count()
- self.form.cardList.setCurrentRow(row)
-
- def cardRowChanged(self):
- self.template = self.model.templates[self.form.cardList.currentRow()]
- self.enableCardMoveButtons()
-
- def enableCardMoveButtons(self):
- f = self.form
- row = f.cardList.currentRow()
- f.cardUp.setEnabled(row >= 1)
- f.cardDown.setEnabled(row < (f.cardList.count() - 1))
-
- def addCard(self):
- cards = len(self.model.templates)
- t = self.model.newTemplate()
- t['name'] = _("Template %d") % (cards+1)
- fields = self.model.fields
- t['qfmt'] = "{{%s}}" % fields[0]['name']
- if len(fields) > 1:
- t['afmt'] = "{{%s}}" % fields[1]['name']
- else:
- t['afmt'] = ""
- self.model.addTemplate(t)
- self.updateCards()
-
- def deleteCard(self):
- if len (self.model.templates) < 2:
- ui.utils.showWarning(
- _("Please add a new template first."),
- parent=self)
- return
- if not askUser(
- _("Delete this template and all cards that use it?")):
- return
- self.model.delTemplate(self.template)
- self.updateCards()
-
- def moveCardUp(self):
- row = self.form.cardList.currentRow()
- if row == 0:
- return
- self.mw.progress.start()
- self.model.moveTemplate(self.template, row-1)
- self.mw.progress.finish()
- self.updateCards()
-
- def moveCardDown(self):
- row = self.form.cardList.currentRow()
- if row == len(self.model.templates) - 1:
- return
- self.mw.progress.start()
- self.model.moveTemplate(self.template, row+1)
- self.mw.progress.finish()
- self.updateCards()
-
# Cleanup
##########################################################################
diff --git a/aqt/templates.py b/aqt/templates.py
new file mode 100644
index 000000000..602070018
--- /dev/null
+++ b/aqt/templates.py
@@ -0,0 +1,106 @@
+# Copyright: Damien Elmes
+# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
+
+from PyQt4.QtGui import *
+from PyQt4.QtCore import *
+import aqt
+from aqt.utils import saveGeom, restoreGeom, askUser, getText
+
+class Templates(QDialog):
+
+ def __init__(self, mw, model, parent=None):
+ self.parent = parent or mw
+ QDialog.__init__(self, self.parent, Qt.Window)
+ self.mw = aqt.mw
+ self.model = model
+ self.form = aqt.forms.templates.Ui_Dialog()
+ self.form.setupUi(self)
+ self.setWindowTitle(_("%s Templates") % self.model.name)
+ self.setupTemplates()
+ self.updateTemplates()
+ self.exec_()
+
+ # Templates
+ ##########################################################################
+
+ def setupTemplates(self):
+ f = self.form; c = self.connect; s = SIGNAL("clicked()")
+ c(f.templateList, SIGNAL("currentRowChanged(int)"),
+ self.templateRowChanged)
+ c(f.templateList, SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
+ self.renameTemplate)
+ c(f.templateAdd, s, self.addTemplate)
+ c(f.templateDelete, s, self.deleteTemplate)
+ c(f.templateUp, s, self.moveTemplateUp)
+ c(f.templateDown, s, self.moveTemplateDown)
+
+ def renameTemplate(self, item):
+ txt = getText(_("New name?"), default=self.template['name'])
+ if txt[0]:
+ self.template['name'] = txt[0]
+
+ def updateTemplates(self, row = None):
+ row = self.form.templateList.currentRow() or 0
+ if row == -1:
+ row = 0
+ self.form.templateList.clear()
+ for template in self.model.templates:
+ item = QListWidgetItem(template['name'])
+ self.form.templateList.addItem(item)
+ count = self.form.templateList.count()
+ self.form.templateList.setCurrentRow(row)
+
+ def templateRowChanged(self):
+ self.template = self.model.templates[self.form.templateList.currentRow()]
+ self.enableTemplateMoveButtons()
+
+ def enableTemplateMoveButtons(self):
+ f = self.form
+ row = f.templateList.currentRow()
+ f.templateUp.setEnabled(row >= 1)
+ f.templateDown.setEnabled(row < (f.templateList.count() - 1))
+
+ def addTemplate(self):
+ templates = len(self.model.templates)
+ t = self.model.newTemplate()
+ t['name'] = _("Template %d") % (templates+1)
+ fields = self.model.fields
+ t['qfmt'] = "{{%s}}" % fields[0]['name']
+ if len(fields) > 1:
+ t['afmt'] = "{{%s}}" % fields[1]['name']
+ else:
+ t['afmt'] = ""
+ self.model.addTemplate(t)
+ self.updateTemplates()
+
+ def deleteTemplate(self):
+ if len (self.model.templates) < 2:
+ ui.utils.showWarning(
+ _("Please add a new template first."),
+ parent=self)
+ return
+ if not askUser(
+ _("Delete this template and all cards that use it?")):
+ return
+ self.model.delTemplate(self.template)
+ self.updateTemplates()
+
+ def moveTemplateUp(self):
+ row = self.form.templateList.currentRow()
+ if row == 0:
+ return
+ self.mw.progress.start()
+ self.model.moveTemplate(self.template, row-1)
+ self.mw.progress.finish()
+ self.updateTemplates()
+ self.form.templateList.setCurrentRow(row-1)
+
+ def moveTemplateDown(self):
+ row = self.form.templateList.currentRow()
+ if row == len(self.model.templates) - 1:
+ return
+ self.mw.progress.start()
+ self.model.moveTemplate(self.template, row+1)
+ self.mw.progress.finish()
+ self.updateTemplates()
+ self.form.templateList.setCurrentRow(row+1)
diff --git a/designer/clayout.ui b/designer/clayout.ui
index 51be4eece..6399bf3c3 100644
--- a/designer/clayout.ui
+++ b/designer/clayout.ui
@@ -6,12 +6,12 @@
0
0
- 472
- 531
+ 759
+ 560
- Card Layout
+
-
@@ -37,11 +37,14 @@
- Card Templates
+ Appearance
-
+
+ 6
+
-
@@ -89,27 +92,6 @@
- -
-
-
-
-
-
-
- 0
- 0
-
-
-
-
- -
-
-
- &Edit
-
-
-
-
-
-
-
@@ -191,6 +173,30 @@
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+ &Manage...
+
+
+ Ctrl+M
+
+
+
+
+
-
diff --git a/designer/main.ui b/designer/main.ui
index 3dc1b3754..2ae7a0538 100644
--- a/designer/main.ui
+++ b/designer/main.ui
@@ -47,6 +47,7 @@
&Help
+
@@ -59,7 +60,6 @@
-
@@ -147,8 +147,10 @@
+
+
@@ -279,7 +281,7 @@
:/icons/list-add.png:/icons/list-add.png
- &Add Items...
+ &Add...
@@ -294,7 +296,7 @@
:/icons/find.png:/icons/find.png
- Brows&e Items...
+ &Browse...
@@ -516,7 +518,7 @@
:/icons/edit-rename.png:/icons/edit-rename.png
- &Current Fact...
+ &Edit Current...
@@ -646,7 +648,7 @@
:/icons/layout.png:/icons/layout.png
- Card Layout...
+ Layout...
L
@@ -685,6 +687,14 @@
Ctrl+M
+
+
+ Documentation...
+
+
+ F1
+
+
diff --git a/designer/models.ui b/designer/models.ui
index cf7744417..7d115f021 100644
--- a/designer/models.ui
+++ b/designer/models.ui
@@ -9,14 +9,14 @@
0
0
- 425
- 446
+ 396
+ 255
Models
-
+
0
@@ -41,51 +41,14 @@
12
-
-
-
- &Add
-
-
- false
-
-
-
- -
-
-
- &Delete
-
-
- false
-
-
-
- -
-
-
- &Layout...
-
-
-
- :/icons/layout.png:/icons/layout.png
-
-
- false
-
-
-
- -
-
+
Qt::Vertical
-
-
- 20
- 40
-
+
+ QDialogButtonBox::Close|QDialogButtonBox::Help
-
+
@@ -107,152 +70,10 @@
- -
-
-
-
- 0
- 10
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sort Field
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
-
-
- -
-
-
- Card Templates
-
-
-
-
-
-
-
-
-
-
- 0
- 1
-
-
-
-
- 0
- 60
-
-
-
-
- -
-
-
-
-
-
- &Add
-
-
- false
-
-
-
- -
-
-
- &Up
-
-
- false
-
-
-
- -
-
-
- Dow&n
-
-
- false
-
-
-
- -
-
-
- &Delete
-
-
- false
-
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 40
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Close|QDialogButtonBox::Help
-
-
-
modelsList
- modelsAdd
- modelsDelete
- modelsLayout
- sortField
- cardList
- cardAdd
- cardUp
- cardDown
- cardDelete
- buttonBox
diff --git a/designer/studyopts.ui b/designer/studyopts.ui
index 44895c258..18474667f 100644
--- a/designer/studyopts.ui
+++ b/designer/studyopts.ui
@@ -6,159 +6,170 @@
0
0
- 380
- 291
+ 382
+ 319
- Dialog
+ Study Options
-
+
-
-
-
-
-
-
- Next day starts at
-
-
+
+
-
+
+
-
+
+
+ Next day starts at
+
+
+
+ -
+
+
+
+ 60
+ 16777215
+
+
+
+ 23
+
+
+
+ -
+
+
+ Learn ahead limit
+
+
+
+ -
+
+
+
+ 60
+ 16777215
+
+
+
+
+ -
+
+
+ mins
+
+
+
+ -
+
+
+ New cards/day
+
+
+
+ -
+
+
+ 999
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ Timebox question limit
+
+
+
+ -
+
+
+ Timebox time limit
+
+
+
+ -
+
+
+ 9999
+
+
+
+ -
+
+
+ 9999
+
+
+
+ -
+
+
+ mins
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
- -
-
-
-
- 60
- 16777215
-
-
-
- 23
-
-
-
- -
-
-
- Learn ahead limit
-
-
-
- -
-
-
-
- 60
- 16777215
-
-
-
-
- -
-
-
- mins
-
-
-
- -
-
-
- New cards/day
-
-
-
- -
-
-
- 999
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- Timebox question limit
-
-
-
- -
-
-
- Timebox time limit
-
-
-
- -
-
-
- 9999
-
-
-
- -
-
-
- 9999
-
-
-
- -
-
-
- mins
-
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 40
-
-
-
+
-
+
+
-
+
+
+ Qt::Vertical
+
+
+ QDialogButtonBox::Help|QDialogButtonBox::Ok
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
-
-
-
-
-
-
- Qt::Vertical
-
-
- QDialogButtonBox::Help|QDialogButtonBox::Ok
-
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 40
-
-
-
-
-
+
+
+ More study options are available in the group settings.
+
+
diff --git a/designer/templates.ui b/designer/templates.ui
new file mode 100644
index 000000000..439614cc8
--- /dev/null
+++ b/designer/templates.ui
@@ -0,0 +1,143 @@
+
+
+ Dialog
+
+
+
+ 0
+ 0
+ 400
+ 300
+
+
+
+
+
+
+ -
+
+
-
+
+
+
+ 0
+ 1
+
+
+
+
+ 0
+ 60
+
+
+
+
+ -
+
+
-
+
+
+ &Add
+
+
+ false
+
+
+
+ -
+
+
+ &Up
+
+
+ false
+
+
+
+ -
+
+
+ Dow&n
+
+
+ false
+
+
+
+ -
+
+
+ &Delete
+
+
+ false
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Close
+
+
+
+
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ Dialog
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ Dialog
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+