add 'note types' to main menu

This commit is contained in:
Damien Elmes 2012-12-22 08:21:24 +09:00
parent a35ce1fd8e
commit ce4c62fcbb
3 changed files with 37 additions and 1 deletions

View file

@ -695,6 +695,10 @@ and check the statistics for a home deck instead."""))
import aqt.preferences
aqt.preferences.Preferences(self)
def onNoteTypes(self):
import aqt.models
aqt.models.Models(self, self, fromMain=True)
def onAbout(self):
import aqt.about
aqt.about.show(self)
@ -760,6 +764,7 @@ and check the statistics for a home deck instead."""))
self.connect(m.actionStudyDeck, s, self.onStudyDeck)
self.connect(m.actionCreateFiltered, s, self.onCram)
self.connect(m.actionEmptyCards, s, self.onEmptyCards)
self.connect(m.actionNoteTypes, s, self.onNoteTypes)
def updateTitleBar(self):
self.setWindowTitle("Anki")

View file

@ -9,9 +9,10 @@ from anki import stdmodels
from aqt.utils import saveGeom, restoreGeom
class Models(QDialog):
def __init__(self, mw, parent=None):
def __init__(self, mw, parent=None, fromMain=False):
self.mw = mw
self.parent = parent or mw
self.fromMain = fromMain
QDialog.__init__(self, self.parent, Qt.Window)
self.col = mw.col
self.mm = self.col.models
@ -38,6 +39,11 @@ class Models(QDialog):
c(b, s, self.onRename)
b = box.addButton(_("Delete"), t)
c(b, s, self.onDelete)
if self.fromMain:
b = box.addButton(_("Fields..."), t)
c(b, s, self.onFields)
b = box.addButton(_("Cards..."), t)
c(b, s, self.onCards)
b = box.addButton(_("Options..."), t)
c(b, s, self.onAdvanced)
c(f.modelsList, SIGNAL("currentRowChanged(int)"), self.modelChanged)
@ -115,6 +121,25 @@ class Models(QDialog):
def saveModel(self):
self.mm.save(self.model)
def _tmpNote(self):
self.mm.setCurrent(self.model)
n = self.col.newNote()
for name in n.keys():
n[name] = "("+name+")"
if "{{cloze:Text}}" in self.model['tmpls'][0]['qfmt']:
n['Text'] = _("This is a {{c1::sample}} cloze deletion.")
return n
def onFields(self):
from aqt.fields import FieldDialog
n = self._tmpNote()
FieldDialog(self.mw, n, parent=self)
def onCards(self):
from aqt.clayout import CardLayout
n = self._tmpNote()
CardLayout(self.mw, n, ord=0, parent=self, addMode=True)
# Cleanup
##########################################################################

View file

@ -110,6 +110,7 @@
<addaction name="separator"/>
<addaction name="menuPlugins"/>
<addaction name="separator"/>
<addaction name="actionNoteTypes"/>
<addaction name="actionPreferences"/>
</widget>
<addaction name="menuCol"/>
@ -257,6 +258,11 @@
<string>F</string>
</property>
</action>
<action name="actionNoteTypes">
<property name="text">
<string>Note Types...</string>
</property>
</action>
</widget>
<resources>
<include location="icons.qrc"/>