11.3.2.2. Parameter and XML

Within PyMoDAQ, Parameter state are often saved or transferred (for instance when using TCP/IP) as a XML string whose Tree structure is well adapted to represent the Parameter tree structure. Below are all the functions used to convert from a Parameter to a XML string (or file) and vice-versa.

pymodaq.daq_utils.parameter.ioxml.walk_parameters_to_xml(parent_elt=None, param=None)[source]

To convert a parameter object (and children) to xml data tree.

Parameters Type Description
parent_elt XML element the root element
param instance of pyqtgraph parameter Parameter object to be converted
Returns:XML element – XML element with subelements from Parameter object
Return type:parent_elt
pymodaq.daq_utils.parameter.ioxml.walk_xml_to_parameter(params=[], XML_elt=None)[source]

To convert an XML element (and children) to dict enabling creation of parameter object.

Parameters Type Description
params dictionnary list the list to create parameter object
XML_elt XML object the XML object to be converted
Returns:params – list of dict to create parameter object
Return type:dictionnary list

Examples

>>> from pyqtgraph.parametertree import Parameter, ParameterItem
>>> import xml.etree.ElementTree as ET
>>> tree = ET.parse('text_bis.xml')
>>> root = tree.getroot()
>>> params=walk_xml_to_parameter(XML_elt=root)
>>> settings_xml=Parameter.create(name='Settings XML', type='group', children=params)
>>> settings=Parameter.create(name='Settings', type='group', children=params)
pymodaq.daq_utils.parameter.ioxml.add_text_to_elt(elt, param)[source]

Add a text filed in a xml element corresponding to the parameter value

Parameters:
  • elt (XML elt) –
  • param (Parameter) –
pymodaq.daq_utils.parameter.ioxml.set_txt_from_elt(el, param_dict)[source]

get the value of the parameter from the text value of the xml element :param el: :type el: xml element :param param_dict: :type param_dict: dictionnary from which the parameter will be constructed

pymodaq.daq_utils.parameter.ioxml.dict_from_param(param)[source]

Get Parameter properties as a dictionary

Parameters:param (Parameter) –
Returns:opts
Return type:dict
pymodaq.daq_utils.parameter.ioxml.elt_to_dict(el)[source]

Convert xml element attributes to a dictionnary

Parameters:el
pymodaq.daq_utils.parameter.ioxml.parameter_to_xml_string(param)[source]

Convert a Parameter to a XML string.

Parameters:param (Parameter) –
Returns:str
Return type:XMl string

Examples

>>> from pyqtgraph.parametertree import Parameter
>>>    #Create an instance of Parameter
>>> settings=Parameter(name='settings')
>>> converted_xml=parameter_to_xml_string(settings)
>>>    # The converted Parameter
>>> print(converted_xml)
b'<settings title="settings" type="None" />'
pymodaq.daq_utils.parameter.ioxml.parameter_to_xml_file(param, filename)[source]

Convert the given parameter to XML element and update the given XML file.

Parameters Type Description
param instance of pyqtgraph parameter the parameter to be added
filename string the filename of the XML file

Examples

pymodaq.daq_utils.parameter.ioxml.XML_file_to_parameter(file_name)[source]

Convert a xml file into pyqtgraph parameter object.

Parameters Type Description
file_name string the file name of the XML file to be converted
Returns:params – a parameter list of dictionnary to init a parameter
Return type:dictionnary list

Examples

pymodaq.daq_utils.parameter.ioxml.XML_string_to_parameter(xml_string)[source]

Convert a xml string into pyqtgraph parameter object.

Parameters Type Description
xml_string string the xml string to be converted
Returns:params
Return type:a parameter list of dict to init a parameter

Examples