Add keys() method to Parameter class
This returns the names attribute, allowing **unpacking of Parameter subclasses.
This commit is contained in:
parent
5bfe8d5a46
commit
9ed51cd1e2
@ -677,6 +677,9 @@ class Parameter(QtCore.QObject):
|
|||||||
names = (names,)
|
names = (names,)
|
||||||
return self.param(*names).setValue(value)
|
return self.param(*names).setValue(value)
|
||||||
|
|
||||||
|
def keys(self):
|
||||||
|
return self.names
|
||||||
|
|
||||||
def child(self, *names):
|
def child(self, *names):
|
||||||
"""Return a child parameter.
|
"""Return a child parameter.
|
||||||
Accepts the name of the child or a tuple (path, to, child)
|
Accepts the name of the child or a tuple (path, to, child)
|
||||||
|
@ -34,3 +34,20 @@ def test_parameter_hasdefault_none(passdefault):
|
|||||||
|
|
||||||
p.setDefault(None)
|
p.setDefault(None)
|
||||||
assert not p.hasDefault()
|
assert not p.hasDefault()
|
||||||
|
|
||||||
|
def test_unpack_parameter():
|
||||||
|
# test that **unpacking correctly returns child name/value maps
|
||||||
|
params = [
|
||||||
|
dict(name='a', type='int', value=1),
|
||||||
|
dict(name='b', type='str', value='2'),
|
||||||
|
dict(name='c', type='float', value=3.0),
|
||||||
|
]
|
||||||
|
p = Parameter.create(name='params', type='group', children=params)
|
||||||
|
result = dict(**p)
|
||||||
|
|
||||||
|
assert 'a' in result
|
||||||
|
assert result['a'] == 1
|
||||||
|
assert 'b' in result
|
||||||
|
assert result['b'] == '2'
|
||||||
|
assert 'c' in result
|
||||||
|
assert result['c'] == 3.0
|
||||||
|
Loading…
Reference in New Issue
Block a user