add cram in editor, rename editor to browser

This commit is contained in:
Damien Elmes 2009-04-06 13:29:24 +09:00
parent 180af193df
commit 14c67e7ab9
5 changed files with 50 additions and 18 deletions

View file

@ -518,6 +518,7 @@ class EditDeck(QMainWindow):
self.connect(self.dialog.actionAddTag, SIGNAL("triggered()"), self.addTags)
self.connect(self.dialog.actionDeleteTag, SIGNAL("triggered()"), self.deleteTags)
self.connect(self.dialog.actionReschedule, SIGNAL("triggered()"), self.reschedule)
self.connect(self.dialog.actionCram, SIGNAL("triggered()"), self.cram)
self.connect(self.dialog.actionAddCards, SIGNAL("triggered()"), self.addCards)
self.connect(self.dialog.actionChangeModel, SIGNAL("triggered()"), self.onChangeModel)
# edit
@ -742,6 +743,14 @@ where id in %s""" % ids2str(sf))
self.updateSearch()
self.updateAfterCardChange()
def cram(self):
if ui.utils.askUser(
_("Cram selected cards in new deck?"),
help="CramMode",
parent=self):
self.close()
self.parent.onCram(self.selectedCards())
def onChangeModel(self):
sf = self.selectedFacts()
mods = self.deck.s.column0("""
@ -872,7 +881,7 @@ where id in %s""" % ids2str(sf))
def onFindReplaceHelp(self):
QDesktopServices.openUrl(QUrl(ankiqt.appWiki +
"Editor#FindReplace"))
"Browser#FindReplace"))
# Jumping
######################################################################
@ -919,7 +928,7 @@ where id in %s""" % ids2str(sf))
######################################################################
def onHelp(self):
QDesktopServices.openUrl(QUrl(ankiqt.appWiki + "Editor"))
QDesktopServices.openUrl(QUrl(ankiqt.appWiki + "Browser"))
# Generate card dialog
######################################################################
@ -965,7 +974,7 @@ order by ordinal""" % ids2str(self.cms))
def onHelp(self):
QDesktopServices.openUrl(QUrl(ankiqt.appWiki +
"Editor#GenerateCards"))
"Browser#GenerateCards"))
# Change model dialog
######################################################################
@ -1111,4 +1120,4 @@ class ChangeModelDialog(QDialog):
def onHelp(self):
QDesktopServices.openUrl(QUrl(ankiqt.appWiki +
"Editor#ChangeModel"))
"Browser#ChangeModel"))

View file

@ -1385,31 +1385,36 @@ day = :d""", d=yesterday)
# Cramming & Sharing
##########################################################################
def _copyToTmpDeck(self, name="cram.anki", tags=""):
def _copyToTmpDeck(self, name="cram.anki", tags="", ids=[]):
ndir = tempfile.mkdtemp(prefix="anki")
path = os.path.join(ndir, name)
from anki.exporting import AnkiExporter
e = AnkiExporter(self.deck)
if tags:
e.limitTags = parseTags(tags)
if ids:
e.limitCardIds = ids
path = unicode(path, sys.getfilesystemencoding())
e.exportInto(path)
return (e, path)
def onCram(self):
def onCram(self, cardIds=[]):
if self.deck.name() == "cram":
ui.utils.showInfo(
_("Already cramming. Please close this deck first."))
return
if not self.save(required=True):
return
(s, ret) = ui.utils.getTag(self, self.deck, _("Tags to cram:"),
help="CramMode", tags="all")
if not ret:
return
s = unicode(s)
# open tmp deck
(e, path) = self._copyToTmpDeck(tags=s)
if not cardIds:
(s, ret) = ui.utils.getTag(self, self.deck, _("Tags to cram:"),
help="CramMode", tags="all")
if not ret:
return
s = unicode(s)
# open tmp deck
(e, path) = self._copyToTmpDeck(tags=s)
else:
(e, path) = self._copyToTmpDeck(ids=cardIds)
if not e.exportedCards:
ui.utils.showInfo(_("No cards matched the provided tags."))
return

View file

@ -55,12 +55,20 @@ def showText(text, parent=None):
SIGNAL("clicked()"), d.accept)
d.exec_()
def askUser(text, parent=None):
def askUser(text, parent=None, help=""):
"Show a yes/no question. Return true if yes."
if not parent:
parent = ankiqt.mw
r = QMessageBox.question(parent, "Anki", text,
QMessageBox.Yes | QMessageBox.No)
sb = QMessageBox.Yes | QMessageBox.No
if help:
sb |= QMessageBox.Help
while 1:
r = QMessageBox.question(parent, "Anki", text, sb,
QMessageBox.Yes)
if r == QMessageBox.Help:
openWikiLink(help)
else:
break
return r == QMessageBox.Yes
class GetTextDialog(QDialog):

View file

@ -10,7 +10,7 @@
</rect>
</property>
<property name="windowTitle" >
<string>Edit Items</string>
<string>Browse Items</string>
</property>
<widget class="QWidget" name="centralwidget" >
<property name="geometry" >
@ -198,6 +198,7 @@
<addaction name="actionAddCards" />
<addaction name="actionChangeModel" />
<addaction name="separator" />
<addaction name="actionCram" />
<addaction name="actionReschedule" />
<addaction name="separator" />
<addaction name="actionDelete" />
@ -409,6 +410,15 @@
<string>Find and Re&amp;place...</string>
</property>
</action>
<action name="actionCram" >
<property name="icon" >
<iconset resource="../icons.qrc" >
<normaloff>:/icons/view-pim-calendar.png</normaloff>:/icons/view-pim-calendar.png</iconset>
</property>
<property name="text" >
<string>&amp;Cram...</string>
</property>
</action>
</widget>
<resources>
<include location="../icons.qrc" />

View file

@ -1496,7 +1496,7 @@
<normaloff>:/icons/find.png</normaloff>:/icons/find.png</iconset>
</property>
<property name="text" >
<string>&amp;Edit All...</string>
<string>Brows&amp;e Items...</string>
</property>
<property name="shortcut" >
<string>Ctrl+F</string>