mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
add cards dialog & model chooser
This commit is contained in:
parent
f8d39ca210
commit
60ba70b1b5
10 changed files with 127 additions and 224 deletions
|
@ -39,7 +39,8 @@ class AddCards(QDialog):
|
||||||
self.setupNewNote()
|
self.setupNewNote()
|
||||||
|
|
||||||
def setupEditor(self):
|
def setupEditor(self):
|
||||||
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, True)
|
self.editor = aqt.editor.Editor(
|
||||||
|
self.mw, self.form.fieldsArea, self, True)
|
||||||
|
|
||||||
def setupChooser(self):
|
def setupChooser(self):
|
||||||
self.modelChooser = aqt.modelchooser.ModelChooser(
|
self.modelChooser = aqt.modelchooser.ModelChooser(
|
||||||
|
@ -69,7 +70,7 @@ class AddCards(QDialog):
|
||||||
self.connect(self.helpButton, SIGNAL("clicked()"), self.helpRequested)
|
self.connect(self.helpButton, SIGNAL("clicked()"), self.helpRequested)
|
||||||
# history
|
# history
|
||||||
b = bb.addButton(
|
b = bb.addButton(
|
||||||
_("History")+ u'▼', ar)
|
_("History")+ u" ▾", ar)
|
||||||
self.connect(b, SIGNAL("clicked()"), self.onHistory)
|
self.connect(b, SIGNAL("clicked()"), self.onHistory)
|
||||||
b.setEnabled(False)
|
b.setEnabled(False)
|
||||||
self.historyButton = b
|
self.historyButton = b
|
||||||
|
@ -126,9 +127,9 @@ class AddCards(QDialog):
|
||||||
browser.onSearch()
|
browser.onSearch()
|
||||||
|
|
||||||
def addNote(self, note):
|
def addNote(self, note):
|
||||||
if any(note.problems()):
|
if note.dupeOrEmpty():
|
||||||
showWarning(_(
|
showWarning(_(
|
||||||
"Some fields are missing or not unique."),
|
"The first field is empty or not unique."),
|
||||||
help="AddItems#AddError")
|
help="AddItems#AddError")
|
||||||
return
|
return
|
||||||
cards = self.mw.col.addNote(note)
|
cards = self.mw.col.addNote(note)
|
||||||
|
|
|
@ -275,7 +275,7 @@ class Editor(object):
|
||||||
native=True, canDisable=False)
|
native=True, canDisable=False)
|
||||||
b("layout", self.onCardLayout, "Ctrl+l",
|
b("layout", self.onCardLayout, "Ctrl+l",
|
||||||
shortcut(_("Customize Card Layout (Ctrl+l)")),
|
shortcut(_("Customize Card Layout (Ctrl+l)")),
|
||||||
size=False, text=_("Layout..."), native=True, canDisable=False)
|
size=False, text=_("Cards..."), native=True, canDisable=False)
|
||||||
# align to right
|
# align to right
|
||||||
self.iconsBox.addItem(QSpacerItem(20,1, QSizePolicy.Expanding))
|
self.iconsBox.addItem(QSpacerItem(20,1, QSizePolicy.Expanding))
|
||||||
b("text_bold", self.toggleBold, "Ctrl+b", _("Bold text (Ctrl+b)"),
|
b("text_bold", self.toggleBold, "Ctrl+b", _("Bold text (Ctrl+b)"),
|
||||||
|
@ -298,7 +298,7 @@ class Editor(object):
|
||||||
# fixme: better image names
|
# fixme: better image names
|
||||||
b("text-speak", self.onAddMedia, "F3", _("Add pictures/audio/video (F3)"))
|
b("text-speak", self.onAddMedia, "F3", _("Add pictures/audio/video (F3)"))
|
||||||
b("media-record", self.onRecSound, "F5", _("Record audio (F5)"))
|
b("media-record", self.onRecSound, "F5", _("Record audio (F5)"))
|
||||||
b("adv", self.onAdvanced, text=u"▼")
|
b("adv", self.onAdvanced, text=u"▾")
|
||||||
s = QShortcut(QKeySequence("Ctrl+t, t"), self.widget)
|
s = QShortcut(QKeySequence("Ctrl+t, t"), self.widget)
|
||||||
s.connect(s, SIGNAL("activated()"), self.insertLatex)
|
s.connect(s, SIGNAL("activated()"), self.insertLatex)
|
||||||
s = QShortcut(QKeySequence("Ctrl+t, e"), self.widget)
|
s = QShortcut(QKeySequence("Ctrl+t, e"), self.widget)
|
||||||
|
@ -442,7 +442,10 @@ class Editor(object):
|
||||||
contents = self.note.fields[0]
|
contents = self.note.fields[0]
|
||||||
browser = aqt.dialogs.open("Browser", self.mw)
|
browser = aqt.dialogs.open("Browser", self.mw)
|
||||||
browser.form.searchEdit.setText(
|
browser.form.searchEdit.setText(
|
||||||
"'model:%s' '%s'" % (self.note.model()['name'], contents))
|
"'model:%s' '%s:%s'" % (
|
||||||
|
self.note.model()['name'],
|
||||||
|
self.note.model()['flds'][0]['name'],
|
||||||
|
contents))
|
||||||
browser.onSearch()
|
browser.onSearch()
|
||||||
|
|
||||||
def fieldsAreBlank(self):
|
def fieldsAreBlank(self):
|
||||||
|
|
|
@ -18,7 +18,6 @@ class FieldDialog(QDialog):
|
||||||
self.mm = self.mw.col.models
|
self.mm = self.mw.col.models
|
||||||
self.model = note.model()
|
self.model = note.model()
|
||||||
self.mw.checkpoint(_("Fields"))
|
self.mw.checkpoint(_("Fields"))
|
||||||
self.setWindowModality(Qt.WindowModal)
|
|
||||||
self.form = aqt.forms.fields.Ui_Dialog()
|
self.form = aqt.forms.fields.Ui_Dialog()
|
||||||
self.form.setupUi(self)
|
self.form.setupUi(self)
|
||||||
self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
|
self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
|
||||||
|
|
16
aqt/main.py
16
aqt/main.py
|
@ -671,28 +671,12 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
self.col.reset()
|
self.col.reset()
|
||||||
self.moveToState("overview")
|
self.moveToState("overview")
|
||||||
|
|
||||||
def onGroups(self, parent=None):
|
|
||||||
from aqt.groups import Groups
|
|
||||||
g = Groups(self, parent)
|
|
||||||
|
|
||||||
def onCardStats(self):
|
def onCardStats(self):
|
||||||
self.cardStats.show()
|
self.cardStats.show()
|
||||||
|
|
||||||
def onStats(self):
|
def onStats(self):
|
||||||
aqt.stats.DeckStats(self)
|
aqt.stats.DeckStats(self)
|
||||||
|
|
||||||
def onCardLayout(self):
|
|
||||||
from aqt.clayout import CardLayout
|
|
||||||
CardLayout(self, self.reviewer.card.note(), ord=self.reviewer.card.ord)
|
|
||||||
|
|
||||||
def onDeckOpts(self):
|
|
||||||
import aqt.deckopts
|
|
||||||
aqt.deckopts.DeckOptions(self)
|
|
||||||
|
|
||||||
def onModels(self):
|
|
||||||
import aqt.models
|
|
||||||
aqt.models.Models(self)
|
|
||||||
|
|
||||||
def onPrefs(self):
|
def onPrefs(self):
|
||||||
import aqt.preferences
|
import aqt.preferences
|
||||||
aqt.preferences.Preferences(self)
|
aqt.preferences.Preferences(self)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from anki import stdmodels
|
|
||||||
from anki.lang import ngettext
|
from anki.lang import ngettext
|
||||||
from anki.hooks import addHook, remHook, runHook
|
from anki.hooks import addHook, remHook, runHook
|
||||||
from aqt.utils import isMac
|
from aqt.utils import isMac
|
||||||
|
@ -11,24 +11,22 @@ import aqt
|
||||||
|
|
||||||
class ModelChooser(QHBoxLayout):
|
class ModelChooser(QHBoxLayout):
|
||||||
|
|
||||||
def __init__(self, mw, widget, cards=True, label=True):
|
def __init__(self, mw, widget, label=True):
|
||||||
QHBoxLayout.__init__(self)
|
QHBoxLayout.__init__(self)
|
||||||
self.widget = widget
|
self.widget = widget
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.deck = mw.col
|
self.deck = mw.col
|
||||||
self.handleCards = cards
|
|
||||||
self.label = label
|
self.label = label
|
||||||
self._ignoreReset = False
|
self._ignoreReset = False
|
||||||
self.setMargin(0)
|
self.setMargin(0)
|
||||||
self.setSpacing(4)
|
self.setSpacing(8)
|
||||||
self.setupModels()
|
self.setupModels()
|
||||||
self.setupTemplates()
|
|
||||||
addHook('reset', self.onReset)
|
addHook('reset', self.onReset)
|
||||||
self.widget.setLayout(self)
|
self.widget.setLayout(self)
|
||||||
|
|
||||||
def setupModels(self):
|
def setupModels(self):
|
||||||
if self.label:
|
if self.label:
|
||||||
self.modelLabel = QLabel(_("<b>Model</b>:"))
|
self.modelLabel = QLabel(_("Note Type:"))
|
||||||
self.addWidget(self.modelLabel)
|
self.addWidget(self.modelLabel)
|
||||||
# models dropdown
|
# models dropdown
|
||||||
self.models = QComboBox()
|
self.models = QComboBox()
|
||||||
|
@ -39,9 +37,12 @@ class ModelChooser(QHBoxLayout):
|
||||||
self.connect(self.models, SIGNAL("activated(int)"), self.onModelChange)
|
self.connect(self.models, SIGNAL("activated(int)"), self.onModelChange)
|
||||||
# edit button
|
# edit button
|
||||||
self.edit = QPushButton()
|
self.edit = QPushButton()
|
||||||
if not isMac:
|
if isMac:
|
||||||
|
self.edit.setFixedWidth(24)
|
||||||
|
self.edit.setFixedHeight(21)
|
||||||
|
else:
|
||||||
self.edit.setFixedWidth(32)
|
self.edit.setFixedWidth(32)
|
||||||
self.edit.setIcon(QIcon(":/icons/configure.png"))
|
self.edit.setIcon(QIcon(":/icons/gears.png"))
|
||||||
self.edit.setShortcut(_("Shift+Alt+e"))
|
self.edit.setShortcut(_("Shift+Alt+e"))
|
||||||
self.edit.setToolTip(_("Customize Models"))
|
self.edit.setToolTip(_("Customize Models"))
|
||||||
self.edit.setAutoDefault(False)
|
self.edit.setAutoDefault(False)
|
||||||
|
@ -54,22 +55,12 @@ class ModelChooser(QHBoxLayout):
|
||||||
self.models.setSizePolicy(sizePolicy)
|
self.models.setSizePolicy(sizePolicy)
|
||||||
self.updateModels()
|
self.updateModels()
|
||||||
|
|
||||||
def setupTemplates(self):
|
|
||||||
self.cardShortcuts = []
|
|
||||||
if self.handleCards:
|
|
||||||
self.cards = QPushButton()
|
|
||||||
self.cards.setAutoDefault(False)
|
|
||||||
self.connect(self.cards, SIGNAL("clicked()"), self.onCardChange)
|
|
||||||
self.addWidget(self.cards)
|
|
||||||
self.updateTemplates()
|
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
remHook('reset', self.onReset)
|
remHook('reset', self.onReset)
|
||||||
|
|
||||||
def onReset(self):
|
def onReset(self):
|
||||||
if not self._ignoreReset:
|
if not self._ignoreReset:
|
||||||
self.updateModels()
|
self.updateModels()
|
||||||
self.updateTemplates()
|
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
self.widget.show()
|
self.widget.show()
|
||||||
|
@ -83,8 +74,7 @@ class ModelChooser(QHBoxLayout):
|
||||||
|
|
||||||
def onModelChange(self, idx):
|
def onModelChange(self, idx):
|
||||||
model = self._models[idx]
|
model = self._models[idx]
|
||||||
self.deck.conf['currentModelId'] = model.id
|
self.deck.conf['curModel'] = model.id
|
||||||
self.updateTemplates()
|
|
||||||
self._ignoreReset = True
|
self._ignoreReset = True
|
||||||
runHook("currentModelChanged")
|
runHook("currentModelChanged")
|
||||||
self._ignoreReset = False
|
self._ignoreReset = False
|
||||||
|
@ -95,105 +85,6 @@ class ModelChooser(QHBoxLayout):
|
||||||
key=itemgetter("name"))
|
key=itemgetter("name"))
|
||||||
self.models.addItems([m['name'] for m in self._models])
|
self.models.addItems([m['name'] for m in self._models])
|
||||||
for c, m in enumerate(self._models):
|
for c, m in enumerate(self._models):
|
||||||
if m['id'] == str(self.deck.conf['currentModelId']):
|
if m['id'] == str(self.deck.conf['curModel']):
|
||||||
self.models.setCurrentIndex(c)
|
self.models.setCurrentIndex(c)
|
||||||
break
|
break
|
||||||
|
|
||||||
def updateTemplates(self):
|
|
||||||
if not self.handleCards:
|
|
||||||
return
|
|
||||||
# remove any shortcuts
|
|
||||||
for s in self.cardShortcuts:
|
|
||||||
s.setEnabled(False)
|
|
||||||
self.cardShortcuts = []
|
|
||||||
m = self.deck.models.current()
|
|
||||||
ts = m['tmpls']
|
|
||||||
active = [t['name'] for t in ts if t['actv']]
|
|
||||||
txt = ngettext("%d card", "%d cards", len(active)) % len(active)
|
|
||||||
self.cards.setText(txt)
|
|
||||||
n = 1
|
|
||||||
for t in ts:
|
|
||||||
s = QShortcut(QKeySequence("Ctrl+%d" % n), self.widget)
|
|
||||||
self.widget.connect(s, SIGNAL("activated()"),
|
|
||||||
lambda t=t: self.toggleTemplate(t))
|
|
||||||
self.cardShortcuts.append(s)
|
|
||||||
n += 1
|
|
||||||
|
|
||||||
def onCardChange(self):
|
|
||||||
m = QMenu(self.widget)
|
|
||||||
model = self.deck.models.current()
|
|
||||||
for template in model.templates:
|
|
||||||
action = QAction(self.widget)
|
|
||||||
action.setCheckable(True)
|
|
||||||
if template['actv']:
|
|
||||||
action.setChecked(True)
|
|
||||||
action.setText(template['name'])
|
|
||||||
self.connect(action, SIGNAL("triggered()"),
|
|
||||||
lambda t=template: \
|
|
||||||
self.toggleTemplate(t))
|
|
||||||
m.addAction(action)
|
|
||||||
m.exec_(self.cards.mapToGlobal(QPoint(0,0)))
|
|
||||||
|
|
||||||
def canDisableTemplate(self):
|
|
||||||
return len([t for t in self.deck.models.current()['tmpls']
|
|
||||||
if t['actv']]) > 1
|
|
||||||
|
|
||||||
def toggleTemplate(self, card):
|
|
||||||
if not card['actv']:
|
|
||||||
card['actv'] = True
|
|
||||||
elif self.canDisableTemplate():
|
|
||||||
card['actv'] = False
|
|
||||||
self.deck.models.current().flush()
|
|
||||||
self.updateTemplates()
|
|
||||||
|
|
||||||
class AddModel(QDialog):
|
|
||||||
|
|
||||||
def __init__(self, mw, parent=None):
|
|
||||||
self.parent = parent or mw
|
|
||||||
self.mw = mw
|
|
||||||
self.deck = mw.col
|
|
||||||
QDialog.__init__(self, self.parent, Qt.Window)
|
|
||||||
self.model = None
|
|
||||||
self.dialog = aqt.forms.addmodel.Ui_Dialog()
|
|
||||||
self.dialog.setupUi(self)
|
|
||||||
# standard models
|
|
||||||
self.models = []
|
|
||||||
for (name, func) in stdmodels.models:
|
|
||||||
item = QListWidgetItem(_("Add: %s") % name)
|
|
||||||
self.dialog.models.addItem(item)
|
|
||||||
self.models.append((True, func))
|
|
||||||
# add copies
|
|
||||||
mids = self.deck.db.list("select id from models order by name")
|
|
||||||
for m in [self.deck.getModel(mid, False) for mid in mids]:
|
|
||||||
m.id = None
|
|
||||||
item = QListWidgetItem(_("Copy: %s") % m['name'])
|
|
||||||
self.dialog.models.addItem(item)
|
|
||||||
m['name'] = _("%s copy") % m['name']
|
|
||||||
self.models.append((False, m))
|
|
||||||
self.dialog.models.setCurrentRow(0)
|
|
||||||
# the list widget will swallow the enter key
|
|
||||||
s = QShortcut(QKeySequence("Return"), self)
|
|
||||||
self.connect(s, SIGNAL("activated()"), self.accept)
|
|
||||||
# help
|
|
||||||
self.connect(self.dialog.buttonBox, SIGNAL("helpRequested()"), self.onHelp)
|
|
||||||
|
|
||||||
def get(self):
|
|
||||||
self.exec_()
|
|
||||||
return self.model
|
|
||||||
|
|
||||||
def reject(self):
|
|
||||||
self.accept()
|
|
||||||
|
|
||||||
def accept(self):
|
|
||||||
(isStd, model) = self.models[self.dialog.models.currentRow()]
|
|
||||||
if isStd:
|
|
||||||
# create
|
|
||||||
self.model = model(self.deck)
|
|
||||||
else:
|
|
||||||
# add copy to deck
|
|
||||||
self.mw.col.addModel(model)
|
|
||||||
self.model = model
|
|
||||||
QDialog.accept(self)
|
|
||||||
|
|
||||||
def onHelp(self):
|
|
||||||
openHelp("AddModel")
|
|
||||||
|
|
103
aqt/models.py
103
aqt/models.py
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from aqt.utils import showInfo, askUser, getText, maybeHideClose
|
from aqt.utils import showInfo, askUser, getText, maybeHideClose, openHelp
|
||||||
import aqt.modelchooser, aqt.clayout
|
import aqt.modelchooser, aqt.clayout
|
||||||
|
from anki import stdmodels
|
||||||
|
|
||||||
class Models(QDialog):
|
class Models(QDialog):
|
||||||
def __init__(self, mw, parent=None):
|
def __init__(self, mw, parent=None):
|
||||||
|
@ -35,7 +36,7 @@ class Models(QDialog):
|
||||||
c(b, s, self.onRename)
|
c(b, s, self.onRename)
|
||||||
b = box.addButton(_("Delete"), t)
|
b = box.addButton(_("Delete"), t)
|
||||||
c(b, s, self.onDelete)
|
c(b, s, self.onDelete)
|
||||||
b = box.addButton(_("Advanced..."), t)
|
b = box.addButton(_("Options..."), t)
|
||||||
c(b, s, self.onAdvanced)
|
c(b, s, self.onAdvanced)
|
||||||
c(f.modelsList, SIGNAL("currentRowChanged(int)"), self.modelChanged)
|
c(f.modelsList, SIGNAL("currentRowChanged(int)"), self.modelChanged)
|
||||||
c(f.modelsList, SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
|
c(f.modelsList, SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
|
||||||
|
@ -45,9 +46,10 @@ class Models(QDialog):
|
||||||
maybeHideClose(box)
|
maybeHideClose(box)
|
||||||
|
|
||||||
def onRename(self):
|
def onRename(self):
|
||||||
txt = getText(_("New name?"), default=self.model.name)
|
txt = getText(_("New name:"), default=self.model.name)
|
||||||
if txt[0]:
|
if txt[0]:
|
||||||
self.model.name = txt[0]
|
self.model['name'] = txt[0]
|
||||||
|
self.mm.save(self.model)
|
||||||
self.updateModelsList()
|
self.updateModelsList()
|
||||||
|
|
||||||
def updateModelsList(self):
|
def updateModelsList(self):
|
||||||
|
@ -59,7 +61,7 @@ class Models(QDialog):
|
||||||
self.form.modelsList.clear()
|
self.form.modelsList.clear()
|
||||||
for m in self.models:
|
for m in self.models:
|
||||||
item = QListWidgetItem(_("%(name)s [%(notes)d notes]") % dict(
|
item = QListWidgetItem(_("%(name)s [%(notes)d notes]") % dict(
|
||||||
name=m.name, notes=m.useCount()))
|
name=m['name'], notes=self.mm.useCount(m)))
|
||||||
self.form.modelsList.addItem(item)
|
self.form.modelsList.addItem(item)
|
||||||
self.form.modelsList.setCurrentRow(row)
|
self.form.modelsList.setCurrentRow(row)
|
||||||
|
|
||||||
|
@ -70,31 +72,10 @@ class Models(QDialog):
|
||||||
self.model = self.models[idx]
|
self.model = self.models[idx]
|
||||||
|
|
||||||
def onAdd(self):
|
def onAdd(self):
|
||||||
m = aqt.modelchooser.AddModel(self.mw, self).get()
|
m = AddModel(self.mw, self).get()
|
||||||
if m:
|
if m:
|
||||||
self.col.addModel(m)
|
|
||||||
self.updateModelsList()
|
self.updateModelsList()
|
||||||
|
|
||||||
def onLayout(self):
|
|
||||||
# set to current
|
|
||||||
# # see if there's an available note
|
|
||||||
dummy = False
|
|
||||||
id = self.col.db.scalar(
|
|
||||||
"select id from notes where mid = ?", self.model.id)
|
|
||||||
if id:
|
|
||||||
note = self.col.getNote(id)
|
|
||||||
else:
|
|
||||||
# generate a dummy one
|
|
||||||
self.col.conf['currentModelId'] = self.model.id
|
|
||||||
note = self.col.newNote()
|
|
||||||
for f in note.keys():
|
|
||||||
note[f] = f
|
|
||||||
self.col.addNote(note)
|
|
||||||
dummy = True
|
|
||||||
aqt.clayout.CardLayout(self.mw, note, type=2, parent=self)
|
|
||||||
if dummy:
|
|
||||||
self.col._delNotes([note.id])
|
|
||||||
|
|
||||||
def onDelete(self):
|
def onDelete(self):
|
||||||
if len(self.models) < 2:
|
if len(self.models) < 2:
|
||||||
showInfo(_("Please add another model first."),
|
showInfo(_("Please add another model first."),
|
||||||
|
@ -104,7 +85,7 @@ class Models(QDialog):
|
||||||
_("Delete this model and all its cards?"),
|
_("Delete this model and all its cards?"),
|
||||||
parent=self):
|
parent=self):
|
||||||
return
|
return
|
||||||
self.col.delModel(self.model.id)
|
self.mm.rem(self.model)
|
||||||
self.model = None
|
self.model = None
|
||||||
self.updateModelsList()
|
self.updateModelsList()
|
||||||
|
|
||||||
|
@ -112,14 +93,20 @@ class Models(QDialog):
|
||||||
d = QDialog(self)
|
d = QDialog(self)
|
||||||
frm = aqt.forms.modelopts.Ui_Dialog()
|
frm = aqt.forms.modelopts.Ui_Dialog()
|
||||||
frm.setupUi(d)
|
frm.setupUi(d)
|
||||||
frm.latexHeader.setText(self.model.conf['latexPre'])
|
frm.clozeCtx.setChecked(self.model['clozectx'])
|
||||||
frm.latexFooter.setText(self.model.conf['latexPost'])
|
frm.latexHeader.setText(self.model['latexPre'])
|
||||||
|
frm.latexFooter.setText(self.model['latexPost'])
|
||||||
|
d.setWindowTitle(_("Options for %s") % self.model['name'])
|
||||||
|
self.connect(
|
||||||
|
frm.buttonBox, SIGNAL("helpRequested()"),
|
||||||
|
lambda: openHelp("NoteOptions"))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
self.model.conf['latexPre'] = unicode(frm.latexHeader.toPlainText())
|
self.model['clozectx'] = frm.clozeCtx.isChecked()
|
||||||
self.model.conf['latexPost'] = unicode(frm.latexFooter.toPlainText())
|
self.model['latexPre'] = unicode(frm.latexHeader.toPlainText())
|
||||||
|
self.model['latexPost'] = unicode(frm.latexFooter.toPlainText())
|
||||||
|
|
||||||
def saveModel(self):
|
def saveModel(self):
|
||||||
self.model.flush()
|
self.mm.save(self.model)
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -130,3 +117,53 @@ class Models(QDialog):
|
||||||
self.saveModel()
|
self.saveModel()
|
||||||
self.mw.reset()
|
self.mw.reset()
|
||||||
QDialog.reject(self)
|
QDialog.reject(self)
|
||||||
|
|
||||||
|
|
||||||
|
class AddModel(QDialog):
|
||||||
|
|
||||||
|
def __init__(self, mw, parent=None):
|
||||||
|
self.parent = parent or mw
|
||||||
|
self.mw = mw
|
||||||
|
self.col = mw.col
|
||||||
|
QDialog.__init__(self, self.parent, Qt.Window)
|
||||||
|
self.model = None
|
||||||
|
self.dialog = aqt.forms.addmodel.Ui_Dialog()
|
||||||
|
self.dialog.setupUi(self)
|
||||||
|
# standard models
|
||||||
|
self.models = []
|
||||||
|
for (name, func) in stdmodels.models:
|
||||||
|
item = QListWidgetItem(_("Add: %s") % name)
|
||||||
|
self.dialog.models.addItem(item)
|
||||||
|
self.models.append((True, func))
|
||||||
|
# add copies
|
||||||
|
for m in self.col.models.all():
|
||||||
|
item = QListWidgetItem(_("Clone: %s") % m['name'])
|
||||||
|
self.dialog.models.addItem(item)
|
||||||
|
self.models.append((False, m))
|
||||||
|
self.dialog.models.setCurrentRow(0)
|
||||||
|
# the list widget will swallow the enter key
|
||||||
|
s = QShortcut(QKeySequence("Return"), self)
|
||||||
|
self.connect(s, SIGNAL("activated()"), self.accept)
|
||||||
|
# help
|
||||||
|
self.connect(self.dialog.buttonBox, SIGNAL("helpRequested()"), self.onHelp)
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
self.exec_()
|
||||||
|
return self.model
|
||||||
|
|
||||||
|
def reject(self):
|
||||||
|
self.accept()
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
(isStd, model) = self.models[self.dialog.models.currentRow()]
|
||||||
|
if isStd:
|
||||||
|
# create
|
||||||
|
self.model = model(self.col)
|
||||||
|
else:
|
||||||
|
# add copy to deck
|
||||||
|
self.model = self.mw.col.models.copy(model)
|
||||||
|
self.mw.col.models.setCurrent(self.model)
|
||||||
|
QDialog.accept(self)
|
||||||
|
|
||||||
|
def onHelp(self):
|
||||||
|
openHelp("AddModel")
|
||||||
|
|
|
@ -358,7 +358,7 @@ def tooltip(msg, period=3000, parent=None):
|
||||||
evt.accept()
|
evt.accept()
|
||||||
self.hide()
|
self.hide()
|
||||||
closeTooltip()
|
closeTooltip()
|
||||||
aw = parent or aqt.mw.app.activeWindow()
|
aw = parent or aqt.mw.app.activeWindow() or aqt.mw
|
||||||
lab = CustomLabel("""\
|
lab = CustomLabel("""\
|
||||||
<table cellpadding=10>
|
<table cellpadding=10>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -104,6 +104,7 @@
|
||||||
<addaction name="actionCheckMediaDatabase"/>
|
<addaction name="actionCheckMediaDatabase"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="menuPlugins"/>
|
<addaction name="menuPlugins"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionPreferences"/>
|
<addaction name="actionPreferences"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuCol"/>
|
<addaction name="menuCol"/>
|
||||||
|
@ -112,10 +113,6 @@
|
||||||
<addaction name="menuHelp"/>
|
<addaction name="menuHelp"/>
|
||||||
</widget>
|
</widget>
|
||||||
<action name="actionExit">
|
<action name="actionExit">
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="icons.qrc">
|
|
||||||
<normaloff>:/icons/application-exit.png</normaloff>:/icons/application-exit.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>E&xit</string>
|
<string>E&xit</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -124,12 +121,8 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionPreferences">
|
<action name="actionPreferences">
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="icons.qrc">
|
|
||||||
<normaloff>:/icons/configure.png</normaloff>:/icons/configure.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Preferences</string>
|
<string>&Preferences...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="statusTip">
|
<property name="statusTip">
|
||||||
<string>Configure interface language and options</string>
|
<string>Configure interface language and options</string>
|
||||||
|
@ -142,10 +135,6 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionAbout">
|
<action name="actionAbout">
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="icons.qrc">
|
|
||||||
<normaloff>:/icons/anki.png</normaloff>:/icons/anki.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&About...</string>
|
<string>&About...</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -154,10 +143,6 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionCstats">
|
<action name="actionCstats">
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="icons.qrc">
|
|
||||||
<normaloff>:/icons/package_games_card.png</normaloff>:/icons/package_games_card.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Card Info</string>
|
<string>&Card Info</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -172,10 +157,6 @@
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="icons.qrc">
|
|
||||||
<normaloff>:/icons/edit-undo.png</normaloff>:/icons/edit-undo.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Undo</string>
|
<string>&Undo</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -184,10 +165,6 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionCheckMediaDatabase">
|
<action name="actionCheckMediaDatabase">
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="icons.qrc">
|
|
||||||
<normaloff>:/icons/text-speak.png</normaloff>:/icons/text-speak.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Unused Media...</string>
|
<string>&Unused Media...</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -211,10 +188,6 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionDonate">
|
<action name="actionDonate">
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="icons.qrc">
|
|
||||||
<normaloff>:/icons/emblem-favorite.png</normaloff>:/icons/emblem-favorite.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Support Anki...</string>
|
<string>&Support Anki...</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -228,19 +201,11 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionFullDatabaseCheck">
|
<action name="actionFullDatabaseCheck">
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="icons.qrc">
|
|
||||||
<normaloff>:/icons/sqlitebrowser.png</normaloff>:/icons/sqlitebrowser.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Check DB...</string>
|
<string>&Check DB...</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionDocumentation">
|
<action name="actionDocumentation">
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="icons.qrc">
|
|
||||||
<normaloff>:/icons/help-hint.png</normaloff>:/icons/help-hint.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Guide...</string>
|
<string>&Guide...</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -249,10 +214,6 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionSwitchProfile">
|
<action name="actionSwitchProfile">
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="icons.qrc">
|
|
||||||
<normaloff>:/icons/user-identity.png</normaloff>:/icons/user-identity.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Switch Profile...</string>
|
<string>&Switch Profile...</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -9,12 +9,12 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>353</width>
|
<width>276</width>
|
||||||
<height>363</height>
|
<height>323</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Model Options</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
|
@ -22,6 +22,33 @@
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QWidget" name="tab_2">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Basic</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="clozeCtx">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show context in cloze answers</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>184</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
<widget class="QWidget" name="tab">
|
<widget class="QWidget" name="tab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>LaTeX</string>
|
<string>LaTeX</string>
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Models</string>
|
<string>Note Types</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="100,0">
|
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="100,0">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
|
|
Loading…
Reference in a new issue