exopy.utils.atom_util module

Utility function to work with Atom tagged members and to automatize preferences handling.

exopy.utils.atom_util.tagged_members(obj, meta=None, meta_value=None)[source]

Utility function to retrieve tagged members from an object

Parameters
  • obj (Atom) – Object from which the tagged members should be retrieved.

  • meta (str, optional) – The tag to look for, only member which has this tag will be returned

  • meta_value (optional) – The value of the metadata used for filtering the members returned

Returns

tagged_members – Dictionary of the members whose metadatas corresponds to the predicate

Return type

dict(str, Member)

exopy.utils.atom_util.member_from_pref(obj, member, val)[source]

Retrieve the value stored in the preferences for a member.

Parameters
  • obj (Atom) – Object who owns the member.

  • member (Member) – Member for which the preferences should be retrieved.

  • val (Value) – Value that is stored in the preferences, depending on the case this might be a serialized value or simply a string.

Returns

value – The deserialized value that can be assigned to the member.

Return type

Value

exopy.utils.atom_util.member_to_pref(obj, member, val)[source]

Provide the value that will be stored in the preferences for a member.

Parameters
  • obj (Atom) – Object who owns the member.

  • member (Member) – Member for which the preferences should be retrieved

  • val (Value) – Value of the member to be stored in the preferences

Returns

pref_value – The serialized value/string that will be stored in the pref.

Return type

str

exopy.utils.atom_util.ordered_dict_to_pref(obj, member, val)[source]
Function to convert an OrderedDict to something that can

be easily stored and read back, in this case a list of tuples.

Parameters
  • obj (Atom) – The instance calling the function

  • member (Member) – The member that must be stored

  • val (OrderedDict) – The current value of the member

Returns

value – the serialized value

Return type

str

exopy.utils.atom_util.ordered_dict_from_pref(obj, member, val)[source]

Read back the list of tuples saved by ‘ordered_dict_to_pref’.

We simply do a literal_eval of the list of tuples, and then convert it to an OrderedDict.

Parameters
  • obj (Atom) – The instance calling the function

  • member (Member) – The member that must be stored

  • val (str) – The string representation of the stored value

Returns

value – An Ordered Dict that can be assigned to the member.

Return type

OrderedDict

class exopy.utils.atom_util.HasPrefAtom[source]

Bases: atom.atom.Atom

Base class for Atom object using preferences.

This class defines the basic functions used to build a string dict from the member value and to update the members from such a dict.

preferences_from_members()

Get the members values as string to store them in .ini files.

update_members_from_preferences(parameters)

Use the string values given in the parameters to update the members

This function will call itself on any tagged HasPrefAtom member.

exopy.utils.atom_util.preferences_from_members(self)[source]

Get the members values as string to store them in .ini files.

exopy.utils.atom_util.update_members_from_preferences(self, parameters)[source]

Use the string values given in the parameters to update the members

This function will call itself on any tagged HasPrefAtom member.