Fix description of exporters
Description broke yet again with the full migration to Fluent
This commit is contained in:
parent
ea1bb4fb89
commit
e3b4802f47
@ -8,7 +8,7 @@ import shutil
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
import zipfile
|
import zipfile
|
||||||
from io import BufferedWriter
|
from io import BufferedWriter
|
||||||
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from anki import hooks
|
from anki import hooks
|
||||||
@ -20,7 +20,6 @@ from anki.utils import ids2str, namedtmp, splitFields, stripHTML
|
|||||||
class Exporter:
|
class Exporter:
|
||||||
includeHTML: Union[bool, None] = None
|
includeHTML: Union[bool, None] = None
|
||||||
ext: Optional[str] = None
|
ext: Optional[str] = None
|
||||||
key: Union[str, Callable, None] = None
|
|
||||||
includeTags: Optional[bool] = None
|
includeTags: Optional[bool] = None
|
||||||
includeSched: Optional[bool] = None
|
includeSched: Optional[bool] = None
|
||||||
includeMedia: Optional[bool] = None
|
includeMedia: Optional[bool] = None
|
||||||
@ -35,6 +34,10 @@ class Exporter:
|
|||||||
self.did = did
|
self.did = did
|
||||||
self.cids = cids
|
self.cids = cids
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def key(col: Collection) -> str:
|
||||||
|
return ""
|
||||||
|
|
||||||
def doExport(self, path) -> None:
|
def doExport(self, path) -> None:
|
||||||
raise Exception("not implemented")
|
raise Exception("not implemented")
|
||||||
|
|
||||||
@ -97,7 +100,10 @@ class TextCardExporter(Exporter):
|
|||||||
|
|
||||||
def __init__(self, col) -> None:
|
def __init__(self, col) -> None:
|
||||||
Exporter.__init__(self, col)
|
Exporter.__init__(self, col)
|
||||||
self.key = col.tr(TR.EXPORTING_CARDS_IN_PLAIN_TEXT)
|
|
||||||
|
@staticmethod
|
||||||
|
def key(col: Collection) -> str:
|
||||||
|
return col.tr(TR.EXPORTING_CARDS_IN_PLAIN_TEXT)
|
||||||
|
|
||||||
def doExport(self, file) -> None:
|
def doExport(self, file) -> None:
|
||||||
ids = sorted(self.cardIds())
|
ids = sorted(self.cardIds())
|
||||||
@ -129,7 +135,10 @@ class TextNoteExporter(Exporter):
|
|||||||
def __init__(self, col: Collection) -> None:
|
def __init__(self, col: Collection) -> None:
|
||||||
Exporter.__init__(self, col)
|
Exporter.__init__(self, col)
|
||||||
self.includeID = False
|
self.includeID = False
|
||||||
self.key = col.tr(TR.EXPORTING_NOTES_IN_PLAIN_TEXT)
|
|
||||||
|
@staticmethod
|
||||||
|
def key(col: Collection) -> str:
|
||||||
|
return col.tr(TR.EXPORTING_NOTES_IN_PLAIN_TEXT)
|
||||||
|
|
||||||
def doExport(self, file: BufferedWriter) -> None:
|
def doExport(self, file: BufferedWriter) -> None:
|
||||||
cardIds = self.cardIds()
|
cardIds = self.cardIds()
|
||||||
@ -170,7 +179,10 @@ class AnkiExporter(Exporter):
|
|||||||
|
|
||||||
def __init__(self, col: Collection) -> None:
|
def __init__(self, col: Collection) -> None:
|
||||||
Exporter.__init__(self, col)
|
Exporter.__init__(self, col)
|
||||||
self.key = col.tr(TR.EXPORTING_ANKI_20_DECK)
|
|
||||||
|
@staticmethod
|
||||||
|
def key(col: Collection) -> str:
|
||||||
|
return col.tr(TR.EXPORTING_ANKI_20_DECK)
|
||||||
|
|
||||||
def deckIds(self) -> List[int]:
|
def deckIds(self) -> List[int]:
|
||||||
if self.cids:
|
if self.cids:
|
||||||
@ -317,7 +329,10 @@ class AnkiPackageExporter(AnkiExporter):
|
|||||||
|
|
||||||
def __init__(self, col: Collection) -> None:
|
def __init__(self, col: Collection) -> None:
|
||||||
AnkiExporter.__init__(self, col)
|
AnkiExporter.__init__(self, col)
|
||||||
self.key = col.tr(TR.EXPORTING_ANKI_DECK_PACKAGE)
|
|
||||||
|
@staticmethod
|
||||||
|
def key(col: Collection) -> str:
|
||||||
|
return col.tr(TR.EXPORTING_ANKI_DECK_PACKAGE)
|
||||||
|
|
||||||
def exportInto(self, path: str) -> None:
|
def exportInto(self, path: str) -> None:
|
||||||
# open a zip file
|
# open a zip file
|
||||||
@ -401,7 +416,10 @@ class AnkiCollectionPackageExporter(AnkiPackageExporter):
|
|||||||
|
|
||||||
def __init__(self, col):
|
def __init__(self, col):
|
||||||
AnkiPackageExporter.__init__(self, col)
|
AnkiPackageExporter.__init__(self, col)
|
||||||
self.key = col.tr(TR.EXPORTING_ANKI_COLLECTION_PACKAGE)
|
|
||||||
|
@staticmethod
|
||||||
|
def key(col: Collection) -> str:
|
||||||
|
return col.tr(TR.EXPORTING_ANKI_COLLECTION_PACKAGE)
|
||||||
|
|
||||||
def doExport(self, z, path):
|
def doExport(self, z, path):
|
||||||
"Export collection. Caller must re-open afterwards."
|
"Export collection. Caller must re-open afterwards."
|
||||||
@ -425,10 +443,10 @@ class AnkiCollectionPackageExporter(AnkiPackageExporter):
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
||||||
def exporters() -> List[Tuple[str, Any]]:
|
def exporters(col: Collection) -> List[Tuple[str, Any]]:
|
||||||
def id(obj):
|
def id(obj):
|
||||||
if callable(obj.key):
|
if callable(obj.key):
|
||||||
key_str = obj.key(obj)
|
key_str = obj.key(col)
|
||||||
else:
|
else:
|
||||||
key_str = obj.key
|
key_str = obj.key
|
||||||
return ("%s (*%s)" % (key_str, obj.ext), obj)
|
return ("%s (*%s)" % (key_str, obj.ext), obj)
|
||||||
|
@ -161,4 +161,4 @@ def test_export_textnote():
|
|||||||
|
|
||||||
|
|
||||||
def test_exporters():
|
def test_exporters():
|
||||||
assert "*.apkg" in str(exporters())
|
assert "*.apkg" in str(exporters(getEmptyCol()))
|
||||||
|
@ -34,7 +34,7 @@ class ExportDialog(QDialog):
|
|||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
||||||
def setup(self, did: Optional[int]):
|
def setup(self, did: Optional[int]):
|
||||||
self.exporters = exporters()
|
self.exporters = exporters(self.col)
|
||||||
# if a deck specified, start with .apkg type selected
|
# if a deck specified, start with .apkg type selected
|
||||||
idx = 0
|
idx = 0
|
||||||
if did or self.cids:
|
if did or self.cids:
|
||||||
@ -114,7 +114,7 @@ class ExportDialog(QDialog):
|
|||||||
|
|
||||||
filename = "{0}{1}".format(deck_name, self.exporter.ext)
|
filename = "{0}{1}".format(deck_name, self.exporter.ext)
|
||||||
if callable(self.exporter.key):
|
if callable(self.exporter.key):
|
||||||
key_str = self.exporter.key()
|
key_str = self.exporter.key(self.col)
|
||||||
else:
|
else:
|
||||||
key_str = self.exporter.key
|
key_str = self.exporter.key
|
||||||
while 1:
|
while 1:
|
||||||
|
Loading…
Reference in New Issue
Block a user