From 621e634bb2cd9f868047f729bd61b8492f28a331 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sat, 15 Feb 2020 23:22:41 +0100 Subject: [PATCH] Add a convenience function for creating toolbar links Similar to aqt.editor.Editor.addButton --- qt/aqt/toolbar.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qt/aqt/toolbar.py b/qt/aqt/toolbar.py index 8f762e835..ae8608820 100644 --- a/qt/aqt/toolbar.py +++ b/qt/aqt/toolbar.py @@ -4,6 +4,8 @@ from __future__ import annotations +from typing import Dict + import aqt from anki.lang import _ from aqt import gui_hooks @@ -27,7 +29,7 @@ class Toolbar: def __init__(self, mw: aqt.AnkiQt, web: AnkiWebView) -> None: self.mw = mw self.web = web - self.link_handlers = { + self.link_handlers: Dict[str, Callable] = { "decks": self._deckLinkHandler, "study": self._studyLinkHandler, "add": self._addLinkHandler, @@ -46,6 +48,13 @@ class Toolbar: # Available links ###################################################################### + def addLink( + self, name: str, cmd: str, func: Callable, tip: str = "", + ): + self.link_handlers[cmd] = func + + return (cmd, name, tip) + def _centerLinks(self): links = [ ("decks", _("Decks"), _("Shortcut key: %s") % "D"),