Fixed Parameter 'readonly' option for bool, color, and text parameter types

This commit is contained in:
Luke Campagnola 2014-05-04 12:24:46 -04:00
parent f18f2b11c8
commit de022be634
3 changed files with 26 additions and 0 deletions

View File

@ -86,6 +86,7 @@ pyqtgraph-0.9.9 [unreleased]
- Fixed TableWidget append / sort issues
- Fixed AxisItem not resizing text area when setTicks() is used
- Removed a few cyclic references
- Fixed Parameter 'readonly' option for bool, color, and text parameter types
pyqtgraph-0.9.8 2013-11-24

View File

@ -125,6 +125,7 @@ class WidgetParameterItem(ParameterItem):
w.sigChanged = w.toggled
w.value = w.isChecked
w.setValue = w.setChecked
w.setEnabled(not opts.get('readonly', False))
self.hideWidget = False
elif t == 'str':
w = QtGui.QLineEdit()
@ -140,6 +141,7 @@ class WidgetParameterItem(ParameterItem):
w.setValue = w.setColor
self.hideWidget = False
w.setFlat(True)
w.setEnabled(not opts.get('readonly', False))
elif t == 'colormap':
from ..widgets.GradientWidget import GradientWidget ## need this here to avoid import loop
w = GradientWidget(orientation='bottom')
@ -274,6 +276,8 @@ class WidgetParameterItem(ParameterItem):
if 'readonly' in opts:
self.updateDefaultBtn()
if isinstance(self.widget, (QtGui.QCheckBox,ColorButton)):
w.setEnabled(not opts['readonly'])
## If widget is a SpinBox, pass options straight through
if isinstance(self.widget, SpinBox):
@ -281,6 +285,9 @@ class WidgetParameterItem(ParameterItem):
opts['suffix'] = opts['units']
self.widget.setOpts(**opts)
self.updateDisplayLabel()
class EventProxy(QtCore.QObject):
def __init__(self, qobj, callback):

View File

@ -0,0 +1,18 @@
import pyqtgraph.parametertree as pt
import pyqtgraph as pg
app = pg.mkQApp()
def test_opts():
paramSpec = [
dict(name='bool', type='bool', readonly=True),
dict(name='color', type='color', readonly=True),
]
param = pt.Parameter.create(name='params', type='group', children=paramSpec)
tree = pt.ParameterTree()
tree.setParameters(param)
assert param.param('bool').items.keys()[0].widget.isEnabled() is False
assert param.param('color').items.keys()[0].widget.isEnabled() is False