vispy.scene.node module

class vispy.scene.node.Node(parent=None, name=None, transforms=None)

Bases: object

Base class representing an object in a scene.

A group of nodes connected through parent-child relationships define a scenegraph. Nodes may have any number of children.

Each Node defines a transform property, which describes the position, orientation, scale, etc. of the Node relative to its parent. The Node’s children inherit this property, and then further apply their own transformations on top of that.

With the transform property, each Node implicitly defines a “local” coordinate system, and the Nodes and edges in the scenegraph can be thought of as coordinate systems connected by transformation functions.

Parameters
parentNode

The parent of the Node.

namestr

The name used to identify the node.

transformsinstance of TransformSystem | None

The associated transforms.

property canvas

The canvas in which this node’s scenegraph is being drawn.

property children

A copy of the list of children of this node. Do not add items to this list, but use x.parent = y instead.

property clip_children

Boolean indicating whether children of this node will inherit its clipper.

property clipper

A visual filter that can be used to clip visuals to the boundaries of this node.

common_parent(node)

Return the common parent of two entities

If the entities have no common parent, return None.

Parameters
nodeinstance of Node

The other node.

Returns
parentinstance of Node | None

The parent.

describe_tree(with_transform=False)

Create tree diagram of children

Parameters
with_transformbool

If true, add information about node transform types.

Returns
treestr

The tree diagram.

property document

The document is an optional property that is an node representing the coordinate system from which this node should make physical measurements such as px, mm, pt, in, etc. This coordinate system should be used when determining line widths, font sizes, and any other lengths specified in physical units.

The default is None; in this case, a default document is used during drawing (usually this is supplied by the SceneCanvas).

property document_node

The node to be used as the document coordinate system.

By default, the document node is self.root_node.

is_child(node)

Check if a node is a child of the current node

Parameters
nodeinstance of Node

The potential child.

Returns
childbool

Whether or not the node is a child.

property name
node_path(node)

Return two lists describing the path from this node to another

Parameters
nodeinstance of Node

The other node.

Returns
p1list

First path (see below).

p2list

Second path (see below).

Notes

The first list starts with this node and ends with the common parent between the endpoint nodes. The second list contains the remainder of the path from the common parent to the specified ending node.

For example, consider the following scenegraph:

A --- B --- C --- D
                           --- E --- F

Calling D.node_path(F) will return:

([D, C, B], [E, F])
node_path_to_child(node)

Return a list describing the path from this node to a child node

If node is not a (grand)child of this node, then raise RuntimeError.

Parameters
nodeinstance of Node

The child node.

Returns
pathlist | None

The path.

node_path_transforms(node)

Return the list of transforms along the path to another node.

The transforms are listed in reverse order, such that the last transform should be applied first when mapping from this node to the other.

Parameters
nodeinstance of Node

The other node.

Returns
transformslist

A list of Transform instances.

node_transform(node)

Return the transform that maps from the coordinate system of self to the local coordinate system of node.

Note that there must be a _single_ path in the scenegraph that connects the two entities; otherwise an exception will be raised.

Parameters
nodeinstance of Node

The other node.

Returns
transforminstance of ChainTransform

The transform.

on_parent_change(event)

Parent change event handler

Parameters
eventinstance of Event

The event.

property opacity
property order

A value used to determine the order in which nodes are drawn.

Greater values are drawn later. Children are always drawn after their parent.

property parent

The parent of this node in the scenegraph.

Nodes inherit coordinate transformations and some filters (opacity and clipping by default) from their parents. Setting this property assigns a new parent, changing the topology of the scenegraph.

May be set to None to remove this node (and its children) from a scenegraph.

parent_chain()

Return the list of parents starting from this node. The chain ends at the first node with no parents.

property picking

Boolean that determines whether this node (and its children) are drawn in picking mode.

property root_node
property scene_node

The first ancestor of this node that is a SubScene instance, or self if no such node exists.

set_transform(type_, *args, **kwargs)

Create a new transform of type and assign it to this node.

All extra arguments are used in the construction of the transform.

Parameters
type_str

The transform type.

*argstuple

Arguments.

**kwargsdict

Keywoard arguments.

property transform

The transform that maps the local coordinate frame to the coordinate frame of the parent.

update()

Emit an event to inform listeners that properties of this Node have changed. Also request a canvas update.

property visible

Whether this node should be drawn or not. Only applicable to nodes that can be drawn.