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_gui.parameter.ioxml.XML_file_to_parameter(file_name)[source]
Convert a xml file into pyqtgraph parameter object.
- Returns:
params – a list of dictionary defining a Parameter object and its children
- Return type:
See also
Examples
- pymodaq_gui.parameter.ioxml.XML_string_to_parameter(xml_string)[source]
Convert a xml string into a list of dict for initialize pyqtgraph parameter object.
- pymodaq_gui.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)
See also
- pymodaq_gui.parameter.ioxml.dict_from_param(param)[source]
Get Parameter properties as a dictionary
- Parameters:
param (
Parameter)- Returns:
opts
- Return type:
See also
- pymodaq_gui.parameter.ioxml.elt_to_dict(el)[source]
Convert xml element attributes to a dictionnary
- Parameters:
el
- pymodaq_gui.parameter.ioxml.parameter_to_xml_file(param, filename, overwrite=True)[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
overwrite
boolean
raise Error is False and file exists
See also
Examples
- pymodaq_gui.parameter.ioxml.parameter_to_xml_string(param)[source]
Convert a Parameter to a XML string.
- Parameters:
param (
Parameter)- Returns:
str
- Return type:
XMl string
See also
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_gui.parameter.ioxml.set_txt_from_elt(el, param_dict)[source]
get the value of the parameter from the text value of the xml element :type el:
xml element:param el: :type el:xml element:type param_dict:dictionnary from which the parameter will be constructed:param param_dict: :type param_dict:dictionnary from which the parameter will be constructed
- pymodaq_gui.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
See also
- pymodaq_gui.parameter.ioxml.walk_xml_to_parameter(params=[], XML_elt=None)[source]
To convert an XML element (and children) to list of 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)
See also