Skip to content

Commit

Permalink
move .reopen() to mw; fix exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed Mar 20, 2020
1 parent fe59d11 commit fa12213
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
8 changes: 0 additions & 8 deletions pylib/anki/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,6 @@ def close(self, save: bool = True) -> None:
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()
Expand Down
6 changes: 3 additions & 3 deletions pylib/anki/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,20 +397,20 @@ def __init__(self, col):
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)


Expand Down
3 changes: 2 additions & 1 deletion qt/aqt/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(
):
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
Expand Down Expand Up @@ -151,6 +151,7 @@ def accept(self):
period = 3000
if self.isVerbatim:
msg = _("Collection exported.")
self.mw.reopen()
else:
if self.isTextNote:
msg = (
Expand Down
5 changes: 4 additions & 1 deletion qt/aqt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,17 @@ def loadCollection(self) -> bool:

def _loadCollection(self) -> bool:
cpath = self.pm.collectionPath()

self.col = Collection(cpath)

self.setEnabled(True)
self.maybeEnableUndo()
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)
Expand Down

0 comments on commit fa12213

Please sign in to comment.