diff --git a/aqt/main.py b/aqt/main.py index eeb91b315..601fc25bf 100755 --- a/aqt/main.py +++ b/aqt/main.py @@ -814,6 +814,7 @@ upload, overwriting any changes either here or on AnkiWeb. Proceed?""")): self.connect(m.actionDocumentation, s, self.onDocumentation) self.connect(m.actionDonate, s, self.onDonate) self.connect(m.actionFullSync, s, self.onFullSync) + self.connect(m.actionStudyDeck, s, self.onStudyDeck) def updateTitleBar(self): self.setWindowTitle("Anki") @@ -946,6 +947,10 @@ Your edits have left some cards empty. Do you want to delete them?""")) tooltip("Deleted.") diag.close() + def onStudyDeck(self): + from aqt.studydeck import StudyDeck + StudyDeck(self) + # System specific code ########################################################################## diff --git a/aqt/studydeck.py b/aqt/studydeck.py new file mode 100644 index 000000000..054ba0ee7 --- /dev/null +++ b/aqt/studydeck.py @@ -0,0 +1,70 @@ +# Copyright: Damien Elmes +# -*- coding: utf-8 -*- +# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +from aqt.qt import * +import aqt, simplejson +from anki.utils import ids2str +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) + self.mw = mw + self.form = aqt.forms.studydeck.Ui_Dialog() + self.form.setupUi(self) + self.form.filter.installEventFilter(self) + self.ok = self.form.buttonBox.addButton( + _("Study"), QDialogButtonBox.AcceptRole) + self.setWindowModality(Qt.WindowModal) + self.connect(self.form.buttonBox, + SIGNAL("helpRequested()"), + lambda: openHelp("studydeck")) + self.connect(self.form.filter, + SIGNAL("textEdited(QString)"), + self.redraw) + self.redraw("") + self.exec_() + + def eventFilter(self, obj, evt): + if evt.type() == QEvent.KeyPress: + if evt.key() == Qt.Key_Up: + c = self.form.list.count() + row = self.form.list.currentRow() - 1 + if row < 0: + row = c - 1 + self.form.list.setCurrentRow(row) + return True + elif evt.key() == Qt.Key_Down: + c = self.form.list.count() + row = self.form.list.currentRow() + 1 + if row == c: + row = 0 + self.form.list.setCurrentRow(row) + return True + 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.form.list.clear() + self.form.list.addItems(self.names) + self.form.list.setCurrentRow(0) + + def _matches(self, name, filt): + name = name.lower() + filt = filt.lower() + if not filt: + return True + for c in filt: + if c not in name: + return False + name = name[name.index(c):] + 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") + QDialog.accept(self) diff --git a/designer/main.ui b/designer/main.ui index d9a12b2d5..114a3bb24 100644 --- a/designer/main.ui +++ b/designer/main.ui @@ -101,6 +101,8 @@ + + @@ -249,6 +251,14 @@ Full Sync... + + + Study Deck... + + + / + + diff --git a/designer/studydeck.ui b/designer/studydeck.ui new file mode 100644 index 000000000..3f9a88168 --- /dev/null +++ b/designer/studydeck.ui @@ -0,0 +1,81 @@ + + + Dialog + + + + 0 + 0 + 400 + 300 + + + + Study Deck + + + + + + + + Filter: + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Help + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +