From 5eac3b90613e13016c3981a789e53dc03acfa8c5 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sat, 28 Aug 2021 20:37:31 +0200 Subject: [PATCH] Add a hook for subscribing to dialog creation / opening --- qt/aqt/__init__.py | 2 ++ qt/tools/genhooks_gui.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index e617eaa0939..315df7fc65d 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -18,6 +18,7 @@ from anki.collection import Collection from anki.consts import HELP_SITE from anki.utils import checksum, isLin, isMac +from aqt import gui_hooks from aqt.qt import * from aqt.utils import TR, locale_dir, tr @@ -114,6 +115,7 @@ def open(self, name: str, *args: Any, **kwargs: Any) -> Any: else: instance = creator(*args, **kwargs) self._dialogs[name][1] = instance + gui_hooks.dialog_manager_did_open_dialog(self, name, instance) return instance def markClosed(self, name: str) -> None: diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index a97ff21f7d4..0387bca7f9a 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -736,6 +736,17 @@ def on_top_toolbar_did_init_links(links, toolbar): Note that the media sync did not necessarily finish at this point.""", ), Hook(name="media_check_will_start", args=[]), + # Dialog Manager + ################### + Hook( + name="dialog_manager_did_open_dialog", + args=[ + "dialog_manager: aqt.DialogManager", + "dialog_name: str", + "dialog_instance: QWidget", + ], + doc="""Executed after aqt.dialogs creates a dialog window""", + ), # Adding cards ################### Hook(