Hook models_advanced_will_show

This will be useful for add-on 1863928230. I want to let users change
the LaTeX footer/header everywhere.
This commit is contained in:
Arthur Milchior 2020-03-19 12:03:09 +01:00
parent e3a57a4193
commit b73507344c
3 changed files with 29 additions and 1 deletions

View file

@ -1206,6 +1206,30 @@ class _MediaSyncDidStartOrStopHook:
media_sync_did_start_or_stop = _MediaSyncDidStartOrStopHook()
class _ModelsAdvancedWillShowHook:
_hooks: List[Callable[[QDialog], None]] = []
def append(self, cb: Callable[[QDialog], None]) -> None:
"""(advanced: QDialog)"""
self._hooks.append(cb)
def remove(self, cb: Callable[[QDialog], None]) -> None:
if cb in self._hooks:
self._hooks.remove(cb)
def __call__(self, advanced: QDialog) -> None:
for hook in self._hooks:
try:
hook(advanced)
except:
# if the hook fails, remove it
self._hooks.remove(hook)
raise
models_advanced_will_show = _ModelsAdvancedWillShowHook()
class _OverviewDidRefreshHook:
"""Allow to update the overview window. E.g. add the deck name in the
title."""

View file

@ -6,7 +6,7 @@ from operator import itemgetter
import aqt.clayout
from anki import stdmodels
from anki.lang import _, ngettext
from aqt import AnkiQt
from aqt import AnkiQt, gui_hooks
from aqt.qt import *
from aqt.utils import (
askUser,
@ -124,6 +124,7 @@ class Models(QDialog):
d.setWindowTitle(_("Options for %s") % self.model["name"])
frm.buttonBox.helpRequested.connect(lambda: openHelp("latex"))
restoreGeom(d, "modelopts")
gui_hooks.models_advanced_will_show(d)
d.exec_()
saveGeom(d, "modelopts")
self.model["latexsvg"] = frm.latexsvg.isChecked()

View file

@ -503,6 +503,9 @@ def emptyNewCard():
args=["dialog: aqt.addons.AddonsDialog", "add_on: aqt.addons.AddonMeta"],
doc="""Allows doing an action when a single add-on is selected.""",
),
# Model
###################
Hook(name="models_advanced_will_show", args=["advanced: QDialog"],),
# Other
###################
Hook(