mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
update exporting dialog
This commit is contained in:
parent
6f0f90fd81
commit
6b2766c2f1
5 changed files with 100 additions and 84 deletions
|
@ -2,74 +2,55 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
import anki, aqt
|
import anki, aqt, aqt.tagedit
|
||||||
from anki.exporting import exporters as exporters_
|
from aqt.utils import getSaveFile, tooltip
|
||||||
from anki.utils import parseTags
|
from anki.exporting import exporters
|
||||||
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
|
|
||||||
|
|
||||||
class ExportDialog(QDialog):
|
class ExportDialog(QDialog):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
QDialog.__init__(self, parent, Qt.Window)
|
QDialog.__init__(self, parent, Qt.Window)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.deck = parent.deck
|
self.col = parent.col
|
||||||
self.dialog = aqt.forms.exporting.Ui_ExportDialog()
|
self.frm = aqt.forms.exporting.Ui_ExportDialog()
|
||||||
self.dialog.setupUi(self)
|
self.frm.setupUi(self)
|
||||||
self.exporter = None
|
self.exporter = None
|
||||||
self.setup()
|
self.setup()
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.dialog.format.insertItems(0, list(zip(*exporters())[0]))
|
self.frm.format.insertItems(0, list(zip(*exporters())[0]))
|
||||||
self.connect(self.dialog.format, SIGNAL("activated(int)"),
|
self.connect(self.frm.format, SIGNAL("activated(int)"),
|
||||||
self.exporterChanged)
|
self.exporterChanged)
|
||||||
self.exporterChanged(0)
|
self.exporterChanged(0)
|
||||||
# fragile
|
self.frm.deck.addItems([_("All Decks")] + sorted(
|
||||||
self.tags = ui.tagedit.TagEdit(self)
|
self.col.decks.allNames()))
|
||||||
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)
|
|
||||||
# save button
|
# save button
|
||||||
b = QPushButton(_("Export..."))
|
b = QPushButton(_("Export..."))
|
||||||
self.dialog.buttonBox.addButton(b, QDialogButtonBox.AcceptRole)
|
self.frm.buttonBox.addButton(b, QDialogButtonBox.AcceptRole)
|
||||||
|
|
||||||
def exporterChanged(self, idx):
|
def exporterChanged(self, idx):
|
||||||
self.exporter = exporters()[idx][1](self.deck)
|
self.exporter = exporters()[idx][1](self.col)
|
||||||
if hasattr(self.exporter, "includeSchedulingInfo"):
|
isAnki = hasattr(self.exporter, "includeSched")
|
||||||
self.dialog.includeScheduling.show()
|
self.frm.includeSched.setShown(isAnki)
|
||||||
else:
|
self.frm.includeMedia.setShown(isAnki)
|
||||||
self.dialog.includeScheduling.hide()
|
self.frm.includeTags.setShown(not isAnki)
|
||||||
if hasattr(self.exporter, "includeTags"):
|
|
||||||
self.dialog.includeTags.show()
|
|
||||||
else:
|
|
||||||
self.dialog.includeTags.hide()
|
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
if isinstance(self.exporter, PackagedAnkiExporter):
|
file = getSaveFile(
|
||||||
self.parent.onShare(unicode(self.tags.text()))
|
self, _("Choose file to export to"), "export",
|
||||||
return QDialog.accept(self)
|
self.exporter.key, self.exporter.ext)
|
||||||
file = ui.utils.getSaveFile(self, _("Choose file to export to"), "export",
|
|
||||||
self.exporter.key, self.exporter.ext)
|
|
||||||
self.hide()
|
self.hide()
|
||||||
|
print file
|
||||||
if file:
|
if file:
|
||||||
self.exporter.includeSchedulingInfo = (
|
self.exporter.includeSched = (
|
||||||
self.dialog.includeScheduling.isChecked())
|
self.frm.includeSched.isChecked())
|
||||||
self.exporter.includeTags = (
|
self.exporter.includeTags = (
|
||||||
self.dialog.includeTags.isChecked())
|
self.frm.includeTags.isChecked())
|
||||||
self.exporter.limitTags = parseTags(unicode(self.tags.text()))
|
if not self.frm.deck.currentIndex():
|
||||||
|
self.exporter.did = None
|
||||||
|
else:
|
||||||
|
self.exporter.did = self.frm.deck.currentIndex() - 1
|
||||||
self.exporter.exportInto(file)
|
self.exporter.exportInto(file)
|
||||||
self.parent.setStatus(_("%d exported.") % self.exporter.count)
|
tooltip(_("%d exported.") % self.exporter.count)
|
||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
|
|
|
@ -204,6 +204,7 @@ Are you sure?"""):
|
||||||
# maybe sync (will load DB)
|
# maybe sync (will load DB)
|
||||||
self.onSync(auto=True)
|
self.onSync(auto=True)
|
||||||
runHook("profileLoaded")
|
runHook("profileLoaded")
|
||||||
|
self.onExport()
|
||||||
|
|
||||||
def unloadProfile(self, browser=True):
|
def unloadProfile(self, browser=True):
|
||||||
if not self.pm.profile:
|
if not self.pm.profile:
|
||||||
|
@ -717,7 +718,7 @@ Please choose a new deck name:"""))
|
||||||
aqt.importing.ImportDialog(self)
|
aqt.importing.ImportDialog(self)
|
||||||
|
|
||||||
def onExport(self):
|
def onExport(self):
|
||||||
return showInfo("not yet implemented")
|
import aqt.exporting
|
||||||
aqt.exporting.ExportDialog(self)
|
aqt.exporting.ExportDialog(self)
|
||||||
|
|
||||||
# Language handling
|
# Language handling
|
||||||
|
@ -764,6 +765,8 @@ Please choose a new deck name:"""))
|
||||||
s = SIGNAL("triggered()")
|
s = SIGNAL("triggered()")
|
||||||
#self.connect(m.actionDownloadSharedPlugin, s, self.onGetSharedPlugin)
|
#self.connect(m.actionDownloadSharedPlugin, s, self.onGetSharedPlugin)
|
||||||
self.connect(m.actionSwitchProfile, s, self.unloadProfile)
|
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.actionExit, s, self, SLOT("close()"))
|
||||||
self.connect(m.actionPreferences, s, self.onPrefs)
|
self.connect(m.actionPreferences, s, self.onPrefs)
|
||||||
self.connect(m.actionCstats, s, self.onCardStats)
|
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 \
|
clock is slow or fast, because the date is set incorrectly, or because \
|
||||||
the timezone or daylight savings information is incorrect. Please correct \
|
the timezone or daylight savings information is incorrect. Please correct \
|
||||||
the problem and restart Anki.""")
|
the problem and restart Anki.""")
|
||||||
self.onClose()
|
self.app.closeAllWindows()
|
||||||
|
|
||||||
# Schema modifications
|
# Schema modifications
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -242,8 +242,8 @@ def getSaveFile(parent, title, dir, key, ext):
|
||||||
"Ask the user for a file to save. Use DIR as config variable."
|
"Ask the user for a file to save. Use DIR as config variable."
|
||||||
dirkey = dir+"Directory"
|
dirkey = dir+"Directory"
|
||||||
file = unicode(QFileDialog.getSaveFileName(
|
file = unicode(QFileDialog.getSaveFileName(
|
||||||
parent, title, aqt.mw.pm.profile.get(dirkey, ""), key,
|
parent, title, aqt.mw.pm.base, key,
|
||||||
None, QFileDialog.DontConfirmOverwrite))
|
options=QFileDialog.DontConfirmOverwrite))
|
||||||
if file:
|
if file:
|
||||||
# add extension
|
# add extension
|
||||||
if not file.lower().endswith(ext):
|
if not file.lower().endswith(ext):
|
||||||
|
|
|
@ -1,57 +1,68 @@
|
||||||
<ui version="4.0" >
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
<class>ExportDialog</class>
|
<class>ExportDialog</class>
|
||||||
<widget class="QDialog" name="ExportDialog" >
|
<widget class="QDialog" name="ExportDialog">
|
||||||
<property name="geometry" >
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>295</width>
|
<width>295</width>
|
||||||
<height>154</height>
|
<height>202</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle">
|
||||||
<string>Export</string>
|
<string>Export</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QVBoxLayout">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" >
|
<layout class="QGridLayout">
|
||||||
<item row="0" column="0" >
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label" >
|
<widget class="QLabel" name="label">
|
||||||
<property name="minimumSize" >
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>100</width>
|
<width>100</width>
|
||||||
<height>0</height>
|
<height>0</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string><b>Export format</b>:</string>
|
<string><b>Export format</b>:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1" >
|
<item row="0" column="1">
|
||||||
<widget class="QComboBox" name="format" />
|
<widget class="QComboBox" name="format"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" >
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_2" >
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string><b>Limit to tags</b>:</string>
|
<string><b>Limit to deck</b>:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QComboBox" name="deck"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QVBoxLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="includeScheduling" >
|
<widget class="QCheckBox" name="includeSched">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Include scheduling information</string>
|
<string>Include scheduling information</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="includeTags" >
|
<widget class="QCheckBox" name="includeMedia">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
|
<string>Include media</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="includeTags">
|
||||||
|
<property name="text">
|
||||||
<string>Include tags</string>
|
<string>Include tags</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -59,11 +70,11 @@
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer" >
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation" >
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0" >
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>20</width>
|
<width>20</width>
|
||||||
<height>40</height>
|
<height>40</height>
|
||||||
|
@ -72,17 +83,25 @@
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation" >
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="standardButtons" >
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Cancel</set>
|
<set>QDialogButtonBox::Cancel</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>format</tabstop>
|
||||||
|
<tabstop>deck</tabstop>
|
||||||
|
<tabstop>includeSched</tabstop>
|
||||||
|
<tabstop>includeMedia</tabstop>
|
||||||
|
<tabstop>includeTags</tabstop>
|
||||||
|
<tabstop>buttonBox</tabstop>
|
||||||
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
|
@ -91,11 +110,11 @@
|
||||||
<receiver>ExportDialog</receiver>
|
<receiver>ExportDialog</receiver>
|
||||||
<slot>accept()</slot>
|
<slot>accept()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel" >
|
<hint type="sourcelabel">
|
||||||
<x>248</x>
|
<x>248</x>
|
||||||
<y>254</y>
|
<y>254</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel" >
|
<hint type="destinationlabel">
|
||||||
<x>157</x>
|
<x>157</x>
|
||||||
<y>274</y>
|
<y>274</y>
|
||||||
</hint>
|
</hint>
|
||||||
|
@ -107,11 +126,11 @@
|
||||||
<receiver>ExportDialog</receiver>
|
<receiver>ExportDialog</receiver>
|
||||||
<slot>reject()</slot>
|
<slot>reject()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel" >
|
<hint type="sourcelabel">
|
||||||
<x>316</x>
|
<x>316</x>
|
||||||
<y>260</y>
|
<y>260</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel" >
|
<hint type="destinationlabel">
|
||||||
<x>286</x>
|
<x>286</x>
|
||||||
<y>274</y>
|
<y>274</y>
|
||||||
</hint>
|
</hint>
|
||||||
|
|
|
@ -70,6 +70,9 @@
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionSwitchProfile"/>
|
<addaction name="actionSwitchProfile"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionImport"/>
|
||||||
|
<addaction name="actionExport"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionExit"/>
|
<addaction name="actionExit"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuTools">
|
<widget class="QMenu" name="menuTools">
|
||||||
|
@ -221,6 +224,16 @@
|
||||||
<string>&Switch Profile...</string>
|
<string>&Switch Profile...</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionExport">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Export...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionImport">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Import...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="icons.qrc"/>
|
<include location="icons.qrc"/>
|
||||||
|
|
Loading…
Reference in a new issue