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