From c2a8302a2609828711864556e4ca4544e94ec54d Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 23 Nov 2008 09:19:56 +0900 Subject: [PATCH] add help to cram mode, fail if no cards matched --- ankiqt/ui/main.py | 5 ++++- ankiqt/ui/utils.py | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 5d05115c5..4f4b6c704 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -1049,7 +1049,7 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) ui.utils.showInfo( _("Already cramming. Please close this deck first.")) return - (s, ret) = QInputDialog.getText(self, _("Anki"), _("Tags to cram:")) + (s, ret) = ui.utils.getText(_("Tags to cram:"), help="CramMode") if not ret: return s = unicode(s) @@ -1063,6 +1063,9 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) if s: e.limitTags = parseTags(s) e.exportInto(path) + if not e.exportedCards: + ui.utils.showInfo(_("No cards matched the provided tags.")) + return self.deck.close() self.deck = None self.loadDeck(path) diff --git a/ankiqt/ui/utils.py b/ankiqt/ui/utils.py index 9c8f8e808..da04e68be 100644 --- a/ankiqt/ui/utils.py +++ b/ankiqt/ui/utils.py @@ -44,13 +44,46 @@ def askUser(text, parent=None): QMessageBox.Yes | QMessageBox.No) return r == QMessageBox.Yes -def getText(prompt, parent=None): +class GetTextDialog(QDialog): + + def __init__(self, parent, question, help=None): + QDialog.__init__(self, parent) + self.setWindowTitle("Anki") + self.question = question + self.help = help + v = QVBoxLayout() + v.addWidget(QLabel(question)) + self.l = QLineEdit() + v.addWidget(self.l) + buts = QDialogButtonBox.Ok | QDialogButtonBox.Cancel + if help: + buts |= QDialogButtonBox.Help + b = QDialogButtonBox(buts) + v.addWidget(b) + self.setLayout(v) + self.connect(b.button(QDialogButtonBox.Ok), + SIGNAL("clicked()"), self.accept) + self.connect(b.button(QDialogButtonBox.Cancel), + SIGNAL("clicked()"), self.reject) + if help: + self.connect(b.button(QDialogButtonBox.Help), + SIGNAL("clicked()"), self.helpRequested) + + def accept(self): + return QDialog.accept(self) + + def reject(self): + return QDialog.reject(self) + + def helpRequested(self): + QDesktopServices.openUrl(QUrl(ankiqt.appWiki + self.help)) + +def getText(prompt, parent=None, help=None): if not parent: parent = ankiqt.mw - (text, ok) = QInputDialog.getText(parent, "Anki", prompt) - if not ok: - return None - return unicode(text) + d = GetTextDialog(parent, prompt, help=help) + ret = d.exec_() + return (unicode(d.l.text()), ret) def getFile(parent, title, dir, key): "Ask the user for a file. Use DIR as config variable."