add help to cram mode, fail if no cards matched

This commit is contained in:
Damien Elmes 2008-11-23 09:19:56 +09:00
parent 9c67a69b65
commit c2a8302a26
2 changed files with 42 additions and 6 deletions

View file

@ -1049,7 +1049,7 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
ui.utils.showInfo( ui.utils.showInfo(
_("Already cramming. Please close this deck first.")) _("Already cramming. Please close this deck first."))
return return
(s, ret) = QInputDialog.getText(self, _("Anki"), _("Tags to cram:")) (s, ret) = ui.utils.getText(_("Tags to cram:"), help="CramMode")
if not ret: if not ret:
return return
s = unicode(s) s = unicode(s)
@ -1063,6 +1063,9 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
if s: if s:
e.limitTags = parseTags(s) e.limitTags = parseTags(s)
e.exportInto(path) e.exportInto(path)
if not e.exportedCards:
ui.utils.showInfo(_("No cards matched the provided tags."))
return
self.deck.close() self.deck.close()
self.deck = None self.deck = None
self.loadDeck(path) self.loadDeck(path)

View file

@ -44,13 +44,46 @@ def askUser(text, parent=None):
QMessageBox.Yes | QMessageBox.No) QMessageBox.Yes | QMessageBox.No)
return r == QMessageBox.Yes 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: if not parent:
parent = ankiqt.mw parent = ankiqt.mw
(text, ok) = QInputDialog.getText(parent, "Anki", prompt) d = GetTextDialog(parent, prompt, help=help)
if not ok: ret = d.exec_()
return None return (unicode(d.l.text()), ret)
return unicode(text)
def getFile(parent, title, dir, key): def getFile(parent, title, dir, key):
"Ask the user for a file. Use DIR as config variable." "Ask the user for a file. Use DIR as config variable."