From de022be634677cc20f1e94f6b662de1ccb5fbd57 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sun, 4 May 2014 12:24:46 -0400 Subject: [PATCH] Fixed Parameter 'readonly' option for bool, color, and text parameter types --- CHANGELOG | 1 + pyqtgraph/parametertree/parameterTypes.py | 7 +++++++ .../parametertree/tests/test_parametertypes.py | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 pyqtgraph/parametertree/tests/test_parametertypes.py diff --git a/CHANGELOG b/CHANGELOG index 6ae13037..e0723ca5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/pyqtgraph/parametertree/parameterTypes.py b/pyqtgraph/parametertree/parameterTypes.py index 53abe429..62e935fd 100644 --- a/pyqtgraph/parametertree/parameterTypes.py +++ b/pyqtgraph/parametertree/parameterTypes.py @@ -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): diff --git a/pyqtgraph/parametertree/tests/test_parametertypes.py b/pyqtgraph/parametertree/tests/test_parametertypes.py new file mode 100644 index 00000000..c7cd2cb3 --- /dev/null +++ b/pyqtgraph/parametertree/tests/test_parametertypes.py @@ -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 + +