Node and Flowchart core elements

Node essentials: the node module

node.py

Contains the base class for Nodes.

class plottr.node.node.Node(name)

Base class of the Node we use for plotter.

This class inherits from pyqtgraph’s Node, and adds a few additional tools, and some defaults.

ctrlWidget()

Returns the node widget, if it exists.

Return type

Optional[QWidget]

dataAxesChanged

signal emitted when available data axes change emits a the list of names of new axes

dataDependentsChanged

signal emitted when available dependents change emits a the list of names of new dependents

dataFieldsChanged

signal emitted when any available data fields change (dep. and indep.) emits a the list of names of new axes

dataShapesChanged

signal emitted when data shapes change

dataStructureChanged

signal emitted when data structure changes (fields, or dtype)

dataTypeChanged

signal emitted when data type changes

logger()

Get a logger for this node

Return type

Logger

Returns

logger with a name that can be traced back easily to this node.

newDataStructure

when data structure changes, emits (structure, shapes, type)

nodeName = 'Node'

Name of the node. used in the flowchart node library.

optionChangeNotification

A signal to notify the UI of option changes arguments is a dictionary of options and new values.

process(dataIn=None)

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.

Return type

Optional[Dict[str, Optional[DataDictBase]]]

setOption(nameAndVal)

Set an option.

name is the name of the property, not the string used for referencing (which could in principle be different).

Parameters

nameAndVal (Tuple[str, Any]) – tuple of option name and new value

Return type

None

setOptions(opts)

Set multiple options.

Parameters

opts (Dict[str, Any]) – a dictionary of property name : value pairs.

Return type

None

setupUi()

setting up the UI widget.

Gets called automatically in the node initialization. Automatically connect the UIs methods to signal option values.

Inheriting classes can use this method to do additional setup of the UI widget (like connecting additional signals/slots between node and node widget).

Return type

None

terminals = {'dataIn': {'io': 'in'}, 'dataOut': {'io': 'out'}}

one input and one output.

Type

Default terminals

uiClass: Optional[Type[NodeWidget]] = None

UI node widget class. If not None, and useUi is True, an instance of the widget is created, and signal/slots are connected.

uiVisibleByDefault = False

Whether the ui should be visible by default

update(signal=True)

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.

Return type

None

useUi = True

Whether or not to automatically set up a UI widget.

validateOptions(data)

Validate the user options

Does nothing in this base implementation. Can be reimplemented by any inheriting class.

Parameters

data (DataDictBase) – the data to verify the options against.

Return type

bool

class plottr.node.node.NodeWidget(parent=None, embedWidgetClass=None, node=None)

Base class for Node control widgets.

For the widget class to set up communication with the Node automatically, make sure to set plottr.node.node.NodeWidget.optGetters and plottr.node.node.NodeWidget.optSetters for a widget class.

allOptionsToNode

(object)) all options to the node.

Type

signal (args

getAllOptions()

Return all options as a dictionary

Return type

Dict[str, Any]

icon: Optional[PyQt5.QtGui.QIcon] = None

icon for this node

optionToNode

object)) to emit to notify the node of a (changed) user option.

Type

signal (args

preferredDockWidgetArea = 1

preferred location of the widget when used as dock widget

setOptionFromNode(opt, value)

Set an option from the node

Calls the set function specified in the class’ optSetters. Decorated with @updateGuiFromNode.

Parameters
  • opt (str) – name of the option

  • value (Any) – value to set

Return type

None

setOptionsFromNode(opts)

Set all options without triggering updates back to the node.

Return type

None

signalAllOptions()

Return all options as a dictionary

Decorated with @emitGuiUpdate('optionToNode').

Return type

Dict[str, Any]

signalOption(name)

Returns name and value of an option.

Value is determined from the optGetters. Decorated with @emitGuiUpdate('optionToNode').

Parameters

name (str) – name of the option

Return type

Tuple[str, Any]

plottr.node.node.emitGuiUpdate(signalName)

Decorator for UI functions to emit the signal signalName (given as argument the decorator), with the return of the wrapped function.

Signal is only emitted if the flag controlled by updateGuiFromNode is not True, i.e., if the option change was not caused by a function decorated with updateGuiFromNode.

Parameters

signalName (str) – name of the signal to emit.

Return type

Callable[[Callable[…, Any]], Callable[…, None]]

plottr.node.node.updateGuiFromNode(func)

Decorator for the UI to set an internal flag to during execution of the wrapped function. Prevents recursive updating (i.e., if the node sends a new option value to the UI for updating, the UI will then not notify the node back after making the update).

Return type

Callable[…, ~V]

plottr.node.node.updateGuiQuietly(func)

Decorator for the UI to set an internal flag to during execution of the wrapped function. Prevents recursive updating (i.e., if the node sends a new option value to the UI for updating, the UI will then not notify the node back after making the update).

Return type

Callable[…, ~V]

plottr.node.node.updateOption(optName=None)

Decorator for property setters that are handy for user options.

Property setters in nodes that are decorated with this will do two things: * call Node.update, in order to update the flowchart. * if there is a UI, we call the matching optSetter function.

Parameters

optName (Optional[str]) – name of the property.

Return type

Callable[[Callable[[~R, ~S], ~T]], Callable[[~R, ~S], ~T]]