diff --git a/qt/aqt/gui_hooks.py b/qt/aqt/gui_hooks.py index 5fd834eea..b5a9ca35c 100644 --- a/qt/aqt/gui_hooks.py +++ b/qt/aqt/gui_hooks.py @@ -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) diff --git a/qt/aqt/toolbar.py b/qt/aqt/toolbar.py index c72faf896..ec5c123d7 100644 --- a/qt/aqt/toolbar.py +++ b/qt/aqt/toolbar.py @@ -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) diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index cc49a96f9..17e55ea25 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -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"],