mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
parent
856d4763a9
commit
a7cb5e210e
5 changed files with 31 additions and 10 deletions
|
@ -897,6 +897,7 @@ class Browser(QMainWindow):
|
|||
gui_hooks.operation_did_execute.append(self.on_operation_did_execute)
|
||||
gui_hooks.focus_did_change.append(self.on_focus_change)
|
||||
gui_hooks.flag_label_did_change.append(self._update_flag_labels)
|
||||
gui_hooks.collection_will_temporarily_close.append(self._on_temporary_close)
|
||||
|
||||
def teardownHooks(self) -> None:
|
||||
gui_hooks.undo_state_did_change.remove(self.on_undo_state_change)
|
||||
|
@ -905,6 +906,11 @@ class Browser(QMainWindow):
|
|||
gui_hooks.operation_did_execute.remove(self.on_operation_did_execute)
|
||||
gui_hooks.focus_did_change.remove(self.on_focus_change)
|
||||
gui_hooks.flag_label_did_change.remove(self._update_flag_labels)
|
||||
gui_hooks.collection_will_temporarily_close.remove(self._on_temporary_close)
|
||||
|
||||
def _on_temporary_close(self, col: Collection) -> None:
|
||||
# we could reload browser columns in the future; for now we just close
|
||||
self.close()
|
||||
|
||||
# Undo
|
||||
######################################################################
|
||||
|
|
|
@ -15,6 +15,7 @@ from anki import hooks
|
|||
from anki.cards import CardId
|
||||
from anki.decks import DeckId
|
||||
from anki.exporting import Exporter, exporters
|
||||
from aqt import gui_hooks
|
||||
from aqt.errors import show_exception
|
||||
from aqt.qt import *
|
||||
from aqt.utils import (
|
||||
|
@ -181,6 +182,8 @@ class ExportDialog(QDialog):
|
|||
else:
|
||||
self.on_export_finished()
|
||||
|
||||
if self.isVerbatim:
|
||||
gui_hooks.collection_will_temporarily_close(self.mw.col)
|
||||
self.mw.progress.start()
|
||||
hooks.media_files_did_export.append(exported_media)
|
||||
|
||||
|
|
|
@ -575,8 +575,9 @@ class AnkiQt(QMainWindow):
|
|||
self.col = Collection(cpath, backend=self.backend)
|
||||
self.setEnabled(True)
|
||||
|
||||
def reopen(self) -> None:
|
||||
self.col.reopen()
|
||||
def reopen(self, after_full_sync: bool = False) -> None:
|
||||
self.col.reopen(after_full_sync=after_full_sync)
|
||||
gui_hooks.collection_did_temporarily_close(self.col)
|
||||
|
||||
def unloadCollection(self, onsuccess: Callable) -> None:
|
||||
def after_media_sync() -> None:
|
||||
|
@ -629,11 +630,6 @@ class AnkiQt(QMainWindow):
|
|||
if corrupt:
|
||||
showWarning(tr.qt_misc_your_collection_file_appears_to_be())
|
||||
|
||||
def _close_for_full_download(self) -> None:
|
||||
"Backup and prepare collection to be overwritten."
|
||||
self.create_backup_now()
|
||||
self.col.close_for_full_sync()
|
||||
|
||||
def apply_collection_options(self) -> None:
|
||||
"Setup audio after collection loaded."
|
||||
aqt.sound.av_player.interrupt_current_audio = self.col.get_config_bool(
|
||||
|
|
|
@ -14,6 +14,7 @@ from anki.errors import Interrupted, SyncError, SyncErrorKind
|
|||
from anki.lang import without_unicode_isolation
|
||||
from anki.sync import SyncOutput, SyncStatus
|
||||
from anki.utils import plat_desc
|
||||
from aqt import gui_hooks
|
||||
from aqt.qt import (
|
||||
QDialog,
|
||||
QDialogButtonBox,
|
||||
|
@ -181,13 +182,17 @@ def full_download(mw: aqt.main.AnkiQt, on_done: Callable[[], None]) -> None:
|
|||
qconnect(timer.timeout, on_timer)
|
||||
timer.start(150)
|
||||
|
||||
# hook needs to be called early, on the main thread
|
||||
gui_hooks.collection_will_temporarily_close(mw.col)
|
||||
|
||||
def download() -> None:
|
||||
mw._close_for_full_download()
|
||||
mw.create_backup_now()
|
||||
mw.col.close_for_full_sync()
|
||||
mw.col.full_download(mw.pm.sync_auth())
|
||||
|
||||
def on_future_done(fut: Future) -> None:
|
||||
timer.stop()
|
||||
mw.col.reopen(after_full_sync=True)
|
||||
mw.reopen(after_full_sync=True)
|
||||
mw.reset()
|
||||
try:
|
||||
fut.result()
|
||||
|
@ -204,6 +209,7 @@ def full_download(mw: aqt.main.AnkiQt, on_done: Callable[[], None]) -> None:
|
|||
|
||||
|
||||
def full_upload(mw: aqt.main.AnkiQt, on_done: Callable[[], None]) -> None:
|
||||
gui_hooks.collection_will_temporarily_close(mw.col)
|
||||
mw.col.close_for_full_sync()
|
||||
|
||||
def on_timer() -> None:
|
||||
|
@ -215,7 +221,7 @@ def full_upload(mw: aqt.main.AnkiQt, on_done: Callable[[], None]) -> None:
|
|||
|
||||
def on_future_done(fut: Future) -> None:
|
||||
timer.stop()
|
||||
mw.col.reopen(after_full_sync=True)
|
||||
mw.reopen(after_full_sync=True)
|
||||
mw.reset()
|
||||
try:
|
||||
fut.result()
|
||||
|
|
|
@ -688,6 +688,16 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
|
|||
""",
|
||||
),
|
||||
Hook(name="profile_will_close", legacy_hook="unloadProfile"),
|
||||
Hook(
|
||||
name="collection_will_temporarily_close",
|
||||
args=["col: anki.collection.Collection"],
|
||||
doc="""Called before one-way syncs and colpkg imports/exports.""",
|
||||
),
|
||||
Hook(
|
||||
name="collection_did_temporarily_close",
|
||||
args=["col: anki.collection.Collection"],
|
||||
doc="""Called after one-way syncs and colpkg imports/exports.""",
|
||||
),
|
||||
Hook(
|
||||
name="collection_did_load",
|
||||
args=["col: anki.collection.Collection"],
|
||||
|
|
Loading…
Reference in a new issue