hook addons_dialog_will_show

This commit is contained in:
Arthur Milchior 2020-03-06 21:04:51 +01:00
parent 18a6b8e33c
commit 4e1838bba8
3 changed files with 34 additions and 0 deletions

View file

@ -706,6 +706,7 @@ class AddonsDialog(QDialog):
self.setAcceptDrops(True)
self.redrawAddons()
restoreGeom(self, "addons")
gui_hooks.addons_dialog_will_show(self)
self.show()
def dragEnterEvent(self, event):

View file

@ -135,6 +135,33 @@ class _AddonConfigEditorWillSaveJsonFilter:
addon_config_editor_will_save_json = _AddonConfigEditorWillSaveJsonFilter()
class _AddonsDialogWillShowHook:
"""Allows changing the add-on dialog before it is shown. E.g. add
buttons."""
_hooks: List[Callable[["aqt.addons.AddonsDialog"], None]] = []
def append(self, cb: Callable[["aqt.addons.AddonsDialog"], None]) -> None:
"""(dialog: aqt.addons.AddonsDialog)"""
self._hooks.append(cb)
def remove(self, cb: Callable[["aqt.addons.AddonsDialog"], None]) -> None:
if cb in self._hooks:
self._hooks.remove(cb)
def __call__(self, dialog: aqt.addons.AddonsDialog) -> None:
for hook in self._hooks:
try:
hook(dialog)
except:
# if the hook fails, remove it
self._hooks.remove(hook)
raise
addons_dialog_will_show = _AddonsDialogWillShowHook()
class _AvPlayerDidBeginPlayingHook:
_hooks: List[Callable[["aqt.sound.Player", "anki.sound.AVTag"], None]] = []

View file

@ -488,6 +488,12 @@ def emptyNewCard():
received from the user before actually reading it. For
example, you can replace new line in strings by some "\\\\n".""",
),
Hook(
name="addons_dialog_will_show",
args=["dialog: aqt.addons.AddonsDialog"],
doc="""Allows changing the add-on dialog before it is shown. E.g. add
buttons.""",
),
# Other
###################
Hook(