Object model#
The datalab.objectmodel module defines the object data model used by the
GUI to store signals, images and groups.
The model is based on a hierarchical tree of objects, with two levels:
The top level is a list of groups (ObjectGroup instances)
The second level is a list of objects (SignalObj or ImageObj instances)
The model is implemented by the ObjectModel class.
Object group#
The ObjectGroup class represents a group of objects. It is a container for SignalObj and ImageObj instances.
- class datalab.objectmodel.ObjectGroup(title: str, model: ObjectModel, prefix: str)[source]#
Represents a DataLab object group
- Parameters:
title – group title
model – object model
prefix – prefix for short ID (“gs” for signal groups, “gi” for image groups)
Object model#
The ObjectModel class is a container for ObjectGroup instances, as well as a container for SignalObj and ImageObj instances.
- class datalab.objectmodel.ObjectModel(group_prefix: str)[source]#
Represents a DataLab object model (groups of signals/images)
- reset_short_ids() None[source]#
Reset short IDs (used for object numbering)
This method is called when an object was removed from a group.
- has_uuid(uuid: str) bool[source]#
Check if an object with the given UUID exists in the model
- Parameters:
uuid – UUID string to check
- Returns:
True if an object with this UUID exists, False otherwise
- get_all_objects(flatten: bool = True) list[SignalObj | ImageObj] | list[list[SignalObj | ImageObj]][source]#
Return all objects, in order of appearance in groups
- Parameters:
flatten – if True, return a flat list of objects, otherwise return a list of lists (one list per group)
- Returns:
List of objects in order of appearance in groups.
- get_object_or_group(uuid: str) SignalObj | ImageObj | ObjectGroup[source]#
Return object or group with uuid
- get_group(uuid: str) ObjectGroup[source]#
Return group with uuid
- get_number(obj_or_group: SignalObj | ImageObj | ObjectGroup) int[source]#
Return number of object or group
- get_group_from_number(number: int) ObjectGroup[source]#
Return group from its number.
- Parameters:
number – group number (starts with 1)
- Returns:
Group
- Raises:
IndexError – if group with number not found
- get_group_from_title(title: str) ObjectGroup[source]#
Return group from its title.
- Parameters:
title – group title
- Returns:
Group
- Raises:
KeyError – if group with title not found
- get_group_from_object(obj: SignalObj | ImageObj) ObjectGroup[source]#
Return group containing object
- Parameters:
obj – object to find group for
- Returns:
Group
- Raises:
KeyError – if object not found in any group
- add_group(title: str) ObjectGroup[source]#
Add group to model
- Parameters:
title – group title
- Returns:
Created group object
- get_object_group_id(obj: SignalObj | ImageObj) str | None[source]#
Return group id of object
- Parameters:
obj – object to get group id from
- Returns:
group id or None if object is not in any group
- remove_group(group: ObjectGroup) None[source]#
Remove group from model
- get_object_from_number(number: int) SignalObj | ImageObj[source]#
Return object from its number.
- Parameters:
number – object number (unique in model)
- Returns:
Object
- Raises:
IndexError – if object with number not found
- get_object_ids(flatten: bool = True) list[str] | list[list[str]][source]#
Return object ids, in order of appearance in groups
- Parameters:
flatten – if True, return a flat list of object ids, otherwise return a list of lists (one list per group)
- Returns:
List of object ids in order of appearance in groups.
- get_group_titles_with_object_info() tuple[list[str], list[list[str]], list[list[str]]][source]#
Return groups titles and lists of inner objects uuids and titles.
- Returns:
groups titles, lists of inner objects uuids and titles
- Return type:
Tuple
- get_object_titles(flatten: bool = True) list[str] | list[list[str]][source]#
Return object titles, in order of appearance in groups
- Parameters:
flatten – if True, return a flat list of object titles, otherwise return a list of lists (one list per group)
- Returns:
List of object titles in order of appearance in groups.
- get_object_from_title(title: str) SignalObj | ImageObj[source]#
Return object with title.
- Parameters:
title – object title
- Returns:
object with title
- Raises:
KeyError – if object with title not found
- replace_short_ids_by_uuids_in_titles(other_objects: tuple[SignalObj | ImageObj] | None = None) None[source]#
Replace short IDs by uuids in titles
- Parameters:
other_objects – tuple of other objects to consider for short ID replacement
Note
This method is called before reorganizing groups or objects. It replaces the short IDs in titles by the uuids. This is needed because the short IDs are used to reflect in the title the operation performed on the object/group, e.g. “fft(s001)” or “g001 + g002”. But when reorganizing groups or objects, the short IDs may change, so we need to replace them by the uuids, which are stable. Once the reorganization is done, we will replace the uuids by the new short IDs thanks to the __replace_uuids_by_short_ids_in_titles method.
- replace_uuids_by_short_ids_in_titles() None[source]#
Replace uuids by short IDs in titles
Note
This method is called after reorganizing groups or objects. It replaces the uuids in titles by the short IDs.