mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 19:30:03 +02:00
added merge_args
This commit is contained in:
parent
f950e32893
commit
ec2d6c597f
@ -2929,7 +2929,10 @@ class Detector(CppDetectorApi):
|
||||
|
||||
@v_limit.setter
|
||||
def v_limit(self, value):
|
||||
self.setDAC(dacIndex.V_LIMIT, value, True)
|
||||
value = ut.merge_args(dacIndex.V_LIMIT, value, True)
|
||||
print(f'{value=}')
|
||||
ut.set_using_dict(self.setDAC, *value)
|
||||
# self.setDAC(dacIndex.V_LIMIT, value, True)
|
||||
|
||||
@property
|
||||
@element
|
||||
|
@ -207,3 +207,45 @@ def add_argument_before(a, args):
|
||||
return (ret,)
|
||||
return a, args
|
||||
|
||||
def add_argument_after(args, a):
|
||||
"""Add a before the other arguments. Also works with
|
||||
dict that holds args to several modules. Always puts the
|
||||
args in a dict to be compatible with set_using_dict"""
|
||||
if isinstance(args, tuple):
|
||||
return (*args, a)
|
||||
elif isinstance(args, dict):
|
||||
ret = {}
|
||||
for key, value in args.items():
|
||||
if isinstance(value, tuple):
|
||||
ret[key] = (*value, a)
|
||||
else:
|
||||
ret[key] = (value, a)
|
||||
return (ret,)
|
||||
return args, a
|
||||
|
||||
def pop_dict(args):
|
||||
for i,a in enumerate(args):
|
||||
if isinstance(a, dict):
|
||||
return args.pop(i), i
|
||||
|
||||
|
||||
def merge_args(*args):
|
||||
#find and pop dict since it holds the arguments
|
||||
n_dict = sum(isinstance(a, dict) for a in args)
|
||||
if n_dict == 0:
|
||||
return args
|
||||
|
||||
elif n_dict == 1:
|
||||
args = [a for a in args] #these are the args to be added
|
||||
values,pos = pop_dict(args)
|
||||
ret = {}
|
||||
for k, v in values.items():
|
||||
if not isinstance(v, tuple):
|
||||
v = (v,)
|
||||
items = [a for a in args]
|
||||
items.insert(pos, *v)
|
||||
ret[k] = tuple(items)
|
||||
return (ret,)
|
||||
|
||||
else:
|
||||
raise ValueError("Multiple dictionaries passes cannot merge args")
|
@ -321,3 +321,16 @@ def test_add_argument_before_dict():
|
||||
assert add_argument_before("another", {9: "string"}) == ({
|
||||
9: ("another", "string")
|
||||
}, )
|
||||
|
||||
|
||||
def test_add_argument_after():
|
||||
assert add_argument_after("a", 5) == ("a", 5)
|
||||
assert add_argument_after(("a", "b"), 3) == ("a", "b", 3)
|
||||
|
||||
def test_add_argument_after_dict():
|
||||
assert add_argument_after({0: "a"}, "b") == ({0: ("a", "b")},)
|
||||
assert add_argument_after({0: ("a", 1)}, True) == ({0: ("a", 1, True)}, )
|
||||
|
||||
def test_merge_args():
|
||||
assert merge_args("a", "b", 1) == ("a", "b", 1)
|
||||
assert merge_args({0:1, 1:2}, "a") == ({0: (1, "a"), 1: (2, "a")},)
|
Loading…
x
Reference in New Issue
Block a user