add "export" button to deck menus

This commit is contained in:
Soren I. Bjornstad 2014-06-19 19:13:12 -05:00
parent 28bb109ded
commit b4784b7437
3 changed files with 15 additions and 5 deletions

View File

@ -268,10 +268,15 @@ where id > ?""", (self.mw.col.sched.dayCutoff-86400)*1000)
a.connect(a, SIGNAL("triggered()"), lambda did=did: self._rename(did))
a = m.addAction(_("Options"))
a.connect(a, SIGNAL("triggered()"), lambda did=did: self._options(did))
a = m.addAction(_("Export"))
a.connect(a, SIGNAL("triggered()"), lambda did=did: self._export(did))
a = m.addAction(_("Delete"))
a.connect(a, SIGNAL("triggered()"), lambda did=did: self._delete(did))
m.exec_(QCursor.pos())
def _export(self, did):
self.mw.onExport(did=did)
def _rename(self, did):
self.mw.checkpoint(_("Rename Deck"))
deck = self.mw.col.decks.get(did)

View File

@ -12,17 +12,17 @@ from anki.exporting import exporters
class ExportDialog(QDialog):
def __init__(self, mw):
def __init__(self, mw, did=None):
QDialog.__init__(self, mw, Qt.Window)
self.mw = mw
self.col = mw.col
self.frm = aqt.forms.exporting.Ui_ExportDialog()
self.frm.setupUi(self)
self.exporter = None
self.setup()
self.setup(did)
self.exec_()
def setup(self):
def setup(self, did):
self.frm.format.insertItems(0, list(zip(*exporters())[0]))
self.connect(self.frm.format, SIGNAL("activated(int)"),
self.exporterChanged)
@ -32,6 +32,11 @@ class ExportDialog(QDialog):
# save button
b = QPushButton(_("Export..."))
self.frm.buttonBox.addButton(b, QDialogButtonBox.AcceptRole)
# set default option if accessed through deck button
if did:
name = self.mw.col.decks.get(did)['name']
index = self.frm.deck.findText(name)
self.frm.deck.setCurrentIndex(index)
def exporterChanged(self, idx):
self.exporter = exporters()[idx][1](self.col)

View File

@ -764,9 +764,9 @@ title="%s">%s</button>''' % (
import aqt.importing
aqt.importing.onImport(self)
def onExport(self):
def onExport(self, did=None):
import aqt.exporting
aqt.exporting.ExportDialog(self)
aqt.exporting.ExportDialog(self, did=did)
# Cramming
##########################################################################