mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
hook addons_dialog_will_show
This commit is contained in:
parent
18a6b8e33c
commit
4e1838bba8
3 changed files with 34 additions and 0 deletions
|
@ -706,6 +706,7 @@ class AddonsDialog(QDialog):
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
self.redrawAddons()
|
self.redrawAddons()
|
||||||
restoreGeom(self, "addons")
|
restoreGeom(self, "addons")
|
||||||
|
gui_hooks.addons_dialog_will_show(self)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def dragEnterEvent(self, event):
|
def dragEnterEvent(self, event):
|
||||||
|
|
|
@ -135,6 +135,33 @@ class _AddonConfigEditorWillSaveJsonFilter:
|
||||||
addon_config_editor_will_save_json = _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:
|
class _AvPlayerDidBeginPlayingHook:
|
||||||
_hooks: List[Callable[["aqt.sound.Player", "anki.sound.AVTag"], None]] = []
|
_hooks: List[Callable[["aqt.sound.Player", "anki.sound.AVTag"], None]] = []
|
||||||
|
|
||||||
|
|
|
@ -488,6 +488,12 @@ def emptyNewCard():
|
||||||
received from the user before actually reading it. For
|
received from the user before actually reading it. For
|
||||||
example, you can replace new line in strings by some "\\\\n".""",
|
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
|
# Other
|
||||||
###################
|
###################
|
||||||
Hook(
|
Hook(
|
||||||
|
|
Loading…
Reference in a new issue