mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
add filter to note type selection
This commit is contained in:
parent
0fac8755c9
commit
82e0349d8f
3 changed files with 38 additions and 35 deletions
|
@ -863,7 +863,10 @@ will be lost. Continue?"""))
|
|||
|
||||
def onStudyDeck(self):
|
||||
from aqt.studydeck import StudyDeck
|
||||
StudyDeck(self)
|
||||
ret = StudyDeck(self)
|
||||
if ret.name:
|
||||
self.col.decks.select(self.col.decks.id(ret.name))
|
||||
self.moveToState("overview")
|
||||
|
||||
def onEmptyCards(self):
|
||||
self.progress.start(immediate=True)
|
||||
|
|
|
@ -16,7 +16,6 @@ class ModelChooser(QHBoxLayout):
|
|||
self.mw = mw
|
||||
self.deck = mw.col
|
||||
self.label = label
|
||||
self._ignoreReset = False
|
||||
self.setMargin(0)
|
||||
self.setSpacing(8)
|
||||
self.setupModels()
|
||||
|
@ -27,13 +26,14 @@ class ModelChooser(QHBoxLayout):
|
|||
if self.label:
|
||||
self.modelLabel = QLabel(_("Note Type:"))
|
||||
self.addWidget(self.modelLabel)
|
||||
# models dropdown
|
||||
self.models = QComboBox()
|
||||
s = QShortcut(QKeySequence(_("Shift+Alt+m")), self.widget)
|
||||
s.connect(s, SIGNAL("activated()"),
|
||||
lambda: self.models.showPopup())
|
||||
# models box
|
||||
self.models = QPushButton()
|
||||
self.models.setStyleSheet("* { text-align: left; }")
|
||||
self.models.setToolTip(_("Change Note Type (Ctrl+N)"))
|
||||
s = QShortcut(QKeySequence(_("Ctrl+N")), self.widget)
|
||||
s.connect(s, SIGNAL("activated()"), self.onModelChange)
|
||||
self.addWidget(self.models)
|
||||
self.connect(self.models, SIGNAL("activated(int)"), self.onModelChange)
|
||||
self.connect(self.models, SIGNAL("clicked()"), self.onModelChange)
|
||||
# edit button
|
||||
self.edit = QPushButton()
|
||||
if isMac:
|
||||
|
@ -42,7 +42,6 @@ class ModelChooser(QHBoxLayout):
|
|||
else:
|
||||
self.edit.setFixedWidth(32)
|
||||
self.edit.setIcon(QIcon(":/icons/gears.png"))
|
||||
self.edit.setShortcut(_("Shift+Alt+e"))
|
||||
self.edit.setToolTip(_("Customize Note Types"))
|
||||
self.edit.setAutoDefault(False)
|
||||
self.addWidget(self.edit)
|
||||
|
@ -58,8 +57,7 @@ class ModelChooser(QHBoxLayout):
|
|||
remHook('reset', self.onReset)
|
||||
|
||||
def onReset(self):
|
||||
if not self._ignoreReset:
|
||||
self.updateModels()
|
||||
self.updateModels()
|
||||
|
||||
def show(self):
|
||||
self.widget.show()
|
||||
|
@ -71,23 +69,21 @@ class ModelChooser(QHBoxLayout):
|
|||
import aqt.models
|
||||
aqt.models.Models(self.mw, self.widget)
|
||||
|
||||
def onModelChange(self, idx):
|
||||
model = self._models[idx]
|
||||
self.deck.conf['curModel'] = model['id']
|
||||
def onModelChange(self):
|
||||
from aqt.studydeck import StudyDeck
|
||||
ret = StudyDeck(self.mw, names=sorted(self.deck.models.allNames()),
|
||||
accept=_("Select"), title=_("Choose Note Type"),
|
||||
help="_notes", parent=self.widget)
|
||||
if not ret.name:
|
||||
return
|
||||
print ret.name
|
||||
m = self.deck.models.byName(ret.name)
|
||||
self.deck.conf['curModel'] = m['id']
|
||||
cdeck = self.deck.decks.current()
|
||||
cdeck['mid'] = model['id']
|
||||
cdeck['mid'] = m['id']
|
||||
self.deck.decks.save(cdeck)
|
||||
self._ignoreReset = True
|
||||
runHook("currentModelChanged")
|
||||
self._ignoreReset = False
|
||||
self.updateModels()
|
||||
|
||||
def updateModels(self):
|
||||
self.models.clear()
|
||||
self._models = sorted(self.deck.models.all(),
|
||||
key=itemgetter("name"))
|
||||
self.models.addItems([m['name'] for m in self._models])
|
||||
cur = self.deck.models.current()
|
||||
for c, m in enumerate(self._models):
|
||||
if m['id'] == cur['id']:
|
||||
self.models.setCurrentIndex(c)
|
||||
break
|
||||
self.models.setText(self.deck.models.current()['name'])
|
||||
|
|
|
@ -9,18 +9,25 @@ from aqt.utils import showInfo, showWarning, openHelp, getOnlyText
|
|||
from operator import itemgetter
|
||||
|
||||
class StudyDeck(QDialog):
|
||||
def __init__(self, mw, first=False, search=""):
|
||||
QDialog.__init__(self, mw)
|
||||
def __init__(self, mw, names=None, accept=None, title=None,
|
||||
help="studydeck", parent=None):
|
||||
QDialog.__init__(self, parent or mw)
|
||||
self.mw = mw
|
||||
self.form = aqt.forms.studydeck.Ui_Dialog()
|
||||
self.form.setupUi(self)
|
||||
self.form.filter.installEventFilter(self)
|
||||
if title:
|
||||
self.setWindowTitle(title)
|
||||
if not names:
|
||||
names = sorted(self.mw.col.decks.allNames())
|
||||
self.origNames = names
|
||||
self.name = None
|
||||
self.ok = self.form.buttonBox.addButton(
|
||||
_("Study"), QDialogButtonBox.AcceptRole)
|
||||
accept or _("Study"), QDialogButtonBox.AcceptRole)
|
||||
self.setWindowModality(Qt.WindowModal)
|
||||
self.connect(self.form.buttonBox,
|
||||
SIGNAL("helpRequested()"),
|
||||
lambda: openHelp("studydeck"))
|
||||
lambda: openHelp(help))
|
||||
self.connect(self.form.filter,
|
||||
SIGNAL("textEdited(QString)"),
|
||||
self.redraw)
|
||||
|
@ -46,8 +53,7 @@ class StudyDeck(QDialog):
|
|||
return False
|
||||
|
||||
def redraw(self, filt):
|
||||
names = sorted(self.mw.col.decks.allNames())
|
||||
self.names = [n for n in names if self._matches(n, filt)]
|
||||
self.names = [n for n in self.origNames if self._matches(n, filt)]
|
||||
self.form.list.clear()
|
||||
self.form.list.addItems(self.names)
|
||||
self.form.list.setCurrentRow(0)
|
||||
|
@ -64,7 +70,5 @@ class StudyDeck(QDialog):
|
|||
return True
|
||||
|
||||
def accept(self):
|
||||
name = self.names[self.form.list.currentRow()]
|
||||
self.mw.col.decks.select(self.mw.col.decks.id(name))
|
||||
self.mw.moveToState("overview")
|
||||
self.name = self.names[self.form.list.currentRow()]
|
||||
QDialog.accept(self)
|
||||
|
|
Loading…
Reference in a new issue