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, group_uuid: str | None = None)[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)
group_uuid – optional group UUID. If None, a new UUID is generated.
- remove_objects(uuids: Collection[str]) None[source]#
Remove objects from group, renumbering the objects once
- Parameters:
uuids – UUIDs of the objects to remove (other UUIDs are ignored)
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 or group with the given UUID exists in the model.
- Parameters:
uuid – UUID string to check
- Returns:
True if an object or group 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
- find_by_title_reference(reference: str) list[SignalObj | ImageObj | ObjectGroup][source]#
Return the objects or groups matching a title reference.
- Parameters:
reference –
<UUID8>(object) org<UUID8>(group) reference- Returns:
Matching objects or groups (more than one only on prefix collision).
- 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
ValueError – if multiple groups have the same title
- 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, group_uuid: str | None = None) ObjectGroup[source]#
Add group to model
- Parameters:
title – group title
group_uuid – optional group UUID. If None, a new UUID is generated.
- 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
- add_objects(objects: Sequence[SignalObj | ImageObj], group_id: str) bool[source]#
Add objects to the model atomically.
- Parameters:
objects – Objects to add, in insertion order
group_id – UUID of the target group
- Returns:
True if the short IDs of objects or groups already in the model changed; False when the objects were added after every existing object (the usual case), which leaves them unchanged.
- Raises:
KeyError – If the target group does not exist
ValueError – If an object UUID is duplicated or already exists
- remove_objects(objects: Iterable[SignalObj | ImageObj]) None[source]#
Remove objects from model, renumbering the remaining objects once
Removing many objects one by one (see
remove_object()) would renumber all the objects of the model after each removal.- Parameters:
objects – Objects to remove
- Raises:
KeyError – If an object is not in the model (nothing is removed)
- 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
ValueError – if multiple objects have the same title
- get_title_reference_index() dict[str, list[SignalObj | ImageObj | ObjectGroup]][source]#
Return a dictionary mapping title references to groups and objects.
Each value is the list
find_by_title_reference()returns for the reference. The index must be built again after objects or groups are added or removed.