browser_did_init

This commit is contained in:
Arthur Milchior 2020-02-29 17:02:51 +01:00
parent f81134830b
commit 047e027e01
3 changed files with 26 additions and 0 deletions

View File

@ -596,6 +596,7 @@ class Browser(QMainWindow):
self.updateFont()
self.onUndoState(self.mw.form.actionUndo.isEnabled())
self.setupSearch()
gui_hooks.browser_will_show(self)
self.show()
def setupMenus(self) -> None:

View File

@ -302,6 +302,30 @@ class _BrowserWillBuildTreeFilter:
browser_will_build_tree = _BrowserWillBuildTreeFilter()
class _BrowserWillShowHook:
_hooks: List[Callable[["aqt.browser.Browser"], None]] = []
def append(self, cb: Callable[["aqt.browser.Browser"], None]) -> None:
"""(browser: aqt.browser.Browser)"""
self._hooks.append(cb)
def remove(self, cb: Callable[["aqt.browser.Browser"], None]) -> None:
if cb in self._hooks:
self._hooks.remove(cb)
def __call__(self, browser: aqt.browser.Browser) -> None:
for hook in self._hooks:
try:
hook(browser)
except:
# if the hook fails, remove it
self._hooks.remove(hook)
raise
browser_will_show = _BrowserWillShowHook()
class _BrowserWillShowContextMenuHook:
_hooks: List[Callable[["aqt.browser.Browser", QMenu], None]] = []

View File

@ -147,6 +147,7 @@ hooks = [
),
# Browser
###################
Hook(name="browser_will_show", args=["browser: aqt.browser.Browser"]),
Hook(
name="browser_menus_did_init",
args=["browser: aqt.browser.Browser"],