From 94cc8935a2043bd4181a83e9c0d414acc9826346 Mon Sep 17 00:00:00 2001 From: Ashwola Date: Fri, 25 Oct 2024 09:39:32 +0200 Subject: [PATCH 01/13] Correctly write and read an XML file which uses parameter with: 1) non-group type 2) children --- src/pymodaq_gui/parameter/ioxml.py | 31 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/pymodaq_gui/parameter/ioxml.py b/src/pymodaq_gui/parameter/ioxml.py index c71cff98..eac3990e 100644 --- a/src/pymodaq_gui/parameter/ioxml.py +++ b/src/pymodaq_gui/parameter/ioxml.py @@ -47,14 +47,12 @@ def walk_parameters_to_xml(parent_elt=None, param=None): params_list = param.children() for param in params_list: - opts = dict_from_param(param) elt = ET.Element(param.name(), **opts) - param_type = str(param.type()) - if 'group' not in param_type: # covers 'group', custom 'groupmove'... - add_text_to_elt(elt, param) - else: + param_type = str(param.type()) + if param.hasChildren(): walk_parameters_to_xml(elt, param) + add_text_to_elt(elt, param) parent_elt.append(elt) return parent_elt @@ -401,19 +399,18 @@ def walk_xml_to_parameter(params=[], XML_elt=None): param_type = el.get('type') if 'group' not in param_type: # covers 'group', custom 'groupmove'... - set_txt_from_elt(el, param_dict) + set_txt_from_elt(el, param_dict) + if param_type not in PARAM_TYPES: + param_dict['type'] = 'group' # in case the custom group has been defined somewhere but not + # registered again in this session + if len(el) == 0: + children = [] else: - if param_type not in PARAM_TYPES: - param_dict['type'] = 'group' # in case the custom group has been defined somewhere but not - # registered again in this session - if len(el) == 0: - children = [] - else: - subparams = [] - children = walk_xml_to_parameter(subparams, el) - param_dict['children'] = children - - param_dict['name'] = el.tag + subparams = [] + children = walk_xml_to_parameter(subparams, el) + param_dict['children'] = children + + param_dict['name'] = el.tag params.append(param_dict) except Exception as e: # to be able to debug when there's an issue From c1b34add25cdeb3d150d599591b9231d0111467f Mon Sep 17 00:00:00 2001 From: Ashwola Date: Tue, 29 Oct 2024 17:30:05 +0100 Subject: [PATCH 02/13] Updating ParameterEx to provide example --- src/pymodaq_gui/examples/parameter_ex.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pymodaq_gui/examples/parameter_ex.py b/src/pymodaq_gui/examples/parameter_ex.py index 6bd97576..327240ac 100644 --- a/src/pymodaq_gui/examples/parameter_ex.py +++ b/src/pymodaq_gui/examples/parameter_ex.py @@ -17,6 +17,11 @@ class ParameterEx(ParameterManager): {'title': 'A visible group:', 'name': 'agroup', 'type': 'group', 'children': []}, {'title': 'An hidden group:', 'name': 'bgroup', 'type': 'group', 'children': [], 'visible': False}, # this # visible option is not available in usual pyqtgraph group + {'title': 'A bool with children:', 'name': 'booleans_group', 'type': 'bool', 'tip': 'Any Parameter can have its own children', 'children': [ + {'title': 'A bool in a bool', 'name': 'a_bool_in_a_bool', 'type': 'bool', 'value': True}, + {'title': 'A push with children', 'name': 'aboolpush', 'type': 'bool_push', 'value': True, 'label': 'action','children':[ + {'title': 'A string in a group', 'name': 'atte_in_a_group', 'type': 'str', 'value': 'this is a string you can edit'}, + ]},]}, ]}, {'title': 'Numbers:', 'name': 'numbers', 'type': 'group', 'children': [ From 1c0f67c80f399fa1c73f8711ed76c8f05aeb6cf4 Mon Sep 17 00:00:00 2001 From: Ashwola Date: Tue, 29 Oct 2024 17:52:50 +0100 Subject: [PATCH 03/13] Adding an assert value in the testing --- src/pymodaq_gui/examples/parameter_ex.py | 2 +- tests/managers/parameter_manager_test.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pymodaq_gui/examples/parameter_ex.py b/src/pymodaq_gui/examples/parameter_ex.py index 327240ac..1e977092 100644 --- a/src/pymodaq_gui/examples/parameter_ex.py +++ b/src/pymodaq_gui/examples/parameter_ex.py @@ -17,7 +17,7 @@ class ParameterEx(ParameterManager): {'title': 'A visible group:', 'name': 'agroup', 'type': 'group', 'children': []}, {'title': 'An hidden group:', 'name': 'bgroup', 'type': 'group', 'children': [], 'visible': False}, # this # visible option is not available in usual pyqtgraph group - {'title': 'A bool with children:', 'name': 'booleans_group', 'type': 'bool', 'tip': 'Any Parameter can have its own children', 'children': [ + {'title': 'A bool with children:', 'name': 'booleans_group', 'type': 'bool', 'value':False, 'tip': 'Any Parameter can have its own children', 'children': [ {'title': 'A bool in a bool', 'name': 'a_bool_in_a_bool', 'type': 'bool', 'value': True}, {'title': 'A push with children', 'name': 'aboolpush', 'type': 'bool_push', 'value': True, 'label': 'action','children':[ {'title': 'A string in a group', 'name': 'atte_in_a_group', 'type': 'str', 'value': 'this is a string you can edit'}, diff --git a/tests/managers/parameter_manager_test.py b/tests/managers/parameter_manager_test.py index cd330336..79d6a5cf 100644 --- a/tests/managers/parameter_manager_test.py +++ b/tests/managers/parameter_manager_test.py @@ -11,7 +11,7 @@ from pyqtgraph.parametertree import Parameter from pymodaq_gui.examples.parameter_ex import ParameterEx -from pymodaq_gui.parameter.utils import ( +from pymodaq_gui.parameter.utils import (getValues,getStruct, iter_children_params, compareParameters, compareStructureParameter, compareValuesParameter) from pymodaq_gui.utils.widgets.table import TableModel @@ -69,7 +69,7 @@ def test_load(qtbot, tmp_path): ptree.save_settings_slot(file_path) parameter_copy = Parameter.create(name='settings', type='group', children=ParameterEx.params) - compareValuesParameter(ptree.settings, parameter_copy) + assert compareValuesParameter(ptree.settings, parameter_copy) parameters = iter_children_params(ptree.settings, childlist=[]) parameters_copy = iter_children_params(parameter_copy, childlist=[]) From 2f4533ae7b1c44276f76ec28defce6c91dbbee23 Mon Sep 17 00:00:00 2001 From: Ashwola Date: Wed, 30 Oct 2024 17:37:12 +0100 Subject: [PATCH 04/13] - adding label keyword in dict_from_param (used by bool_push) - using 'value' in param.opts for criteria to access add_text_to_elt --- src/pymodaq_gui/parameter/ioxml.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pymodaq_gui/parameter/ioxml.py b/src/pymodaq_gui/parameter/ioxml.py index 968eb816..c80a4b41 100644 --- a/src/pymodaq_gui/parameter/ioxml.py +++ b/src/pymodaq_gui/parameter/ioxml.py @@ -42,7 +42,7 @@ def walk_parameters_to_xml(parent_elt=None, param=None): opts = dict_from_param(param) parent_elt = ET.Element(param.name(), **opts) param_type = str(param.type()) - if 'group' not in param_type: # covers 'group', custom 'groupmove', 'groupai' ... + if 'value' in param.opts: add_text_to_elt(parent_elt, param) params_list = param.children() @@ -52,9 +52,11 @@ def walk_parameters_to_xml(parent_elt=None, param=None): param_type = str(param.type()) if param.hasChildren(): walk_parameters_to_xml(elt, param) - add_text_to_elt(elt, param) + if 'value' in param.opts: + add_text_to_elt(elt, param) parent_elt.append(elt) + return parent_elt @@ -191,6 +193,10 @@ def dict_from_param(param): movelist = str(param.opts['movelist']) opts.update(dict(movelist=movelist)) + if 'label' in param.opts: + label = str(param.opts['label']) + opts.update(dict(label=label)) + if 'show_pb' in param.opts: if param.opts['show_pb']: show_pb = '1' From a053153948baa991fda66f87601e61b2d1f271f8 Mon Sep 17 00:00:00 2001 From: Ashwola Date: Wed, 30 Oct 2024 17:42:02 +0100 Subject: [PATCH 05/13] adding label keyword in elt_to_dict --- src/pymodaq_gui/parameter/ioxml.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pymodaq_gui/parameter/ioxml.py b/src/pymodaq_gui/parameter/ioxml.py index c80a4b41..b0959be8 100644 --- a/src/pymodaq_gui/parameter/ioxml.py +++ b/src/pymodaq_gui/parameter/ioxml.py @@ -282,6 +282,10 @@ def elt_to_dict(el): addText = str(el.get('addText')) param.update(dict(addText=addText)) + if 'label' in el.attrib.keys(): + label = str(el.get('label')) + param.update(dict(label=label)) + # if 'limits' in el.attrib.keys(): # try: # values = list(eval(el.get('limits'))) # make sure the evaluated values are returned as list (in case another From e9a9ad43e5013869df316f20939f1a2b3c346ed0 Mon Sep 17 00:00:00 2001 From: Ashwola Date: Wed, 30 Oct 2024 18:34:08 +0100 Subject: [PATCH 06/13] Some formatting and cleaning up redundancies --- src/pymodaq_gui/parameter/ioxml.py | 34 ++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/pymodaq_gui/parameter/ioxml.py b/src/pymodaq_gui/parameter/ioxml.py index b0959be8..6150cdfe 100644 --- a/src/pymodaq_gui/parameter/ioxml.py +++ b/src/pymodaq_gui/parameter/ioxml.py @@ -41,7 +41,6 @@ def walk_parameters_to_xml(parent_elt=None, param=None): if parent_elt is None: opts = dict_from_param(param) parent_elt = ET.Element(param.name(), **opts) - param_type = str(param.type()) if 'value' in param.opts: add_text_to_elt(parent_elt, param) @@ -49,7 +48,6 @@ def walk_parameters_to_xml(parent_elt=None, param=None): for param in params_list: opts = dict_from_param(param) elt = ET.Element(param.name(), **opts) - param_type = str(param.type()) if param.hasChildren(): walk_parameters_to_xml(elt, param) if 'value' in param.opts: @@ -397,20 +395,12 @@ def walk_xml_to_parameter(params=[], XML_elt=None): raise TypeError('not valid XML element') if len(XML_elt) == 0: - param_dict = elt_to_dict(XML_elt) - param_type = XML_elt.get('type') - - if 'group' not in param_type: # covers 'group', custom 'groupmove'... - set_txt_from_elt(XML_elt, param_dict) + param_dict = set_dict_from_el(XML_elt) params.append(param_dict) for el in XML_elt: - param_dict = elt_to_dict(el) - param_type = el.get('type') - - if 'group' not in param_type: # covers 'group', custom 'groupmove'... - set_txt_from_elt(el, param_dict) - if param_type not in PARAM_TYPES: + param_dict = set_dict_from_el(el) + if param_dict['type'] not in PARAM_TYPES: param_dict['type'] = 'group' # in case the custom group has been defined somewhere but not # registered again in this session if len(el) == 0: @@ -418,15 +408,22 @@ def walk_xml_to_parameter(params=[], XML_elt=None): else: subparams = [] children = walk_xml_to_parameter(subparams, el) - param_dict['children'] = children - - param_dict['name'] = el.tag - + param_dict['children'] = children params.append(param_dict) + except Exception as e: # to be able to debug when there's an issue raise e return params +def set_dict_from_el(el): + """Convert an element into a dict + ---------- + el: xml element + param_dict: dictionnary from which the parameter will be constructed + """ + param_dict = elt_to_dict(el) + set_txt_from_elt(el, param_dict) + return param_dict def set_txt_from_elt(el, param_dict): """ @@ -438,7 +435,8 @@ def set_txt_from_elt(el, param_dict): """ val_text = el.text - param_type = el.get('type') + param_type = param_dict['type'] + # param_type = el.get('type') # Redundancy (param_dict already has this attribute) if val_text is not None: if param_type == 'float': param_value = float(val_text) From 4f05166ff10f749850d9a2cd9646454d59a603e0 Mon Sep 17 00:00:00 2001 From: Ashwola Date: Thu, 31 Oct 2024 15:46:01 +0100 Subject: [PATCH 07/13] Adding keyworkds to filter children parameters according to their name or their types --- src/pymodaq_gui/parameter/utils.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/pymodaq_gui/parameter/utils.py b/src/pymodaq_gui/parameter/utils.py index 881fe648..ccc3b502 100644 --- a/src/pymodaq_gui/parameter/utils.py +++ b/src/pymodaq_gui/parameter/utils.py @@ -166,14 +166,30 @@ def iter_children(param, childlist=[]): return childlist -def iter_children_params(param, childlist=[]): +def iter_children_params(param, childlist=[], filter_type=[], filter_name=[]): """Get a list of parameters under a given Parameter + | Returns all children parameters. + =============== ================================= ==================================== + **Parameters** **Type** **Description** + *param* instance of pyqtgraph parameter the root node to be coursed + *childlist* list the child list recetion structure + *filter_type* list filter parameter sharing those types from output + *filter_name* list filter parameter sharing those names from output + =============== ================================= ==================================== + + Returns + ------- + childlist : parameter list + The list of the children from the given node. """ for child in param.children(): - childlist.append(child) + if child.type() in filter_type or child.name() in filter_name: + pass + else: + childlist.append(child) if child.hasChildren(): - childlist.extend(iter_children_params(child, [])) + childlist.extend(iter_children_params(child, [], filter_type, filter_name)) return childlist From a8b2a5a3cf7856fef7ccab26522f2bc4aa5c8541 Mon Sep 17 00:00:00 2001 From: Ashwola Date: Thu, 31 Oct 2024 15:59:19 +0100 Subject: [PATCH 08/13] - Adding possibility to select filtered types - Adding tests --- src/pymodaq_gui/parameter/utils.py | 15 ++++++++++----- tests/parameter_test/param_utils_test.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/pymodaq_gui/parameter/utils.py b/src/pymodaq_gui/parameter/utils.py index ccc3b502..7b32ddd0 100644 --- a/src/pymodaq_gui/parameter/utils.py +++ b/src/pymodaq_gui/parameter/utils.py @@ -166,7 +166,7 @@ def iter_children(param, childlist=[]): return childlist -def iter_children_params(param, childlist=[], filter_type=[], filter_name=[]): +def iter_children_params(param, childlist=[], filter_type=[], filter_name=[], selectFilter=False): """Get a list of parameters under a given Parameter | Returns all children parameters. @@ -174,8 +174,10 @@ def iter_children_params(param, childlist=[], filter_type=[], filter_name=[]): **Parameters** **Type** **Description** *param* instance of pyqtgraph parameter the root node to be coursed *childlist* list the child list recetion structure - *filter_type* list filter parameter sharing those types from output - *filter_name* list filter parameter sharing those names from output + *filter_type* list filter parameter sharing those types from output + *filter_name* list filter parameter sharing those names from output + *selectFilter* bool if True, add filtered parameters to output list + =============== ================================= ==================================== Returns @@ -184,10 +186,13 @@ def iter_children_params(param, childlist=[], filter_type=[], filter_name=[]): The list of the children from the given node. """ for child in param.children(): - if child.type() in filter_type or child.name() in filter_name: - pass + isFiltered = child.type() in filter_type or child.name() in filter_name + if isFiltered: + if selectFilter: + childlist.append(child) else: childlist.append(child) + if child.hasChildren(): childlist.extend(iter_children_params(child, [], filter_type, filter_name)) return childlist diff --git a/tests/parameter_test/param_utils_test.py b/tests/parameter_test/param_utils_test.py index 73eacbb4..63450665 100644 --- a/tests/parameter_test/param_utils_test.py +++ b/tests/parameter_test/param_utils_test.py @@ -58,6 +58,17 @@ P3 = Parameter(name='settings3', type='group', children=params3) P4 = Parameter(name='settings4', type='group', children=params4) +def test_iter_children_params(): + settings = Parameter.create(name='settings', type='group', children=params) + param_list = putils.iter_children_params(settings,filter_type=['group']) + assert [p.type() != 'group' for p in param_list] + param_list = putils.iter_children_params(settings,filter_name=['axis']) + assert [p.name() != 'axis' for p in param_list] + param_list = putils.iter_children_params(settings,filter_name=['axis'],selectFilter=True) + assert [p.name() != 'axis' for p in param_list] + param_list = putils.iter_children_params(settings,filter_type=['group'],selectFilter=True) + assert [p.type() == 'group' for p in param_list] + def test_get_param_path(): settings = Parameter.create(name='settings', type='group', children=params) From 9d784a32578390bbd0625516acde3d37da31644b Mon Sep 17 00:00:00 2001 From: Ashwola Date: Thu, 31 Oct 2024 16:33:46 +0100 Subject: [PATCH 09/13] now works at intended --- src/pymodaq_gui/parameter/utils.py | 10 ++++------ tests/parameter_test/param_utils_test.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/pymodaq_gui/parameter/utils.py b/src/pymodaq_gui/parameter/utils.py index 7b32ddd0..cb8b08b0 100644 --- a/src/pymodaq_gui/parameter/utils.py +++ b/src/pymodaq_gui/parameter/utils.py @@ -187,14 +187,12 @@ def iter_children_params(param, childlist=[], filter_type=[], filter_name=[], se """ for child in param.children(): isFiltered = child.type() in filter_type or child.name() in filter_name - if isFiltered: - if selectFilter: - childlist.append(child) - else: + addSelectChild = selectFilter and isFiltered + addNonSelectChild = not selectFilter and not isFiltered + if addSelectChild or addNonSelectChild: childlist.append(child) - if child.hasChildren(): - childlist.extend(iter_children_params(child, [], filter_type, filter_name)) + iter_children_params(child, childlist, filter_type, filter_name, selectFilter) return childlist diff --git a/tests/parameter_test/param_utils_test.py b/tests/parameter_test/param_utils_test.py index 63450665..08594e85 100644 --- a/tests/parameter_test/param_utils_test.py +++ b/tests/parameter_test/param_utils_test.py @@ -61,14 +61,14 @@ def test_iter_children_params(): settings = Parameter.create(name='settings', type='group', children=params) param_list = putils.iter_children_params(settings,filter_type=['group']) - assert [p.type() != 'group' for p in param_list] - param_list = putils.iter_children_params(settings,filter_name=['axis']) - assert [p.name() != 'axis' for p in param_list] - param_list = putils.iter_children_params(settings,filter_name=['axis'],selectFilter=True) - assert [p.name() != 'axis' for p in param_list] - param_list = putils.iter_children_params(settings,filter_type=['group'],selectFilter=True) - assert [p.type() == 'group' for p in param_list] - + assert all([p.type() != 'group' for p in param_list]) + param_list = putils.iter_children_params(settings,childlist=[],filter_name=['axis']) + assert all([p.name() != 'axis' for p in param_list]) + param_list = putils.iter_children_params(settings,childlist=[],filter_name=['axis'],selectFilter=True) + assert all([p.name() == 'axis' for p in param_list]) + param_list = putils.iter_children_params(settings,childlist=[],filter_type=['group'],selectFilter=True) + assert all([p.type() == 'group' for p in param_list]) + def test_get_param_path(): settings = Parameter.create(name='settings', type='group', children=params) From 1e72c196793ad1a41b7039759d7553c0d927625a Mon Sep 17 00:00:00 2001 From: Ashwola Date: Sun, 3 Nov 2024 10:30:46 +0100 Subject: [PATCH 10/13] implementing comments from review --- src/pymodaq_gui/parameter/utils.py | 83 +++++++++++++++--------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/src/pymodaq_gui/parameter/utils.py b/src/pymodaq_gui/parameter/utils.py index cb8b08b0..51fe635f 100644 --- a/src/pymodaq_gui/parameter/utils.py +++ b/src/pymodaq_gui/parameter/utils.py @@ -143,56 +143,57 @@ def compareValuesParameter(param1:Parameter,param2:Parameter,)-> bool: """ return getValues(param1) == getValues(param2) -def iter_children(param, childlist=[]): - """Get a list of parameters name under a given Parameter - | Returns all childrens names. +def iter_children(param, childlist=[], filter_type=(), filter_name=(), select_filter=False): - =============== ================================= ==================================== - **Parameters** **Type** **Description** - *param* instance of pyqtgraph parameter the root node to be coursed - *childlist* list the child list recetion structure - =============== ================================= ==================================== - - Returns - ------- - childlist : parameter list - The list of the children from the given node. """ - for child in param.children(): - childlist.append(child.name()) - if child.hasChildren(): - # if 'group' in child.type(): - childlist.extend(iter_children(child, [])) - return childlist - + Old instance of iter_children_params + """ + DeprecationWarning('iter_children is obsolete since pymodaq_5.0.0 and will soon be removed, now use iter_children_params with output_type=\'name\'') + return iter_children_params(param, childlist=[], output_type='name', filter_type=(), filter_name=(), select_filter=False) -def iter_children_params(param, childlist=[], filter_type=[], filter_name=[], selectFilter=False): - """Get a list of parameters under a given Parameter - | Returns all children parameters. - =============== ================================= ==================================== - **Parameters** **Type** **Description** - *param* instance of pyqtgraph parameter the root node to be coursed - *childlist* list the child list recetion structure - *filter_type* list filter parameter sharing those types from output - *filter_name* list filter parameter sharing those names from output - *selectFilter* bool if True, add filtered parameters to output list +def iter_children_params(param, childlist=[], output_type=None, filter_type=(), filter_name=(), select_filter=False): + """ + Get a list of parameters under a given Parameter. - =============== ================================= ==================================== + Parameters + ---------- + param : Parameter (pyqtgraph) + the root node to be coursed + childlist: list + the child/output list + output_type: str + the attribute of parameter that will be added to the output list + filter_type: list + filter children sharing those types + filter_name: list + filter children sharing those names + select_filter: bool + if True, add filtered parameters to output list. + if False (default), add non-filtered parameter to output list. - Returns - ------- - childlist : parameter list - The list of the children from the given node. + Returns + ------- + list + The list of the children from the given node. """ + for child in param.children(): - isFiltered = child.type() in filter_type or child.name() in filter_name - addSelectChild = selectFilter and isFiltered - addNonSelectChild = not selectFilter and not isFiltered - if addSelectChild or addNonSelectChild: - childlist.append(child) + # XNOR Gate + is_filtered = child.type() in filter_type or child.name() in filter_name + add_selected_child = select_filter and is_filtered + add_notselected_child = not select_filter and not is_filtered + if add_selected_child or add_notselected_child: + if output_type is not None: + try: + output = getattr(child,output_type)() + except Exception as e: + print(str(e)) + else: + output = child + childlist.append(output) if child.hasChildren(): - iter_children_params(child, childlist, filter_type, filter_name, selectFilter) + childlist.extend(iter_children_params(child, [], output_type, filter_type, filter_name, select_filter)) return childlist From 8034415023d7c524a92197dce39bd4579eee548c Mon Sep 17 00:00:00 2001 From: Ashwola Date: Sun, 3 Nov 2024 10:31:16 +0100 Subject: [PATCH 11/13] - add test --- tests/parameter_test/param_ioxml_test.py | 6 +++--- tests/parameter_test/param_utils_test.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/parameter_test/param_ioxml_test.py b/tests/parameter_test/param_ioxml_test.py index 1af240b6..6dcadfc2 100644 --- a/tests/parameter_test/param_ioxml_test.py +++ b/tests/parameter_test/param_ioxml_test.py @@ -99,9 +99,9 @@ class TestXMLbackForth(): def test_save_load_xml(self): param_back = ioxml.XML_string_to_pobject(ioxml.parameter_to_xml_string(self.settings)) - - for child, child_back in zip(putils.iter_children_params(self.settings), - putils.iter_children_params(param_back)): + children_list_in = putils.iter_children_params(self.settings) + children_list_back = putils.iter_children_params(param_back) + for child, child_back in zip(children_list_in,children_list_back): assert child_back.name() == child.name() assert child_back.title() == child.title() assert child_back.value() == child.value() diff --git a/tests/parameter_test/param_utils_test.py b/tests/parameter_test/param_utils_test.py index 08594e85..38a8dfd8 100644 --- a/tests/parameter_test/param_utils_test.py +++ b/tests/parameter_test/param_utils_test.py @@ -64,11 +64,21 @@ def test_iter_children_params(): assert all([p.type() != 'group' for p in param_list]) param_list = putils.iter_children_params(settings,childlist=[],filter_name=['axis']) assert all([p.name() != 'axis' for p in param_list]) - param_list = putils.iter_children_params(settings,childlist=[],filter_name=['axis'],selectFilter=True) + param_list = putils.iter_children_params(settings,childlist=[],filter_name=['axis'],select_filter=True) assert all([p.name() == 'axis' for p in param_list]) - param_list = putils.iter_children_params(settings,childlist=[],filter_type=['group'],selectFilter=True) + param_list = putils.iter_children_params(settings,childlist=[],filter_type=['group'],select_filter=True) assert all([p.type() == 'group' for p in param_list]) +def test_iter_children_attributes(): + settings = Parameter.create(name='settings', type='group', children=params) + param_name = putils.iter_children_params(settings, childlist=[], output_type='name') + param_type = putils.iter_children_params(settings, childlist=[], output_type='type') + param_list = putils.iter_children_params(settings, childlist=[]) + for p_name,p_type,p in zip(param_name,param_type,param_list): + assert p_name == p.name() + assert p_type == p.type() + + def test_get_param_path(): settings = Parameter.create(name='settings', type='group', children=params) From 16a2ddb01308c81d1922ee610926ec5428fdf0fa Mon Sep 17 00:00:00 2001 From: Ashwola Date: Sun, 3 Nov 2024 12:40:04 +0100 Subject: [PATCH 12/13] need to explicitely give empty string to avoid issue when testing --- src/pymodaq_gui/parameter/utils.py | 12 ++++++++---- tests/parameter_test/param_utils_test.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pymodaq_gui/parameter/utils.py b/src/pymodaq_gui/parameter/utils.py index 51fe635f..02023a9b 100644 --- a/src/pymodaq_gui/parameter/utils.py +++ b/src/pymodaq_gui/parameter/utils.py @@ -143,16 +143,20 @@ def compareValuesParameter(param1:Parameter,param2:Parameter,)-> bool: """ return getValues(param1) == getValues(param2) -def iter_children(param, childlist=[], filter_type=(), filter_name=(), select_filter=False): +def iter_children(param, childlist=[], filter_type=(), filter_name=(), select_filter=False)-> list: """ - Old instance of iter_children_params + Get a list of parameters' name under a given Parameter (see iter_children_params) + + Returns + ------- + list + The list of the children name from the given node. """ - DeprecationWarning('iter_children is obsolete since pymodaq_5.0.0 and will soon be removed, now use iter_children_params with output_type=\'name\'') return iter_children_params(param, childlist=[], output_type='name', filter_type=(), filter_name=(), select_filter=False) -def iter_children_params(param, childlist=[], output_type=None, filter_type=(), filter_name=(), select_filter=False): +def iter_children_params(param, childlist=[], output_type=None, filter_type=(), filter_name=(), select_filter=False)-> list: """ Get a list of parameters under a given Parameter. diff --git a/tests/parameter_test/param_utils_test.py b/tests/parameter_test/param_utils_test.py index 38a8dfd8..b36d26aa 100644 --- a/tests/parameter_test/param_utils_test.py +++ b/tests/parameter_test/param_utils_test.py @@ -60,7 +60,7 @@ def test_iter_children_params(): settings = Parameter.create(name='settings', type='group', children=params) - param_list = putils.iter_children_params(settings,filter_type=['group']) + param_list = putils.iter_children_params(settings,childlist=[],filter_type=['group']) assert all([p.type() != 'group' for p in param_list]) param_list = putils.iter_children_params(settings,childlist=[],filter_name=['axis']) assert all([p.name() != 'axis' for p in param_list]) From d4c3def13fdd67e80824c769a054809dc74ab45a Mon Sep 17 00:00:00 2001 From: Ashwola Date: Mon, 4 Nov 2024 07:42:27 +0100 Subject: [PATCH 13/13] fix argument transfer between functions --- src/pymodaq_gui/parameter/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_gui/parameter/utils.py b/src/pymodaq_gui/parameter/utils.py index 02023a9b..2f5c08f5 100644 --- a/src/pymodaq_gui/parameter/utils.py +++ b/src/pymodaq_gui/parameter/utils.py @@ -153,7 +153,7 @@ def iter_children(param, childlist=[], filter_type=(), filter_name=(), select_fi list The list of the children name from the given node. """ - return iter_children_params(param, childlist=[], output_type='name', filter_type=(), filter_name=(), select_filter=False) + return iter_children_params(param, childlist=childlist, output_type='name', filter_type=(), filter_name=(), select_filter=False) def iter_children_params(param, childlist=[], output_type=None, filter_type=(), filter_name=(), select_filter=False)-> list: