Fixed bug where enabled opt is not respected

This commit is contained in:
Daniel Lidstrom 2020-12-21 19:01:54 -08:00
parent 4e8a609375
commit 4618c705e2

View File

@ -213,7 +213,8 @@ class WidgetParameterItem(ParameterItem):
def updateDefaultBtn(self): def updateDefaultBtn(self):
## enable/disable default btn ## enable/disable default btn
self.defaultBtn.setEnabled(not self.param.valueIsDefault() and self.param.writable()) self.defaultBtn.setEnabled(
not self.param.valueIsDefault() and self.param.opts['enabled'] and self.param.writable())
# hide / show # hide / show
self.defaultBtn.setVisible(self.param.hasDefault() and not self.param.readonly()) self.defaultBtn.setVisible(self.param.hasDefault() and not self.param.readonly())
@ -301,13 +302,17 @@ class WidgetParameterItem(ParameterItem):
"""Called when any options are changed that are not """Called when any options are changed that are not
name, value, default, or limits""" name, value, default, or limits"""
ParameterItem.optsChanged(self, param, opts) ParameterItem.optsChanged(self, param, opts)
if 'enabled' in opts:
self.updateDefaultBtn()
self.widget.setEnabled(opts['enabled'])
if 'readonly' in opts: if 'readonly' in opts:
self.updateDefaultBtn() self.updateDefaultBtn()
if hasattr(self.widget, 'setReadOnly'): if hasattr(self.widget, 'setReadOnly'):
self.widget.setReadOnly(opts['readonly']) self.widget.setReadOnly(opts['readonly'])
else: else:
self.widget.setEnabled(not opts['readonly']) self.widget.setEnabled(self.param.opts['enabled'] and not opts['readonly'])
if 'tip' in opts: if 'tip' in opts:
self.widget.setToolTip(opts['tip']) self.widget.setToolTip(opts['tip'])
@ -415,7 +420,9 @@ class GroupParameterItem(ParameterItem):
self.addItem.depth = self.depth + 1 self.addItem.depth = self.depth + 1
ParameterItem.addChild(self, self.addItem) ParameterItem.addChild(self, self.addItem)
self.addItem.setSizeHint(0, self.addWidgetBox.sizeHint()) self.addItem.setSizeHint(0, self.addWidgetBox.sizeHint())
self.optsChanged(self.param, self.param.opts)
def updateDepth(self, depth): def updateDepth(self, depth):
## Change item's appearance based on its depth in the tree ## Change item's appearance based on its depth in the tree
## This allows highest-level groups to be displayed more prominently. ## This allows highest-level groups to be displayed more prominently.
@ -474,7 +481,10 @@ class GroupParameterItem(ParameterItem):
if 'addList' in opts: if 'addList' in opts:
self.updateAddList() self.updateAddList()
if 'enabled' in opts and hasattr(self, 'addWidget'):
self.addWidget.setEnabled(opts['enabled'])
def updateAddList(self): def updateAddList(self):
self.addWidget.blockSignals(True) self.addWidget.blockSignals(True)
try: try:
@ -632,6 +642,7 @@ class ActionParameterItem(ParameterItem):
self.layout.addStretch() self.layout.addStretch()
self.button.clicked.connect(self.buttonClicked) self.button.clicked.connect(self.buttonClicked)
self.titleChanged() self.titleChanged()
self.optsChanged(self.param, self.param.opts)
def treeWidgetChanged(self): def treeWidgetChanged(self):
ParameterItem.treeWidgetChanged(self) ParameterItem.treeWidgetChanged(self)
@ -645,7 +656,13 @@ class ActionParameterItem(ParameterItem):
def titleChanged(self): def titleChanged(self):
self.button.setText(self.param.title()) self.button.setText(self.param.title())
self.setSizeHint(0, self.button.sizeHint()) self.setSizeHint(0, self.button.sizeHint())
def optsChanged(self, param, opts):
ParameterItem.optsChanged(self, param, opts)
if 'enabled' in opts:
self.button.setEnabled(opts['enabled'])
def buttonClicked(self): def buttonClicked(self):
self.param.activate() self.param.activate()