Merge pull request #1954 from ntjess/deprecate-values-opt

Deprecate `values` opt for list parameter
This commit is contained in:
Ogi Moore 2021-09-07 20:57:27 -07:00 committed by GitHub
commit 2a66460afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 23 additions and 20 deletions

View File

@ -115,9 +115,9 @@ children = [
dict(name='enableExperimental', type='bool', value=pg.getConfigOption('enableExperimental')), dict(name='enableExperimental', type='bool', value=pg.getConfigOption('enableExperimental')),
dict(name='pen', type='pen', value=default_pen), dict(name='pen', type='pen', value=default_pen),
dict(name='antialias', type='bool', value=pg.getConfigOption('antialias')), dict(name='antialias', type='bool', value=pg.getConfigOption('antialias')),
dict(name='connect', type='list', values=['all', 'pairs', 'finite', 'array'], value='all'), dict(name='connect', type='list', limits=['all', 'pairs', 'finite', 'array'], value='all'),
dict(name='skipFiniteCheck', type='bool', value=False), dict(name='skipFiniteCheck', type='bool', value=False),
dict(name='plotMethod', title='Plot Method', type='list', values=['pyqtgraph', 'drawPolyline', 'drawLines']) dict(name='plotMethod', title='Plot Method', type='list', limits=['pyqtgraph', 'drawPolyline', 'drawLines'])
] ]
params = ptree.Parameter.create(name='Parameters', type='group', children=children) params = ptree.Parameter.create(name='Parameters', type='group', children=children)

View File

@ -26,7 +26,7 @@ param = ptree.Parameter.create(name=translate('ScatterPlot', 'Parameters'), type
dict(name='randomize', title=translate('ScatterPlot', 'Randomize: '), type='bool', value=False), dict(name='randomize', title=translate('ScatterPlot', 'Randomize: '), type='bool', value=False),
dict(name='pxMode', title='pxMode: ', type='bool', value=True), dict(name='pxMode', title='pxMode: ', type='bool', value=True),
dict(name='useCache', title='useCache: ', type='bool', value=True), dict(name='useCache', title='useCache: ', type='bool', value=True),
dict(name='mode', title=translate('ScatterPlot', 'Mode: '), type='list', values={translate('ScatterPlot', 'New Item'): 'newItem', translate('ScatterPlot', 'Reuse Item'): 'reuseItem', translate('ScatterPlot', 'Simulate Pan/Zoom'): 'panZoom', translate('ScatterPlot', 'Simulate Hover'): 'hover'}, value='reuseItem'), dict(name='mode', title=translate('ScatterPlot', 'Mode: '), type='list', limits={translate('ScatterPlot', 'New Item'): 'newItem', translate('ScatterPlot', 'Reuse Item'): 'reuseItem', translate('ScatterPlot', 'Simulate Pan/Zoom'): 'panZoom', translate('ScatterPlot', 'Simulate Hover'): 'hover'}, value='reuseItem'),
]) ])
for c in param.children(): for c in param.children():
c.setDefault(c.value()) c.setDefault(c.value())

View File

@ -66,8 +66,8 @@ params = [
{'name': 'Integer', 'type': 'int', 'value': 10}, {'name': 'Integer', 'type': 'int', 'value': 10},
{'name': 'Float', 'type': 'float', 'value': 10.5, 'step': 0.1, 'finite': False}, {'name': 'Float', 'type': 'float', 'value': 10.5, 'step': 0.1, 'finite': False},
{'name': 'String', 'type': 'str', 'value': "hi", 'tip': 'Well hello'}, {'name': 'String', 'type': 'str', 'value': "hi", 'tip': 'Well hello'},
{'name': 'List', 'type': 'list', 'values': [1,2,3], 'value': 2}, {'name': 'List', 'type': 'list', 'limits': [1,2,3], 'value': 2},
{'name': 'Named List', 'type': 'list', 'values': {"one": 1, "two": "twosies", "three": [3,3,3]}, 'value': 2}, {'name': 'Named List', 'type': 'list', 'limits': {"one": 1, "two": "twosies", "three": [3,3,3]}, 'value': 2},
{'name': 'Boolean', 'type': 'bool', 'value': True, 'tip': "This is a checkbox"}, {'name': 'Boolean', 'type': 'bool', 'value': True, 'tip': "This is a checkbox"},
{'name': 'Color', 'type': 'color', 'value': "#FF0", 'tip': "This is a color button"}, {'name': 'Color', 'type': 'color', 'value': "#FF0", 'tip': "This is a color button"},
{'name': 'Gradient', 'type': 'colormap'}, {'name': 'Gradient', 'type': 'colormap'},

View File

@ -27,10 +27,10 @@ class RelativityGUI(QtGui.QWidget):
self.objectGroup = ObjectGroupParam() self.objectGroup = ObjectGroupParam()
self.params = Parameter.create(name='params', type='group', children=[ self.params = Parameter.create(name='params', type='group', children=[
dict(name='Load Preset..', type='list', values=[]), dict(name='Load Preset..', type='list', limits=[]),
#dict(name='Unit System', type='list', values=['', 'MKS']), #dict(name='Unit System', type='list', limits=['', 'MKS']),
dict(name='Duration', type='float', value=10.0, step=0.1, limits=[0.1, None]), dict(name='Duration', type='float', value=10.0, step=0.1, limits=[0.1, None]),
dict(name='Reference Frame', type='list', values=[]), dict(name='Reference Frame', type='list', limits=[]),
dict(name='Animate', type='bool', value=True), dict(name='Animate', type='bool', value=True),
dict(name='Animation Speed', type='float', value=1.0, dec=True, step=0.1, limits=[0.0001, None]), dict(name='Animation Speed', type='float', value=1.0, dec=True, step=0.1, limits=[0.0001, None]),
dict(name='Recalculate Worldlines', type='action'), dict(name='Recalculate Worldlines', type='action'),

View File

@ -15,9 +15,9 @@ class CSVExporter(Exporter):
def __init__(self, item): def __init__(self, item):
Exporter.__init__(self, item) Exporter.__init__(self, item)
self.params = Parameter(name='params', type='group', children=[ self.params = Parameter(name='params', type='group', children=[
{'name': 'separator', 'title': translate("Exporter", 'separator'), 'type': 'list', 'value': 'comma', 'values': ['comma', 'tab']}, {'name': 'separator', 'title': translate("Exporter", 'separator'), 'type': 'list', 'value': 'comma', 'limits': ['comma', 'tab']},
{'name': 'precision', 'title': translate("Exporter", 'precision'), 'type': 'int', 'value': 10, 'limits': [0, None]}, {'name': 'precision', 'title': translate("Exporter", 'precision'), 'type': 'int', 'value': 10, 'limits': [0, None]},
{'name': 'columnMode', 'title': translate("Exporter", 'columnMode'), 'type': 'list', 'values': ['(x,y) per plot', '(x,y,y,y) for all plots']} {'name': 'columnMode', 'title': translate("Exporter", 'columnMode'), 'type': 'list', 'limits': ['(x,y) per plot', '(x,y,y,y) for all plots']}
]) ])
def parameters(self): def parameters(self):

View File

@ -26,7 +26,7 @@ class HDF5Exporter(Exporter):
self.params = Parameter(name='params', type='group', children=[ self.params = Parameter(name='params', type='group', children=[
{'name': 'Name', 'title': translate("Exporter", 'Name'), 'type': 'str', 'value': 'Export', }, {'name': 'Name', 'title': translate("Exporter", 'Name'), 'type': 'str', 'value': 'Export', },
{'name': 'columnMode', 'title': translate("Exporter", 'columnMode'), 'type': 'list', {'name': 'columnMode', 'title': translate("Exporter", 'columnMode'), 'type': 'list',
'values': ['(x,y) per plot', '(x,y,y,y) for all plots']}, 'limits': ['(x,y) per plot', '(x,y,y,y) for all plots']},
]) ])
def parameters(self): def parameters(self):

View File

@ -1,3 +1,4 @@
import warnings
from collections import OrderedDict from collections import OrderedDict
from .basetypes import WidgetParameterItem from .basetypes import WidgetParameterItem
@ -74,7 +75,7 @@ class ListParameter(Parameter):
In addition to the generic :class:`~pyqtgraph.parametertree.Parameter` In addition to the generic :class:`~pyqtgraph.parametertree.Parameter`
options, this parameter type accepts a ``limits`` argument specifying the options, this parameter type accepts a ``limits`` argument specifying the
list of allowed values. ``values`` is an alias and may be used instead. list of allowed values.
The values may generally be of any data type, as long as they can be The values may generally be of any data type, as long as they can be
represented as a string. If the string representation provided is represented as a string. If the string representation provided is
@ -90,6 +91,8 @@ class ListParameter(Parameter):
# Parameter uses 'limits' option to define the set of allowed values # Parameter uses 'limits' option to define the set of allowed values
if 'values' in opts: if 'values' in opts:
warnings.warn('Using "values" to set limits is deprecated. Use "limits" instead.',
DeprecationWarning, stacklevel=2)
opts['limits'] = opts['values'] opts['limits'] = opts['values']
if opts.get('limits', None) is None: if opts.get('limits', None) is None:
opts['limits'] = [] opts['limits'] = []

View File

@ -194,10 +194,10 @@ class RangeColorMapItem(ptree.types.SimpleParameter):
ptree.types.SimpleParameter.__init__(self, ptree.types.SimpleParameter.__init__(self,
name=name, autoIncrementName=True, type='colormap', removable=True, renamable=True, name=name, autoIncrementName=True, type='colormap', removable=True, renamable=True,
children=[ children=[
#dict(name="Field", type='list', value=name, values=fields), #dict(name="Field", type='list', value=name, limits=fields),
dict(name='Min', type='float', value=0.0, suffix=units, siPrefix=True), dict(name='Min', type='float', value=0.0, suffix=units, siPrefix=True),
dict(name='Max', type='float', value=1.0, suffix=units, siPrefix=True), dict(name='Max', type='float', value=1.0, suffix=units, siPrefix=True),
dict(name='Operation', type='list', value='Overlay', values=['Overlay', 'Add', 'Multiply', 'Set']), dict(name='Operation', type='list', value='Overlay', limits=['Overlay', 'Add', 'Multiply', 'Set']),
dict(name='Channels..', type='group', expanded=False, children=[ dict(name='Channels..', type='group', expanded=False, children=[
dict(name='Red', type='bool', value=True), dict(name='Red', type='bool', value=True),
dict(name='Green', type='bool', value=True), dict(name='Green', type='bool', value=True),
@ -240,7 +240,7 @@ class EnumColorMapItem(ptree.types.GroupParameter):
name=name, autoIncrementName=True, removable=True, renamable=True, name=name, autoIncrementName=True, removable=True, renamable=True,
children=[ children=[
dict(name='Values', type='group', children=childs), dict(name='Values', type='group', children=childs),
dict(name='Operation', type='list', value='Overlay', values=['Overlay', 'Add', 'Multiply', 'Set']), dict(name='Operation', type='list', value='Overlay', limits=['Overlay', 'Add', 'Multiply', 'Set']),
dict(name='Channels..', type='group', expanded=False, children=[ dict(name='Channels..', type='group', expanded=False, children=[
dict(name='Red', type='bool', value=True), dict(name='Red', type='bool', value=True),
dict(name='Green', type='bool', value=True), dict(name='Green', type='bool', value=True),

View File

@ -130,7 +130,7 @@ class RangeFilterItem(ptree.types.SimpleParameter):
ptree.types.SimpleParameter.__init__(self, ptree.types.SimpleParameter.__init__(self,
name=name, autoIncrementName=True, type='bool', value=True, removable=True, renamable=True, name=name, autoIncrementName=True, type='bool', value=True, removable=True, renamable=True,
children=[ children=[
#dict(name="Field", type='list', value=name, values=fields), #dict(name="Field", type='list', value=name, limits=fields),
dict(name='Min', type='float', value=0.0, suffix=units, siPrefix=True), dict(name='Min', type='float', value=0.0, suffix=units, siPrefix=True),
dict(name='Max', type='float', value=1.0, suffix=units, siPrefix=True), dict(name='Max', type='float', value=1.0, suffix=units, siPrefix=True),
]) ])

View File

@ -31,8 +31,8 @@ def test_types():
dict(name='float', type='float'), dict(name='float', type='float'),
dict(name='int', type='int'), dict(name='int', type='int'),
dict(name='str', type='str'), dict(name='str', type='str'),
dict(name='list', type='list', values=['x','y','z']), dict(name='list', type='list', limits=['x','y','z']),
dict(name='dict', type='list', values={'x':1, 'y':3, 'z':7}), dict(name='dict', type='list', limits={'x':1, 'y':3, 'z':7}),
dict(name='bool', type='bool'), dict(name='bool', type='bool'),
dict(name='color', type='color'), dict(name='color', type='color'),
] ]
@ -129,8 +129,8 @@ def test_limits_enforcement():
p = pt.Parameter.create(name='params', type='group', children=[ p = pt.Parameter.create(name='params', type='group', children=[
dict(name='float', type='float', limits=[0, 1]), dict(name='float', type='float', limits=[0, 1]),
dict(name='int', type='int', bounds=[0, 1]), dict(name='int', type='int', bounds=[0, 1]),
dict(name='list', type='list', values=['x', 'y']), dict(name='list', type='list', limits=['x', 'y']),
dict(name='dict', type='list', values={'x': 1, 'y': 2}), dict(name='dict', type='list', limits={'x': 1, 'y': 2}),
]) ])
t = pt.ParameterTree() t = pt.ParameterTree()
t.setParameters(p) t.setParameters(p)