Update 'top_toolbar_did_init_links' hook
This commit is contained in:
parent
e13fee5aa3
commit
dfefd67508
@ -1295,25 +1295,28 @@ style_did_init = _StyleDidInitFilter()
|
||||
|
||||
|
||||
class _TopToolbarDidInitLinksHook:
|
||||
_hooks: List[
|
||||
Callable[[List[Tuple[str, str, str]], "aqt.toolbar.Toolbar"], None]
|
||||
] = []
|
||||
"""Used to modify or add links in the top toolbar of Anki's main window
|
||||
|
||||
'links' is a list of HTML link elements. Add-ons can generate their own links
|
||||
by using aqt.toolbar.Toolbar.create_link. Links created in that way can then be
|
||||
appended to the link list, e.g.:
|
||||
|
||||
def append(
|
||||
self, cb: Callable[[List[Tuple[str, str, str]], "aqt.toolbar.Toolbar"], None]
|
||||
) -> None:
|
||||
"""(links: List[Tuple[str, str, str]], top_toolbar: aqt.toolbar.Toolbar)"""
|
||||
def on_top_toolbar_did_init_links(links, toolbar):
|
||||
my_link = toolbar.create_link(...)
|
||||
links.append(my_link)
|
||||
"""
|
||||
|
||||
_hooks: List[Callable[[List[str], "aqt.toolbar.Toolbar"], None]] = []
|
||||
|
||||
def append(self, cb: Callable[[List[str], "aqt.toolbar.Toolbar"], None]) -> None:
|
||||
"""(links: List[str], top_toolbar: aqt.toolbar.Toolbar)"""
|
||||
self._hooks.append(cb)
|
||||
|
||||
def remove(
|
||||
self, cb: Callable[[List[Tuple[str, str, str]], "aqt.toolbar.Toolbar"], None]
|
||||
) -> None:
|
||||
def remove(self, cb: Callable[[List[str], "aqt.toolbar.Toolbar"], None]) -> None:
|
||||
if cb in self._hooks:
|
||||
self._hooks.remove(cb)
|
||||
|
||||
def __call__(
|
||||
self, links: List[Tuple[str, str, str]], top_toolbar: aqt.toolbar.Toolbar
|
||||
) -> None:
|
||||
def __call__(self, links: List[str], top_toolbar: aqt.toolbar.Toolbar) -> None:
|
||||
for hook in self._hooks:
|
||||
try:
|
||||
hook(links, top_toolbar)
|
||||
|
@ -109,7 +109,7 @@ class Toolbar:
|
||||
|
||||
links.append(self._create_sync_link())
|
||||
|
||||
# gui_hooks.top_toolbar_did_init_links(links, self)
|
||||
gui_hooks.top_toolbar_did_init_links(links, self)
|
||||
|
||||
return "\n".join(links)
|
||||
|
||||
|
@ -308,7 +308,17 @@ hooks = [
|
||||
),
|
||||
Hook(
|
||||
name="top_toolbar_did_init_links",
|
||||
args=["links: List[Tuple[str, str, str]]", "top_toolbar: aqt.toolbar.Toolbar"],
|
||||
args=["links: List[str]", "top_toolbar: aqt.toolbar.Toolbar"],
|
||||
doc="""Used to modify or add links in the top toolbar of Anki's main window
|
||||
|
||||
'links' is a list of HTML link elements. Add-ons can generate their own links
|
||||
by using aqt.toolbar.Toolbar.create_link. Links created in that way can then be
|
||||
appended to the link list, e.g.:
|
||||
|
||||
def on_top_toolbar_did_init_links(links, toolbar):
|
||||
my_link = toolbar.create_link(...)
|
||||
links.append(my_link)
|
||||
""",
|
||||
),
|
||||
Hook(
|
||||
name="media_sync_did_progress", args=["entry: aqt.mediasync.LogEntryWithTime"],
|
||||
|
Loading…
Reference in New Issue
Block a user