relation

class janim.items.relation.Relation

Bases: Refreshable, Generic

Defines the containment relationship of a directed acyclic graph and some practical operations

That is, for each object:

  • self.parents stores the directly associated parent objects

  • self.children stores the directly associated child objects

  • Use add() to establish relationships between objects

  • Use remove() to cancel relationships between objects

  • ancestors() 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() and descendants() :
    • Does not include the caller itself, and the returned list has no duplicate elements

    • The order of the objects is DFS order

parents: list[GRelT]

Warning

不要直接对该变量作出修改,请使用 add()remove() 等方法

对该变量的直接访问仅是为了方便遍历等操作

children: list[GRelT]

Warning

不要直接对该变量作出修改,请使用 add()remove() 等方法

对该变量的直接访问仅是为了方便遍历等操作

mark_refresh(func: Callable | str, *, recurse_up=False, recurse_down=False) Self

Marks the specified func for an update

parents_changed() None

Signal triggered when self.parents changes

children_changed() None

Signal triggered when self.children changes

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_cls as 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_cls as the base class, but exclude the descendants of objects that already meet the conditions