Update signature of main_window_will_require_reset hook

This commit is contained in:
Henrik Giesel 2020-08-09 13:22:23 +02:00
parent dd515e65e7
commit f1286a0ce3
2 changed files with 7 additions and 7 deletions

View file

@ -1745,23 +1745,23 @@ class _MainWindowWillRequireResetFilter:
from the main window. from the main window.
""" """
_hooks: List[Callable[[bool], bool]] = [] _hooks: List[Callable[[bool, str, Optional[Any]], bool]] = []
def append(self, cb: Callable[[bool], bool]) -> None: def append(self, cb: Callable[[bool, str, Optional[Any]], bool]) -> None:
"""(will_reset: bool)""" """(will_reset: bool, reason: str, context: Optional[Any])"""
self._hooks.append(cb) self._hooks.append(cb)
def remove(self, cb: Callable[[bool], bool]) -> None: def remove(self, cb: Callable[[bool, str, Optional[Any]], bool]) -> None:
if cb in self._hooks: if cb in self._hooks:
self._hooks.remove(cb) self._hooks.remove(cb)
def count(self) -> int: def count(self) -> int:
return len(self._hooks) return len(self._hooks)
def __call__(self, will_reset: bool) -> bool: def __call__(self, will_reset: bool, reason: str, context: Optional[Any]) -> bool:
for filter in self._hooks: for filter in self._hooks:
try: try:
will_reset = filter(will_reset) will_reset = filter(will_reset, reason, context)
except: except:
# if the hook fails, remove it # if the hook fails, remove it
self._hooks.remove(filter) self._hooks.remove(filter)

View file

@ -442,7 +442,7 @@ hooks = [
), ),
Hook( Hook(
name="main_window_will_require_reset", name="main_window_will_require_reset",
args=["will_reset: bool"], args=["will_reset: bool", "reason: str", "context: Optional[Any]"],
return_type="bool", return_type="bool",
doc="""Executed before the main window will require a reset doc="""Executed before the main window will require a reset