add a flag to keep editor buttons enabled when no field selected

This commit is contained in:
Damien Elmes 2017-12-08 21:06:16 +10:00
parent 774c19e83e
commit fccfdef73d
2 changed files with 10 additions and 6 deletions

View File

@ -128,7 +128,7 @@ class Editor:
def addButton(self, icon, cmd, func, tip="", label="", def addButton(self, icon, cmd, func, tip="", label="",
id=None, toggleable=False, keys=None): id=None, toggleable=False, keys=None, disables=True):
"""Assign func to bridge cmd, register shortcut, return button""" """Assign func to bridge cmd, register shortcut, return button"""
if cmd not in self._links: if cmd not in self._links:
self._links[cmd] = func self._links[cmd] = func
@ -136,10 +136,11 @@ class Editor:
QShortcut(QKeySequence(keys), self.widget, QShortcut(QKeySequence(keys), self.widget,
activated = lambda s=self: func(s)) activated = lambda s=self: func(s))
btn = self._addButton(icon, cmd, tip=tip, label=label, btn = self._addButton(icon, cmd, tip=tip, label=label,
id=id, toggleable=toggleable) id=id, toggleable=toggleable, disables=disables)
return btn return btn
def _addButton(self, icon, cmd, tip="", label="", id=None, toggleable=False): def _addButton(self, icon, cmd, tip="", label="", id=None, toggleable=False,
disables=True):
if icon: if icon:
if os.path.isabs(icon): if os.path.isabs(icon):
iconstr = self.resourceToData(icon) iconstr = self.resourceToData(icon)
@ -161,11 +162,14 @@ class Editor:
else: else:
toggleScript = '' toggleScript = ''
tip = shortcut(tip) tip = shortcut(tip)
return ('''<button tabindex=-1 {id} class=linkb type="button" title="{tip}"''' theclass = "linkb"
if not disables:
theclass += " perm"
return ('''<button tabindex=-1 {id} class="{theclass}" type="button" title="{tip}"'''
''' onclick="pycmd('{cmd}');{togglesc}return false;">''' ''' onclick="pycmd('{cmd}');{togglesc}return false;">'''
'''{imgelm}{labelelm}</button>'''.format( '''{imgelm}{labelelm}</button>'''.format(
imgelm=imgelm, cmd=cmd, tip=tip, labelelm=labelelm, id=idstr, imgelm=imgelm, cmd=cmd, tip=tip, labelelm=labelelm, id=idstr,
togglesc=toggleScript) togglesc=toggleScript, theclass=theclass)
) )
def setupShortcuts(self): def setupShortcuts(self):

View File

@ -217,7 +217,7 @@ function wrappedExceptForWhitespace(text, front, back) {
} }
function disableButtons() { function disableButtons() {
$("button.linkb").prop("disabled", true); $("button.linkb:not(.perm)").prop("disabled", true);
} }
function enableButtons() { function enableButtons() {