Merge pull request #516 from Arthur-Milchior/hook_models_advanced_will_show

Hook models_advanced_will_show
This commit is contained in:
Damien Elmes 2020-03-20 20:42:14 +10:00 committed by GitHub
commit b2aa0756c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View file

@ -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."""

View file

@ -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()

View file

@ -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(