mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
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:
parent
e3a57a4193
commit
b73507344c
3 changed files with 29 additions and 1 deletions
|
@ -1206,6 +1206,30 @@ class _MediaSyncDidStartOrStopHook:
|
||||||
media_sync_did_start_or_stop = _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:
|
class _OverviewDidRefreshHook:
|
||||||
"""Allow to update the overview window. E.g. add the deck name in the
|
"""Allow to update the overview window. E.g. add the deck name in the
|
||||||
title."""
|
title."""
|
||||||
|
|
|
@ -6,7 +6,7 @@ from operator import itemgetter
|
||||||
import aqt.clayout
|
import aqt.clayout
|
||||||
from anki import stdmodels
|
from anki import stdmodels
|
||||||
from anki.lang import _, ngettext
|
from anki.lang import _, ngettext
|
||||||
from aqt import AnkiQt
|
from aqt import AnkiQt, gui_hooks
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
askUser,
|
askUser,
|
||||||
|
@ -124,6 +124,7 @@ class Models(QDialog):
|
||||||
d.setWindowTitle(_("Options for %s") % self.model["name"])
|
d.setWindowTitle(_("Options for %s") % self.model["name"])
|
||||||
frm.buttonBox.helpRequested.connect(lambda: openHelp("latex"))
|
frm.buttonBox.helpRequested.connect(lambda: openHelp("latex"))
|
||||||
restoreGeom(d, "modelopts")
|
restoreGeom(d, "modelopts")
|
||||||
|
gui_hooks.models_advanced_will_show(d)
|
||||||
d.exec_()
|
d.exec_()
|
||||||
saveGeom(d, "modelopts")
|
saveGeom(d, "modelopts")
|
||||||
self.model["latexsvg"] = frm.latexsvg.isChecked()
|
self.model["latexsvg"] = frm.latexsvg.isChecked()
|
||||||
|
|
|
@ -503,6 +503,9 @@ def emptyNewCard():
|
||||||
args=["dialog: aqt.addons.AddonsDialog", "add_on: aqt.addons.AddonMeta"],
|
args=["dialog: aqt.addons.AddonsDialog", "add_on: aqt.addons.AddonMeta"],
|
||||||
doc="""Allows doing an action when a single add-on is selected.""",
|
doc="""Allows doing an action when a single add-on is selected.""",
|
||||||
),
|
),
|
||||||
|
# Model
|
||||||
|
###################
|
||||||
|
Hook(name="models_advanced_will_show", args=["advanced: QDialog"],),
|
||||||
# Other
|
# Other
|
||||||
###################
|
###################
|
||||||
Hook(
|
Hook(
|
||||||
|
|
Loading…
Reference in a new issue