From 8454e27efb6d3180b983c84ed354f599c905a82d Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Mon, 24 Feb 2020 15:47:48 +0100 Subject: [PATCH] Use a consistent function signature across load and save hooks --- qt/aqt/deckconf.py | 2 +- qt/aqt/gui_hooks.py | 20 +++++++++++--------- qt/tools/genhooks_gui.py | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/qt/aqt/deckconf.py b/qt/aqt/deckconf.py index 219632ebc..6527ff22b 100644 --- a/qt/aqt/deckconf.py +++ b/qt/aqt/deckconf.py @@ -221,7 +221,7 @@ class DeckConf(QDialog): f.replayQuestion.setChecked(c.get("replayq", True)) # description f.desc.setPlainText(self.deck["desc"]) - gui_hooks.deck_conf_did_load_config(self, self.conf) + gui_hooks.deck_conf_did_load_config(self, self.deck, self.conf) def onRestore(self): self.mw.progress.start() diff --git a/qt/aqt/gui_hooks.py b/qt/aqt/gui_hooks.py index f019a803f..de0ec671d 100644 --- a/qt/aqt/gui_hooks.py +++ b/qt/aqt/gui_hooks.py @@ -521,20 +521,22 @@ deck_browser_will_show_options_menu = _DeckBrowserWillShowOptionsMenuHook() class _DeckConfDidLoadConfigHook: """Called once widget state has been set from deck config""" - _hooks: List[Callable[["aqt.deckconf.DeckConf", Any], None]] = [] + _hooks: List[Callable[["aqt.deckconf.DeckConf", Any, Any], None]] = [] - def append(self, cb: Callable[["aqt.deckconf.DeckConf", Any], None]) -> None: - """(deck_conf: aqt.deckconf.DeckConf, config: Any)""" + def append(self, cb: Callable[["aqt.deckconf.DeckConf", Any, Any], None]) -> None: + """(deck_conf: aqt.deckconf.DeckConf, deck: Any, config: Any)""" self._hooks.append(cb) - def remove(self, cb: Callable[["aqt.deckconf.DeckConf", Any], None]) -> None: + def remove(self, cb: Callable[["aqt.deckconf.DeckConf", Any, Any], None]) -> None: if cb in self._hooks: self._hooks.remove(cb) - def __call__(self, deck_conf: aqt.deckconf.DeckConf, config: Any) -> None: + def __call__( + self, deck_conf: aqt.deckconf.DeckConf, deck: Any, config: Any + ) -> None: for hook in self._hooks: try: - hook(deck_conf, config) + hook(deck_conf, deck, config) except: # if the hook fails, remove it self._hooks.remove(hook) @@ -576,7 +578,7 @@ class _DeckConfWillSaveConfigHook: _hooks: List[Callable[["aqt.deckconf.DeckConf", Any, Any], None]] = [] def append(self, cb: Callable[["aqt.deckconf.DeckConf", Any, Any], None]) -> None: - """(deck_conf: aqt.deckconf.DeckConf, config: Any, deck: Any)""" + """(deck_conf: aqt.deckconf.DeckConf, deck: Any, config: Any)""" self._hooks.append(cb) def remove(self, cb: Callable[["aqt.deckconf.DeckConf", Any, Any], None]) -> None: @@ -584,11 +586,11 @@ class _DeckConfWillSaveConfigHook: self._hooks.remove(cb) def __call__( - self, deck_conf: aqt.deckconf.DeckConf, config: Any, deck: Any + self, deck_conf: aqt.deckconf.DeckConf, deck: Any, config: Any ) -> None: for hook in self._hooks: try: - hook(deck_conf, config, deck) + hook(deck_conf, deck, config) except: # if the hook fails, remove it self._hooks.remove(hook) diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index c7d959f51..b92d0a969 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -135,12 +135,12 @@ hooks = [ ), Hook( name="deck_conf_did_load_config", - args=["deck_conf: aqt.deckconf.DeckConf", "config: Any"], + args=["deck_conf: aqt.deckconf.DeckConf", "deck: Any", "config: Any"], doc="Called once widget state has been set from deck config", ), Hook( name="deck_conf_will_save_config", - args=["deck_conf: aqt.deckconf.DeckConf", "config: Any", "deck: Any"], + args=["deck_conf: aqt.deckconf.DeckConf", "deck: Any", "config: Any"], doc="Called before widget state is saved to config", ), # Browser