From d7bf86552435b994136108ae2bd7202af394daae Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Wed, 23 Aug 2017 23:48:08 +0200 Subject: [PATCH] Reintroduce button labels for the Editor Anki 2.0.x provided add-on authors with the ability to define labels that could be used instead of icons. This commit reintroduces that ability and makes the use of an icon optional. --- aqt/editor.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index e96274fa4..05056f635 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -125,11 +125,19 @@ class Editor: data64 = b''.join(base64.encodestring(data).splitlines()) return 'data:%s;base64,%s' % (mime, data64.decode('ascii')) - def _addButton(self, icon, cmd, tip="", id=None, toggleable=False): - if os.path.isabs(icon): - iconstr = self.resourceToData(icon) + def _addButton(self, icon, cmd, tip="", label="", id=None, toggleable=False): + if icon: + if os.path.isabs(icon): + iconstr = self.resourceToData(icon) + else: + iconstr = "/_anki/imgs/{}.png".format(icon) + imgelm = ''''''.format(iconstr) else: - iconstr = "/_anki/imgs/{}.png".format(icon) + imgelm = "" + if label or not imgelm: + labelelm = '''{}'''.format(label or cmd) + else: + labelelm = "" if id: idstr = 'id={}'.format(id) else: @@ -139,8 +147,12 @@ class Editor: else: toggleScript = '' tip = shortcut(tip) - return ''''''.format(icon=iconstr, cmd=cmd, tip=tip, id=idstr, togglesc=toggleScript) + return (''''''.format( + imgelm=imgelm, cmd=cmd, tip=tip, labelelm=labelelm, id=idstr, + togglesc=toggleScript) + ) def setupShortcuts(self): cuts = [