Fork me on GitHub

pyhrf.xmlio module

exception pyhrf.xmlio.DeprecatedXMLFormatException

Bases: exceptions.Exception

class pyhrf.xmlio.Initable

Bases: object

Abstract class to keep track of how an object is initialised. To do so, it stores the init function and its parameters. The aim is to use it in a user interface or to serialize objects. It also allows to add comments and meta info on init parameters.

assert_is_initialized()
check_init_obj(params=None)

check if the function used for init can be used in this API -> must allow **kwargs and *args. All arguments must have a value: either a default one or specified in the input dict params

from_ui_node
get_arg_for_ui(a)
get_arg_from_ui(a)
get_init_func()
get_parameters_comments()
get_parameters_meta()
get_parameters_to_show()
init_new_obj()

Creates a new instance

set_arg_translation(a, t)

Set the display name of argument a as t

set_init(init_obj, **init_params)

Override init function with init_obj and use init_params as new init parameters. init_obj must return an instance of the same class as the current object. Useful when the object is not instanciated via its __init__ function but eg a static method.

set_init_param(param_name, param_value)
to_ui_node(label, parent=None)
class pyhrf.xmlio.UiNode(label, parent=None, attributes=None)

Bases: object

Store data hierarchically to be used in a Qt model/tree view setting. Also store additional node-specific data as attributes (in a dict). Attributes must only contain strings.

The resulting data structure is:

   col 0        | col 1
|- <node_label> | <node_attributes>                   #row 0
    |
    |  col 0              | col 1
    |- <child_node_label> | <child_node_attributes>   #row 0
        |
        |...
...

This structure is similar to DOM.

Features:

  • can be instantiated from any python object that can be serialized into human-readable strings: bool, int, float, string, numpy scalars, numpy arrays. It also support container types (list, dict, OrderedDict) as long as their items are also serializable into human-readable strings.

See static method from_py_object.

add_child(child)
child(row)
childCount()
from_py_object
from_xml
get_attribute(attr_name)
get_children()
has_attribute(attr_name)
is_leaf_node()
label()
log(tabLevel=-1)
serialize_attributes()
set_attribute(attr_name, attr_value)
set_label(label)
to_xml(pretty=False)

Return an XML representation (str) of the Node and its children.

type_info()
unserialize_attributes
pyhrf.xmlio.XmlInitable

alias of pyhrf.xmlio.Initable

pyhrf.xmlio.from_xml(sxml)
pyhrf.xmlio.numpy_array_from_string(s, sdtype, sshape=None)
pyhrf.xmlio.protect_xml_attr(sa)
pyhrf.xmlio.read_xml(fn)
pyhrf.xmlio.to_xml(obj, label='anonym', pretty=False)

Return an XML representation of the init state of the given object obj.

pyhrf.xmlio.unprotect_xml_attr(sa)
pyhrf.xmlio.write_xml(obj, fn)