From fa12213e987a86e538a1082a6e0e06f335e830dd Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 6 Mar 2020 14:03:23 +1000 Subject: [PATCH] move .reopen() to mw; fix exporting --- pylib/anki/collection.py | 8 -------- pylib/anki/exporting.py | 6 +++--- qt/aqt/exporting.py | 3 ++- qt/aqt/main.py | 5 ++++- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index 95fef5eaa..06442fe95 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -262,14 +262,6 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""", self.media.close() self._closeLog() - def reopen(self) -> None: - "Reconnect to DB (after changing threads, etc)." - raise Exception("fixme") - # if not self.db: - # # self.db = DBProxy(self.path) - # self.media.connect() - # self._openLog() - def rollback(self) -> None: self.db.rollback() self.db.begin() diff --git a/pylib/anki/exporting.py b/pylib/anki/exporting.py index 67fd5faa6..92a77d2a9 100644 --- a/pylib/anki/exporting.py +++ b/pylib/anki/exporting.py @@ -397,20 +397,20 @@ class AnkiCollectionPackageExporter(AnkiPackageExporter): AnkiPackageExporter.__init__(self, col) def doExport(self, z, path): - # close our deck & write it into the zip file, and reopen + "Export collection. Caller must re-open afterwards." + # close our deck & write it into the zip file self.count = self.col.cardCount() v2 = self.col.schedVer() != 1 + mdir = self.col.media.dir() self.col.close() if not v2: z.write(self.col.path, "collection.anki2") else: self._addDummyCollection(z) z.write(self.col.path, "collection.anki21") - self.col.reopen() # copy all media if not self.includeMedia: return {} - mdir = self.col.media.dir() return self._exportMedia(z, os.listdir(mdir), mdir) diff --git a/qt/aqt/exporting.py b/qt/aqt/exporting.py index 8b6657f8d..2e63e65e7 100644 --- a/qt/aqt/exporting.py +++ b/qt/aqt/exporting.py @@ -25,7 +25,7 @@ class ExportDialog(QDialog): ): QDialog.__init__(self, mw, Qt.Window) self.mw = mw - self.col = mw.col + self.col = mw.col.weakref() self.frm = aqt.forms.exporting.Ui_ExportDialog() self.frm.setupUi(self) self.exporter = None @@ -151,6 +151,7 @@ class ExportDialog(QDialog): period = 3000 if self.isVerbatim: msg = _("Collection exported.") + self.mw.reopen() else: if self.isTextNote: msg = ( diff --git a/qt/aqt/main.py b/qt/aqt/main.py index dd3ab2566..661608dcc 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -459,7 +459,6 @@ close the profile or restart Anki.""" def _loadCollection(self) -> bool: cpath = self.pm.collectionPath() - self.col = Collection(cpath) self.setEnabled(True) @@ -467,6 +466,10 @@ close the profile or restart Anki.""" self.moveToState("deckBrowser") return True + def reopen(self): + cpath = self.pm.collectionPath() + self.col = Collection(cpath) + def unloadCollection(self, onsuccess: Callable) -> None: def callback(): self.setEnabled(False)