update exporting dialog

This commit is contained in:
Damien Elmes 2012-02-26 03:12:21 +09:00
parent 6f0f90fd81
commit 6b2766c2f1
5 changed files with 100 additions and 84 deletions

View file

@ -2,74 +2,55 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from aqt.qt import *
import anki, aqt
from anki.exporting import exporters as exporters_
from anki.utils import parseTags
from aqt import ui
class PackagedAnkiExporter(object):
def __init__(self, *args):
pass
def exporters():
l = list(exporters_())
l.insert(1, (_("Packaged Anki Deck (*.zip)"),
PackagedAnkiExporter))
return l
import anki, aqt, aqt.tagedit
from aqt.utils import getSaveFile, tooltip
from anki.exporting import exporters
class ExportDialog(QDialog):
def __init__(self, parent):
QDialog.__init__(self, parent, Qt.Window)
self.parent = parent
self.deck = parent.deck
self.dialog = aqt.forms.exporting.Ui_ExportDialog()
self.dialog.setupUi(self)
self.col = parent.col
self.frm = aqt.forms.exporting.Ui_ExportDialog()
self.frm.setupUi(self)
self.exporter = None
self.setup()
self.exec_()
def setup(self):
self.dialog.format.insertItems(0, list(zip(*exporters())[0]))
self.connect(self.dialog.format, SIGNAL("activated(int)"),
self.frm.format.insertItems(0, list(zip(*exporters())[0]))
self.connect(self.frm.format, SIGNAL("activated(int)"),
self.exporterChanged)
self.exporterChanged(0)
# fragile
self.tags = ui.tagedit.TagEdit(self)
self.tags.setDeck(self.deck)
self.dialog.gridlayout.addWidget(self.tags,1,1)
self.setTabOrder(self.dialog.format,
self.tags)
self.setTabOrder(self.tags,
self.dialog.includeScheduling)
self.frm.deck.addItems([_("All Decks")] + sorted(
self.col.decks.allNames()))
# save button
b = QPushButton(_("Export..."))
self.dialog.buttonBox.addButton(b, QDialogButtonBox.AcceptRole)
self.frm.buttonBox.addButton(b, QDialogButtonBox.AcceptRole)
def exporterChanged(self, idx):
self.exporter = exporters()[idx][1](self.deck)
if hasattr(self.exporter, "includeSchedulingInfo"):
self.dialog.includeScheduling.show()
else:
self.dialog.includeScheduling.hide()
if hasattr(self.exporter, "includeTags"):
self.dialog.includeTags.show()
else:
self.dialog.includeTags.hide()
self.exporter = exporters()[idx][1](self.col)
isAnki = hasattr(self.exporter, "includeSched")
self.frm.includeSched.setShown(isAnki)
self.frm.includeMedia.setShown(isAnki)
self.frm.includeTags.setShown(not isAnki)
def accept(self):
if isinstance(self.exporter, PackagedAnkiExporter):
self.parent.onShare(unicode(self.tags.text()))
return QDialog.accept(self)
file = ui.utils.getSaveFile(self, _("Choose file to export to"), "export",
file = getSaveFile(
self, _("Choose file to export to"), "export",
self.exporter.key, self.exporter.ext)
self.hide()
print file
if file:
self.exporter.includeSchedulingInfo = (
self.dialog.includeScheduling.isChecked())
self.exporter.includeSched = (
self.frm.includeSched.isChecked())
self.exporter.includeTags = (
self.dialog.includeTags.isChecked())
self.exporter.limitTags = parseTags(unicode(self.tags.text()))
self.frm.includeTags.isChecked())
if not self.frm.deck.currentIndex():
self.exporter.did = None
else:
self.exporter.did = self.frm.deck.currentIndex() - 1
self.exporter.exportInto(file)
self.parent.setStatus(_("%d exported.") % self.exporter.count)
tooltip(_("%d exported.") % self.exporter.count)
QDialog.accept(self)

View file

@ -204,6 +204,7 @@ Are you sure?"""):
# maybe sync (will load DB)
self.onSync(auto=True)
runHook("profileLoaded")
self.onExport()
def unloadProfile(self, browser=True):
if not self.pm.profile:
@ -717,7 +718,7 @@ Please choose a new deck name:"""))
aqt.importing.ImportDialog(self)
def onExport(self):
return showInfo("not yet implemented")
import aqt.exporting
aqt.exporting.ExportDialog(self)
# Language handling
@ -764,6 +765,8 @@ Please choose a new deck name:"""))
s = SIGNAL("triggered()")
#self.connect(m.actionDownloadSharedPlugin, s, self.onGetSharedPlugin)
self.connect(m.actionSwitchProfile, s, self.unloadProfile)
self.connect(m.actionImport, s, self.onImport)
self.connect(m.actionExport, s, self.onExport)
self.connect(m.actionExit, s, self, SLOT("close()"))
self.connect(m.actionPreferences, s, self.onPrefs)
self.connect(m.actionCstats, s, self.onCardStats)
@ -809,7 +812,7 @@ This can be because the \
clock is slow or fast, because the date is set incorrectly, or because \
the timezone or daylight savings information is incorrect. Please correct \
the problem and restart Anki.""")
self.onClose()
self.app.closeAllWindows()
# Schema modifications
##########################################################################

View file

@ -242,8 +242,8 @@ def getSaveFile(parent, title, dir, key, ext):
"Ask the user for a file to save. Use DIR as config variable."
dirkey = dir+"Directory"
file = unicode(QFileDialog.getSaveFileName(
parent, title, aqt.mw.pm.profile.get(dirkey, ""), key,
None, QFileDialog.DontConfirmOverwrite))
parent, title, aqt.mw.pm.base, key,
options=QFileDialog.DontConfirmOverwrite))
if file:
# add extension
if not file.lower().endswith(ext):

View file

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExportDialog</class>
<widget class="QDialog" name="ExportDialog">
@ -6,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>295</width>
<height>154</height>
<height>202</height>
</rect>
</property>
<property name="windowTitle">
@ -24,7 +25,7 @@
</size>
</property>
<property name="text">
<string>&lt;b>Export format&lt;/b>:</string>
<string>&lt;b&gt;Export format&lt;/b&gt;:</string>
</property>
</widget>
</item>
@ -34,21 +35,31 @@
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&lt;b>Limit to tags&lt;/b>:</string>
<string>&lt;b&gt;Limit to deck&lt;/b&gt;:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="deck"/>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout">
<item>
<widget class="QCheckBox" name="includeScheduling" >
<widget class="QCheckBox" name="includeSched">
<property name="text">
<string>Include scheduling information</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="includeMedia">
<property name="text">
<string>Include media</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="includeTags">
<property name="text">
@ -83,6 +94,14 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>format</tabstop>
<tabstop>deck</tabstop>
<tabstop>includeSched</tabstop>
<tabstop>includeMedia</tabstop>
<tabstop>includeTags</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>

View file

@ -70,6 +70,9 @@
</property>
<addaction name="actionSwitchProfile"/>
<addaction name="separator"/>
<addaction name="actionImport"/>
<addaction name="actionExport"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuTools">
@ -221,6 +224,16 @@
<string>&amp;Switch Profile...</string>
</property>
</action>
<action name="actionExport">
<property name="text">
<string>&amp;Export...</string>
</property>
</action>
<action name="actionImport">
<property name="text">
<string>&amp;Import...</string>
</property>
</action>
</widget>
<resources>
<include location="icons.qrc"/>