mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Merge pull request #201 from glutanimate/editor-addbutton-convenience-function
Convenience function to assign function a button, bridge cmd & shortcut
This commit is contained in:
commit
3b9ac82a32
1 changed files with 13 additions and 0 deletions
|
@ -125,6 +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, func, tip="", label="",
|
||||
id=None, toggleable=False, keys=None):
|
||||
"""Assign func to bridge cmd, register shortcut, return button"""
|
||||
if cmd not in self._links:
|
||||
self._links[cmd] = func
|
||||
if keys:
|
||||
QShortcut(QKeySequence(keys), self.widget,
|
||||
activated = lambda s=self: func(s))
|
||||
btn = self._addButton(icon, cmd, tip=tip, label=label,
|
||||
id=id, toggleable=toggleable)
|
||||
return btn
|
||||
|
||||
def _addButton(self, icon, cmd, tip="", label="", id=None, toggleable=False):
|
||||
if icon:
|
||||
if os.path.isabs(icon):
|
||||
|
|
Loading…
Reference in a new issue