flowchart.Node

class pyqtgraph.flowchart.Node(name, terminals=None, allowAddInput=False, allowAddOutput=False, allowRemove=True)[source]

Node represents the basic processing unit of a flowchart. A Node subclass implements at least:

  1. A list of input / ouptut terminals and their properties

  2. a process() function which takes the names of input terminals as keyword arguments and returns a dict with the names of output terminals as keys.

A flowchart thus consists of multiple instances of Node subclasses, each of which is connected to other by wires between their terminals. A flowchart is, itself, also a special subclass of Node. This allows Nodes within the flowchart to connect to the input/output nodes of the flowchart itself.

Optionally, a node class can implement the ctrlWidget() method, which must return a QWidget (usually containing other widgets) that will be displayed in the flowchart control panel. Some nodes implement fairly complex control widgets, but most nodes follow a simple form-like pattern: a list of parameter names and a single value (represented as spin box, check box, etc..) for each parameter. To make this easier, the CtrlNode subclass allows you to instead define a simple data structure that CtrlNode will use to automatically generate the control widget.

__init__(name, terminals=None, allowAddInput=False, allowAddOutput=False, allowRemove=True)[source]

Arguments:

name

The name of this specific node instance. It can be any string, but must be unique within a flowchart. Usually, we simply let the flowchart decide on a name when calling Flowchart.addNode(…)

terminals

Dict-of-dicts specifying the terminals present on this Node. Terminal specifications look like:

'inputTerminalName': {'io': 'in'}
'outputTerminalName': {'io': 'out'}

There are a number of optional parameters for terminals: multi, pos, renamable, removable, multiable, bypass. See the Terminal class for more information.

allowAddInput

bool; whether the user is allowed to add inputs by the context menu.

allowAddOutput

bool; whether the user is allowed to add outputs by the context menu.

allowRemove

bool; whether the user is allowed to remove this node by the context menu.

addInput(name='Input', **args)[source]

Add a new input terminal to this Node with the given name. Extra keyword arguments are passed to Terminal.__init__.

This is a convenience function that just calls addTerminal(io=’in’, …)

addOutput(name='Output', **args)[source]

Add a new output terminal to this Node with the given name. Extra keyword arguments are passed to Terminal.__init__.

This is a convenience function that just calls addTerminal(io=’out’, …)

addTerminal(name, **opts)[source]

Add a new terminal to this Node with the given name. Extra keyword arguments are passed to Terminal.__init__.

Causes sigTerminalAdded to be emitted.

bypass(byp)[source]

Set whether this node should be bypassed.

When bypassed, a Node’s process() method is never called. In some cases, data is automatically copied directly from specific input nodes to output nodes instead (see the bypass argument to Terminal.__init__). This is usually called when the user disables a node from the flowchart control panel.

close()[source]

Cleans up after the node–removes terminals, graphicsItem, widget

connected(localTerm, remoteTerm)[source]

Called whenever one of this node’s terminals is connected elsewhere.

ctrlWidget()[source]

Return this Node’s control widget.

By default, Nodes have no control widget. Subclasses may reimplement this method to provide a custom widget. This method is called by Flowcharts when they are constructing their Node list.

dependentNodes()[source]

Return the list of nodes which provide direct input to this node

disconnected(localTerm, remoteTerm)[source]

Called whenever one of this node’s terminals is disconnected from another.

graphicsItem()[source]

Return the GraphicsItem for this node. Subclasses may re-implement this method to customize their appearance in the flowchart.

inputValues()[source]

Return a dict of all input values currently assigned to this node.

inputs()[source]

Return dict of all input terminals. Warning: do not modify.

isBypassed()[source]

Return True if this Node is currently bypassed.

name()[source]

Return the name of this node.

nextTerminalName(name)[source]

Return an unused terminal name

outputValues()[source]

Return a dict of all output values currently generated by this node.

outputs()[source]

Return dict of all output terminals. Warning: do not modify.

process(**kargs)[source]

Process data through this node. This method is called any time the flowchart wants the node to process data. It will be called with one keyword argument corresponding to each input terminal, and must return a dict mapping the name of each output terminal to its new value.

This method is also called with a ‘display’ keyword argument, which indicates whether the node should update its display (if it implements any) while processing this data. This is primarily used to disable expensive display operations during batch processing.

processBypassed(args)[source]

Called when the flowchart would normally call Node.process, but this node is currently bypassed. The default implementation looks for output terminals with a bypass connection and returns the corresponding values. Most Node subclasses will _not_ need to reimplement this method.

removeTerminal(term)[source]

Remove the specified terminal from this Node. May specify either the terminal’s name or the terminal itself.

Causes sigTerminalRemoved to be emitted.

rename(name)[source]

Rename this node. This will cause sigRenamed to be emitted.

restoreState(state)[source]

Restore the state of this node from a structure previously generated by saveState().

saveState()[source]

Return a dictionary representing the current state of this node (excluding input / output values). This is used for saving/reloading flowcharts. The default implementation returns this Node’s position, bypass state, and information about each of its terminals.

Subclasses may want to extend this method, adding extra keys to the returned dict.

setInput(**args)[source]

Set the values on input terminals. For most nodes, this will happen automatically through Terminal.inputChanged. This is normally only used for nodes with no connected inputs.

terminalRenamed(term, oldName)[source]

Called after a terminal has been renamed

Causes sigTerminalRenamed to be emitted.

update(signal=True)[source]

Collect all input values, attempt to process new output values, and propagate downstream. Subclasses should call update() whenever thir internal state has changed (such as when the user interacts with the Node’s control widget). Update is automatically called when the inputs to the node are changed.