import mapped files like csv in a background thread
This commit is contained in:
parent
53952ba131
commit
231fa30a86
@ -9,6 +9,7 @@ import shutil
|
||||
import traceback
|
||||
import unicodedata
|
||||
import zipfile
|
||||
from concurrent.futures import Future
|
||||
|
||||
import anki.importing as importing
|
||||
import aqt.deckchooser
|
||||
@ -74,6 +75,7 @@ class ChangeMap(QDialog):
|
||||
self.accept()
|
||||
|
||||
|
||||
# called by importFile() when importing a mappable file like .csv
|
||||
class ImportDialog(QDialog):
|
||||
def __init__(self, mw: AnkiQt, importer) -> None:
|
||||
QDialog.__init__(self, mw, Qt.Window)
|
||||
@ -192,8 +194,12 @@ you can enter it here. Use \\t to represent tab."""
|
||||
self.mw.col.decks.select(did)
|
||||
self.mw.progress.start(immediate=True)
|
||||
self.mw.checkpoint(_("Import"))
|
||||
|
||||
def on_done(future: Future):
|
||||
self.mw.progress.finish()
|
||||
|
||||
try:
|
||||
self.importer.run()
|
||||
future.result()
|
||||
except UnicodeDecodeError:
|
||||
showUnicodeWarning()
|
||||
return
|
||||
@ -208,8 +214,7 @@ you can enter it here. Use \\t to represent tab."""
|
||||
msg += traceback.format_exc()
|
||||
showText(msg)
|
||||
return
|
||||
finally:
|
||||
self.mw.progress.finish()
|
||||
else:
|
||||
txt = _("Importing complete.") + "\n"
|
||||
if self.importer.log:
|
||||
txt += "\n".join(self.importer.log)
|
||||
@ -217,6 +222,8 @@ you can enter it here. Use \\t to represent tab."""
|
||||
showText(txt)
|
||||
self.mw.reset()
|
||||
|
||||
self.mw.taskman.run_in_background(self.importer.run, on_done)
|
||||
|
||||
def setupMappingFrame(self):
|
||||
# qt seems to have a bug with adding/removing from a grid, so we add
|
||||
# to a separate object and add/remove that instead
|
||||
@ -380,9 +387,13 @@ def importFile(mw, file):
|
||||
except:
|
||||
showWarning(invalidZipMsg())
|
||||
return
|
||||
# we need to ask whether to import/replace
|
||||
# we need to ask whether to import/replace; if it's
|
||||
# a colpkg file then the rest of the import process
|
||||
# will happen in setupApkgImport()
|
||||
if not setupApkgImport(mw, importer):
|
||||
return
|
||||
|
||||
# importing non-colpkg files
|
||||
mw.progress.start(immediate=True)
|
||||
try:
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user