mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Add deck_conf_did_setup_ui_form hook
Called earlier than deck_conf_will_show, allowing add-on authors to perform UI modifications before the deck config is loaded.
This commit is contained in:
parent
335047187a
commit
7cc9311b79
3 changed files with 32 additions and 0 deletions
|
@ -29,6 +29,7 @@ class DeckConf(QDialog):
|
||||||
self._origNewOrder = None
|
self._origNewOrder = None
|
||||||
self.form = aqt.forms.dconf.Ui_Dialog()
|
self.form = aqt.forms.dconf.Ui_Dialog()
|
||||||
self.form.setupUi(self)
|
self.form.setupUi(self)
|
||||||
|
gui_hooks.deck_conf_did_setup_ui_form(self)
|
||||||
self.mw.checkpoint(_("Options"))
|
self.mw.checkpoint(_("Options"))
|
||||||
self.setupCombos()
|
self.setupCombos()
|
||||||
self.setupConfs()
|
self.setupConfs()
|
||||||
|
|
|
@ -544,6 +544,32 @@ class _DeckConfDidLoadConfigHook:
|
||||||
deck_conf_did_load_config = _DeckConfDidLoadConfigHook()
|
deck_conf_did_load_config = _DeckConfDidLoadConfigHook()
|
||||||
|
|
||||||
|
|
||||||
|
class _DeckConfDidSetupUiFormHook:
|
||||||
|
"""Allows modifying or adding widgets in the deck options UI form"""
|
||||||
|
|
||||||
|
_hooks: List[Callable[["aqt.deckconf.DeckConf"], None]] = []
|
||||||
|
|
||||||
|
def append(self, cb: Callable[["aqt.deckconf.DeckConf"], None]) -> None:
|
||||||
|
"""(deck_conf: aqt.deckconf.DeckConf)"""
|
||||||
|
self._hooks.append(cb)
|
||||||
|
|
||||||
|
def remove(self, cb: Callable[["aqt.deckconf.DeckConf"], None]) -> None:
|
||||||
|
if cb in self._hooks:
|
||||||
|
self._hooks.remove(cb)
|
||||||
|
|
||||||
|
def __call__(self, deck_conf: aqt.deckconf.DeckConf) -> None:
|
||||||
|
for hook in self._hooks:
|
||||||
|
try:
|
||||||
|
hook(deck_conf)
|
||||||
|
except:
|
||||||
|
# if the hook fails, remove it
|
||||||
|
self._hooks.remove(hook)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
deck_conf_did_setup_ui_form = _DeckConfDidSetupUiFormHook()
|
||||||
|
|
||||||
|
|
||||||
class _DeckConfWillSaveConfigHook:
|
class _DeckConfWillSaveConfigHook:
|
||||||
"""Called before widget state is saved to config"""
|
"""Called before widget state is saved to config"""
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,11 @@ hooks = [
|
||||||
),
|
),
|
||||||
# Deck options
|
# Deck options
|
||||||
###################
|
###################
|
||||||
|
Hook(
|
||||||
|
name="deck_conf_did_setup_ui_form",
|
||||||
|
args=["deck_conf: aqt.deckconf.DeckConf"],
|
||||||
|
doc="Allows modifying or adding widgets in the deck options UI form",
|
||||||
|
),
|
||||||
Hook(
|
Hook(
|
||||||
name="deck_conf_will_show",
|
name="deck_conf_will_show",
|
||||||
args=["deck_conf: aqt.deckconf.DeckConf"],
|
args=["deck_conf: aqt.deckconf.DeckConf"],
|
||||||
|
|
Loading…
Reference in a new issue