move .reopen() to mw; fix exporting

This commit is contained in:
Damien Elmes 2020-03-06 14:03:23 +10:00
parent fe59d11047
commit fa12213e98
4 changed files with 9 additions and 13 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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 = (

View File

@ -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)