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 objectsUse
get_parents()andget_children()to get copies of the object listsancestors()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
- property parents¶
A copy of the parent-item list
- property children¶
A copy of the child-item list
- index(obj: GRelT) int¶
Get the index of a child item in the list
- Parameters:
obj – Child item to find
- Returns:
Index of the child item
- Raises:
ValueError – Child item not in the list
- mark_refresh(name: str, *, recurse_up=False, recurse_down=False) Self¶
Marks the specified
nameas needing an update
- add(*objs: GRelT, prepend=False, insert=None) Self¶
Add child items to this item
- Parameters:
objs – Child items to add
prepend – If insert=True (default is False), then insert at the beginning of the list of child items.
- insert(index: int, *objs: GRelT) Self¶
Insert child items at the specified index
- Parameters:
index – Index at which to insert
objs – Child items to insert
- remove(*objs: GRelT) Self¶
Remove child items from this item
- Parameters:
objs – Child items to remove
- shuffle() Self¶
Randomly shuffle the order of child items
Note
This method uses
random.shuffle()to shuffleFor reproducible randomness, set the seed with
random.seed()before calling this method
- clear_parents() Self¶
Clear parent items
- clear_children() Self¶
Clear child items
- ancestors() list[GRelT]¶
Get a list of ancestor items
- descendants() list[GRelT]¶
Get a list of descendant items
- walk_ancestors(base_cls: None = None) Generator[GRelT, None, None]¶
- walk_ancestors(base_cls: type[RelT]) Generator[RelT, None, None]
Traverse ancestor nodes with
base_cls(default to traverse all) as the base class
- walk_descendants(base_cls: None = None) Generator[GRelT, None, None]¶
- walk_descendants(base_cls: type[RelT]) 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[Self | GRelT, None, None]¶
Traverse self and ancestor nodes
- walk_self_and_descendants(root_only=False) Generator[Self | 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 items 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 items that already meet the conditions