Node

class pyrubrum.Node(menu: pyrubrum.menus.base_menu.BaseMenu, children: Optional[Set[Node]] = None)

Representation of a single object in a tree, which might have defined a parent (i.e. the Node object it is child of) and a set of other nodes, which are its children. Each Node instance is linked to a subclass of BaseMenu.

Parameters
  • menu (BaseMenu) – The menu this node is being linked to.

  • children (Optional[Set[Node]]) – The nodes whose parent is going to be this instance. Defaults to None, which makes the children set an empty one.

add_child(node: pyrubrum.tree.node.Node)

Add a Node instance to the set of children.

Parameters

node (Node) – The node which is being added as a child of this object.

get_children_menus() → Iterable[pyrubrum.menus.base_menu.BaseMenu]

Get all the menus that are linked to the children belonging to this instance.

Returns

A tuple that contains all the retrieved menus.

Return type

Iterable[BaseMenu]

get_family(menu_id: str, parent: Optional[Node]) → Tuple[Optional[pyrubrum.menus.base_menu.BaseMenu], Optional[Set[pyrubrum.menus.base_menu.BaseMenu]]]

Retrieve the menus which are linked to both parent and children of this instance if this instance matches the provided identifier. Otherwise it will search the menu matching it in its children and return its family, if matched. On failure, it will return a tuple of length two filled with null values (i.e. None).

Parameters
  • menu_id (str) – The identifier which must be matched.

  • parent (Optional[Node]) – The parent this Node comes from.

Returns

A tuple of length two, whose first element is the parent node of the matched node while the second one is a tuple of all its children If no Node is found, the tuple will be filled with null values (i.e. None).

Return type

Tuple[Optional[BaseMenu], Optional[Tuple[BaseMenu]]]

get_menus() → Set[pyrubrum.menus.base_menu.BaseMenu]

Retrieve the set of all the menus which are linked to the nodes belonging to the descent of this class (i.e. the children, the children of the children, etc…).

Returns

The set of all the retrieved menus.

Return type

Set[BaseMenu]