Merge pull request #476 from Arthur-Milchior/hook_browser_init
Hook browser init
This commit is contained in:
commit
5cf7d6672e
@ -596,6 +596,7 @@ class Browser(QMainWindow):
|
|||||||
self.updateFont()
|
self.updateFont()
|
||||||
self.onUndoState(self.mw.form.actionUndo.isEnabled())
|
self.onUndoState(self.mw.form.actionUndo.isEnabled())
|
||||||
self.setupSearch()
|
self.setupSearch()
|
||||||
|
gui_hooks.browser_will_show(self)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def setupMenus(self) -> None:
|
def setupMenus(self) -> None:
|
||||||
|
@ -302,6 +302,30 @@ class _BrowserWillBuildTreeFilter:
|
|||||||
browser_will_build_tree = _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:
|
class _BrowserWillShowContextMenuHook:
|
||||||
_hooks: List[Callable[["aqt.browser.Browser", QMenu], None]] = []
|
_hooks: List[Callable[["aqt.browser.Browser", QMenu], None]] = []
|
||||||
|
|
||||||
|
@ -45,31 +45,6 @@ hooks = [
|
|||||||
content.table += "\n<div>my html</div>"
|
content.table += "\n<div>my html</div>"
|
||||||
""",
|
""",
|
||||||
),
|
),
|
||||||
Hook(
|
|
||||||
name="deck_browser_did_render",
|
|
||||||
args=["deck_browser: aqt.deckbrowser.DeckBrowser"],
|
|
||||||
doc="""Allow to update the deck browser window. E.g. change its title.""",
|
|
||||||
),
|
|
||||||
Hook(
|
|
||||||
name="deck_browser_will_render_content",
|
|
||||||
args=[
|
|
||||||
"deck_browser: aqt.deckbrowser.DeckBrowser",
|
|
||||||
"content: aqt.deckbrowser.DeckBrowserContent",
|
|
||||||
],
|
|
||||||
doc="""Used to modify HTML content sections in the deck browser body
|
|
||||||
|
|
||||||
'content' contains the sections of HTML content the deck browser body
|
|
||||||
will be updated with.
|
|
||||||
|
|
||||||
When modifying the content of a particular section, please make sure your
|
|
||||||
changes only perform the minimum required edits to make your add-on work.
|
|
||||||
You should avoid overwriting or interfering with existing data as much
|
|
||||||
as possible, instead opting to append your own changes, e.g.:
|
|
||||||
|
|
||||||
def on_deck_browser_will_render_content(deck_browser, content):
|
|
||||||
content.stats += "\n<div>my html</div>"
|
|
||||||
""",
|
|
||||||
),
|
|
||||||
Hook(
|
Hook(
|
||||||
name="reviewer_did_show_question",
|
name="reviewer_did_show_question",
|
||||||
args=["card: Card"],
|
args=["card: Card"],
|
||||||
@ -132,6 +107,33 @@ hooks = [
|
|||||||
legacy_hook="prepareQA",
|
legacy_hook="prepareQA",
|
||||||
doc="Can modify card text before review/preview.",
|
doc="Can modify card text before review/preview.",
|
||||||
),
|
),
|
||||||
|
# Deck browser
|
||||||
|
###################
|
||||||
|
Hook(
|
||||||
|
name="deck_browser_did_render",
|
||||||
|
args=["deck_browser: aqt.deckbrowser.DeckBrowser"],
|
||||||
|
doc="""Allow to update the deck browser window. E.g. change its title.""",
|
||||||
|
),
|
||||||
|
Hook(
|
||||||
|
name="deck_browser_will_render_content",
|
||||||
|
args=[
|
||||||
|
"deck_browser: aqt.deckbrowser.DeckBrowser",
|
||||||
|
"content: aqt.deckbrowser.DeckBrowserContent",
|
||||||
|
],
|
||||||
|
doc="""Used to modify HTML content sections in the deck browser body
|
||||||
|
|
||||||
|
'content' contains the sections of HTML content the deck browser body
|
||||||
|
will be updated with.
|
||||||
|
|
||||||
|
When modifying the content of a particular section, please make sure your
|
||||||
|
changes only perform the minimum required edits to make your add-on work.
|
||||||
|
You should avoid overwriting or interfering with existing data as much
|
||||||
|
as possible, instead opting to append your own changes, e.g.:
|
||||||
|
|
||||||
|
def on_deck_browser_will_render_content(deck_browser, content):
|
||||||
|
content.stats += "\n<div>my html</div>"
|
||||||
|
""",
|
||||||
|
),
|
||||||
# Deck options
|
# Deck options
|
||||||
###################
|
###################
|
||||||
Hook(
|
Hook(
|
||||||
@ -156,6 +158,7 @@ hooks = [
|
|||||||
),
|
),
|
||||||
# Browser
|
# Browser
|
||||||
###################
|
###################
|
||||||
|
Hook(name="browser_will_show", args=["browser: aqt.browser.Browser"]),
|
||||||
Hook(
|
Hook(
|
||||||
name="browser_menus_did_init",
|
name="browser_menus_did_init",
|
||||||
args=["browser: aqt.browser.Browser"],
|
args=["browser: aqt.browser.Browser"],
|
||||||
|
Loading…
Reference in New Issue
Block a user