API Reference

NodeWidget

The NodeWidget class provides the main entry point to the nodeworks library. The class provides a QWidget that can be inserted into Qt based applications. The NodeWidget contains methods for adding/removing Nodes and Connections as well as saving, loading, exporting, and solving the network.

class nodeworks.nodewidget.NodeWidget(parent: None = None, parentNode: None = None, showtoolbar: bool = True, onlypositivecoords: bool = False, threaded: bool = False, prompt: bool = True)[source]

Main widget for the displaying and editing a Node Chart.

addConnection(from_, to, controlpoints=None)[source]

Add a new connection

addNode(path=[], pos=None, geometry=None, uniquename=None, node=None)[source]

Add a node to the scene.

buildRunOrder()[source]

Process dependencies of Nodes, determine order.

copyNodes(recursive=False)[source]

Copy the currently selected Nodes

cutNodes()[source]

Copies and designates the currently selected Nodes for deletion

deleteAllNodes(confirm=True)[source]

Delete all Nodes.

deleteCopyNodes()[source]

Delete the cut Nodes.

deleteNodes()[source]

Delete the currently selected Nodes.

deselectAll()[source]

Deselect Everything

executeThreaded()[source]

Run the nodes.

keyboardPress(key, data)[source]

Handle keyboard press events from the view. Only lets control modified keys through, except for delete.

keyboardSearch(pos, text=None)[source]

Display a Node search tool when typing.

networkChanged(args=None)[source]

Every time a new connection is made, or widget value changes, run this code.

open(event=None, path=None, nodeDict=None, customParams=None)[source]

Open a node chart or nodeDict

pasteNodes(recursive=False)[source]

Paste the currently copied Nodes.

remove(items)[source]

Delete items from scene

resizeEvent(self, a0: Optional[QResizeEvent])[source]
save(event=None, path=None, customParams=None, save_connected_value=False, save_non_widget_value=True)[source]

Save the node chart

selectAll()[source]

Select Everything

stopRun()[source]

Stop the run

topologicalSort()[source]

Sort the dependency tree. Inspired by: http://code.activestate.com/recipes/578272-topological-sort/

NodeWidget Support

class nodeworks.nodewidget.GraphicsScene(parent=None)[source]

Custom QGraphicsScene.

focusInEvent(self, event: Optional[QFocusEvent])[source]
focusOutEvent(self, event: Optional[QFocusEvent])[source]
mousePressEvent(self, event: Optional[QGraphicsSceneMouseEvent])[source]
mouseReleaseEvent(self, event: Optional[QGraphicsSceneMouseEvent])[source]
class nodeworks.nodewidget.StructureScene(parent=None)[source]

Custom QGraphicsScene for structures.

class nodeworks.nodewidget.GraphicsView(scene: GraphicsScene, parent: None = None)[source]

Custom QGraphicsScene.

keyPressEvent(event)[source]

Handle key press events

leaveEvent(self, a0: Optional[QEvent])[source]
mouseMoveEvent(self, event: Optional[QMouseEvent])[source]
mousePressEvent(event: QMouseEvent)[source]

Catch mouse events.

mouseReleaseEvent(self, event: Optional[QMouseEvent])[source]
save_to_image(fname, scale=1)[source]

Save the image to a file.

wheelEvent(event)[source]

Handle zooming with the mouse wheel.

class nodeworks.nodewidget.PreviewView(scene: GraphicsScene, parent: NodeWidget | None = None, view: GraphicsView | None = None)[source]

Custom QGraphicsScene.

mouseDoubleClickEvent(self, event: Optional[QMouseEvent])[source]
mouseMoveEvent(self, event: Optional[QMouseEvent])[source]
mousePressEvent(self, event: Optional[QMouseEvent])[source]
mouseReleaseEvent(self, event: Optional[QMouseEvent])[source]
resizeEvent(self, event: Optional[QResizeEvent])[source]
class nodeworks.nodewidget.SearchNodeWidget(parent: NodeWidget | None = None, nodelist: List[Any] = [])[source]

Provide a search interface for the nodes

hide(self)[source]
class nodeworks.nodewidget.WorkerThread(function, parent=None)[source]
run(self)[source]

Node

The Node provides the top-level methods for a node.

class nodeworks.node.Node(parent=None, style={})[source]

Main class for a Node.

Parameters

parent (QObject):

parent of the node, typically nodeworks.nodewidget.NodeWidget (default None)

style (dict):

a dictionary describing the style of the node

addMissingTerminal(terminal)[source]

This method is called when options for a terminal exist in the state however, the terminal does not exist in the Node. This method is meant to be overridden.

Parameters

terminal (dict):

a dictionary of options

addTerminal(name, opts={}, insert=None)[source]

Add a terminal to the Node.

Parameters

name (str):

the name of the Terminal, and the index of the Terminal in terminals

opts (dict):

a dictionary of Terminal options (default dict())

insert (int):

the position to insert the Terminal at.

Returns

term (Terminal):

the created terminal

addWidget(widget, insert=None)[source]

Add an arbitrary widget to the Node.

Parameters

widget (QWidget):

the widget to be added to the node. Can be any QtWidgets.QWidget based class such as QtWidgets.QLineEdit, QtWidgets.QPushButton, etc.

insert (int):

the position to insert the wiget at.

clearError()[source]

Clear the Node’s error state, allow to run.

clearRunning()[source]

Set the Node is not running.

collapse(hide=None)[source]

Collapse/expand the node down to only the connected terminals.

Parameters

hide (bool):

a boolean that determines if the terminals should be hidden

dependencies()[source]

Collect and return the dependencies of the Node

Returns

depSet (set):

a set nodes that this node depends on

depsFinished()[source]

Have the dependencies of the Node been processed

Returns

(bool):

are the dependencies finished

errorCheck()[source]

Override this function with code to check for errors.

flipTerminals()[source]

Loop over terminals and flip them to/from left and right

manageTerminals()[source]

This method is called when users select options that need to hide or show terminals based on selected options within the Node. This method is meant to be overridden.

manual_process()[source]

Call this method to run the self.process method threaded.

process()[source]

Override this function with the code to be called when the Node is executed.

removeAllTerminals(inout=None)[source]

Remove all terminals from the Node.

removeConnections()[source]

Remove all connections from the Node.

removeTerminal(name)[source]

Remove the terminal from the Node.

Parameters

name (str):

name of the terminal to be removed

runNode()[source]

Run the node. This function updates connections, clears any errors, checks for errors, finally if there are no errors and the input values have changed, calls the process method

Returns

ran (bool):

False if process was not called (error) else True

setError(message='None', terminal=None)[source]

Set the Node in an error state, will not let Node execute.

Parameters

message (str):

an error message to be displayed for user information

terminal (str):

name of the terminal to highlight in red

setRunning()[source]

Set the Node is running.

setState(state, customParams=None)[source]

Set the state. The uniquename, position, and connections are set through the addNode method of NodeWidget.

Parameters

state (dict):

a dictionary containing information to set the terminal values

setStyle(style=None)[source]

Set the style of the Node, as well as the terminals

Parameters

style (dict):

a dictionary describing the style

setUniqueName(name)[source]

Set the unique name of the node. This name is used in NodeWidget.nodeDict.

Parameters

name (str):

the unique name

showHelpDoc()[source]

Display the help documentation

state(customParams=None, save_connected_value=False, save_non_widget_value=True)[source]

The current state of the node (position, values, connections, path)

Returns

stateDict (dict):

a JSON encodable dictionary

terminalChanged(value)[source]

A function that is called if a value is changed. This enables the node for processing

Parameters

value (Object):

the value to emit with the valueChanged signal

updateInputs()[source]

Loop through terminals, updating inputs

Node Support

class nodeworks.node.NodeGraphic(node, parent=None, style={})[source]

This class handles all the graphics for a Node.

Parameters

node (Node):

the Node that this NodeGraphic is part of

parent (QObject):

parent (default None)

style (dict):

dictionary containing options

Signals

rightClickEvent (QGraphicsEvent):

emits when a user right clicks on a node but not over a Terminal

addTerminal(opts, style={}, insert=None)[source]

Add a terminal to the Node.

Parameters
opts (dict):

a dictionary with options to define the terminal

style (dict):

a dictionary descripting the style of the terminal

insert (int):

the position in the layout to insert the terminal at. Index starts at 0. Thfirst item in the layout is typical the label for the node (default None)

Returns
term (Terminal):

the Terminal that was just created

addTerminalPad(pos=None, connect=True, rect=None, name=None, inout=None, dtype=None, padtype='pass', load=False)[source]

Add an arbitrary terminal pad to the Node

Parameters
pos (QtCore.QPoint):

position where to add the pad (default None)

connect (bool):

True to emit a new connection event (default True)

rect (QtCore.QRectF):

rectangle describing the geometry of the pad (default None)

name (str):

name of the pad (default None)

inout (str):

‘in’ for an input pad, ‘out’ for an output pad.

dtype (type):

dtype of the pad

padtype (str):

type of the pad either ‘pass’, ‘index’, or ‘shift’ for a pass through terminal, an indexed terminal, or a shifted terminal.

addWidget(widget, insert=None)[source]

Allows arbitrary widgets to be added to a Node.

Parameters
widget (QWidget):

the widget to be added

insert (int):

the position in the layout to insert the terminal at. Index starts at 0. Thfirst item in the layout is typical the label for the node (default None)

buildLabelEditWidget()[source]

Create a QLineEdit to edit the Nodes name.

deletePad(pad)[source]

Delete the pad

dropConnectionEvent(scenePos)[source]

Handle Drop Events

hoverEnterEvent(self, event: Optional[QGraphicsSceneHoverEvent])[source]
hoverLeaveEvent(self, event: Optional[QGraphicsSceneHoverEvent])[source]
hoverMoveEvent(self, event: Optional[QGraphicsSceneHoverEvent])[source]
itemChange(self, change: QGraphicsItem.GraphicsItemChange, value: Any) Any[source]
keyPressEvent(self, event: Optional[QKeyEvent])[source]
mouseDoubleClickEvent(event)[source]

Capture double click event

mouseMoveEvent(event)[source]

Handle mouse move events.

mousePressEvent(event)[source]

Capture mouse press events and find where the mouse was pressed on the object.

mouseReleaseEvent(event)[source]

Capture mouse Release events.

moveTo(pos)[source]

Move Node to position.

Parameters
pos (QPointF):

position to move the NodeGraphic to.

paint(self, painter: Optional[QPainter], option: Optional[QStyleOptionGraphicsItem], widget: Optional[QWidget])[source]
removeTerminal(term)[source]

Remove a terminal from the node.

Parameters
term (Terminal):

the terminal object to remove from the NodeGraphic

rename(name)[source]

Rename the node.

Parameters
name (str):

string to change the node name to

resizeToMinimum()[source]

Resize the NodeGraphic to the minimum size allowed by the widgets in the node.

screenPos()[source]

calculates the upper left hand corner of a node regardless of layering of structures

setLabelEditWidget(widget)[source]

Set a QWidget to act as an editor for renaming the node.

Parameters
widget (QWidget):

A QWidget to be called when the user edits the node name. This widget must have a lostFocus signal that is emitted when the widget as a new name to set the Node name to.

setStyle(self, style: Optional[QStyle])[source]
showRightClickMenu(globalpos, otheractions=None)[source]

Creates, configures, and sets right click menu.

Parameters
globalpos (QPoint):

the QPoint object that represents the position of the mouse when the function is called

otheractions (list):

a list of additional QAction items that should be added to the right click menu for the node

update(self, rect: QRectF = QRectF())[source]
update(self, ax: float, ay: float, width: float, height: float) None
updateConnections()[source]

Update Connections

updateTerminalValues()[source]

Update Connections

updateTerminals()[source]

Update Connections

class nodeworks.node.Terminal(opts, node, style={})[source]

This class draws a terminal.

Parameters

opts (dict):

a dictionary of options for a terminal

node (Node):

the Node that this terminal is a part of

style (dict):

a dictionary of terminal options (default {})

Signals

valueChanged(value)

a signal that emits the the current value every time that the value is changed

compare(value1, value2)[source]

Compare two values to see if they are the same. True means the values are NOT equal.

hide(self)[source]
paintEvent(self, a0: Optional[QPaintEvent])[source]
removeAllConnections()[source]

Remove all connections. Called at node delete event.

removeConnection(removeconnection)[source]

Remove a specific connection. The connection should already be removed from the scene.

Parameters
removeconnection (Connection):

the connection to be removed.

setStyle(self, a0: Optional[QStyle])[source]
setValue(value, trigger_update=False)[source]

Set the current value.

show(self)[source]
updateInput()[source]

If there is an input connection, update the value.

property value

The current value.

Connection

The Connection provides connections between Terminals of Nodes

class nodeworks.node.Connection(nodeWidget=None, style=None, parent=None)[source]

This class draws connections between Terminals on Nodes.

boundingRect()[source]

Return the bounding rectangle of the connection.

generatePath(points)[source]

Generate a path following points

Parameters

points (list):

a list of QtCore.QPoint points for the connection line to follow

isConnected()[source]

Check if the connection has both a start and stop terminal. It it does, return True, else return False.

mouseDoubleClickEvent(self, event: Optional[QGraphicsSceneMouseEvent])[source]
mousePressEvent(event)[source]

Capture the mouse press event

Parameters

event ():

mouse event

paint(painter, *args)[source]

Paint the line.

removeConnections()[source]

Remove self from connected Nodes.

removeStartTerm()[source]

Remove the starting terminal

removeStopTerm()[source]

Remove the stop terminal

setStartTerminal(startTerm)[source]

Set the starting terminal for a connection.

setStopTerminal(stopTerm)[source]

Set the starting terminal for a connection.

shape()[source]

Calculate and return the shape of the connection. This shape is used for determining if the mouse is “over” the connection. This is used for mouseEvents and HoverEvents.

state(customParams=None, save_connected_value=False, save_non_widget_value=True)[source]

The current state of the node (position, values, connections, path)

Returns

stateDict (dict):

a JSON encodable dictionary

updateLine(mousePos=None)[source]

Update the line. If mousePos, use as missing point (start, stop).

Parameters

mousePos (QtCore.QPoint):

a position to use as the missing point if

NodeLibrary

The NodeLibrary provides methods for building and maintaining a collection of Nodes that can be added to a network.

class nodeworks.nodelibrary.NodeLibrary[source]

Collection of Nodes

addNode(node, path)[source]

Add a Node to the library

build_default_library()[source]

build the default node library

getNode(path)[source]

Return the node at path

Base Widgets

Base widgets provide unified value and setValue methods as well as ValueChanged Signals for a collection of QWidgets.

Tools

A collection of helper functions.