relation¶
- class janim.items.relation.Relation¶
Bases:
Refreshable,GenericDefines the containment relationship of a directed acyclic graph and some practical operations
That is, for each object:
self.parentsstores the directly associated parent objectsself.childrenstores the directly associated child objectsUse
add()to establish relationships between objectsUse
remove()to cancel relationships between objectsancestors()represents the ancestor objects directly associated with it (including parent objects and parent objects’ parent objects, …)descendants()represents the descendant objects directly associated with it (including child objects, and child objects’ child objects, …)- For
ancestors()anddescendants(): Does not include the caller itself, and the returned list has no duplicate elements
The order of the objects is DFS order
- For
- parents: list[GRelT]¶
- children: list[GRelT]¶
- mark_refresh(func: Callable | str, *, recurse_up=False, recurse_down=False) Self¶
Marks the specified
funcfor an update
- parents_changed() None¶
Signal triggered when
self.parentschanges
- children_changed() None¶
Signal triggered when
self.childrenchanges
- add(*objs: GRelT, insert=False) Self¶
Add objects to this object
If insert=True (default is False), then insert at the beginning of the list of child items.
- remove(*objs: GRelT) Self¶
Remove objects from this object
- shuffle() Self¶
- clear_parents() Self¶
- clear_children() Self¶
- ancestors() list[GRelT]¶
Get a list of ancestor objects
- descendants() list[GRelT]¶
Get a list of descendant objects
- walk_ancestors(base_cls: type[RelT] = None) Generator[RelT, None, None]¶
Traverse ancestor nodes with base_cls (default to traverse all) as the base class
- walk_descendants(base_cls: type[RelT] = None) Generator[RelT, None, None]¶
Traverse descendant nodes with base_cls (default to traverse all) as the base class
- walk_self_and_ancestors(root_only=False) Generator[GRelT, None, None]¶
Traverse self and ancestor nodes
- walk_self_and_descendants(root_only=False) Generator[GRelT, None, None]¶
Traverse self and descendant nodes
- walk_nearest_ancestors(base_cls: type[RelT]) Generator[RelT, None, None]¶
Traverse ancestor nodes with
base_clsas the base class, but exclude the ancestors of objects that already meet the conditions
- walk_nearest_descendants(base_cls: type[RelT]) Generator[RelT, None, None]¶
Traverse descendant nodes with
base_clsas the base class, but exclude the descendants of objects that already meet the conditions