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.
- addNode(path=[], pos=None, geometry=None, uniquename=None, node=None)[source]¶
Add a node to the scene.
- keyboardPress(key, data)[source]¶
Handle keyboard press events from the view. Only lets control modified keys through, except for delete.
- 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
- save(event=None, path=None, customParams=None, save_connected_value=False, save_non_widget_value=True)[source]¶
Save the node chart
- topologicalSort()[source]¶
Sort the dependency tree. Inspired by: http://code.activestate.com/recipes/578272-topological-sort/
NodeWidget Support¶
- class nodeworks.nodewidget.StructureScene(parent=None)[source]¶
Custom QGraphicsScene for structures.
- class nodeworks.nodewidget.GraphicsView(scene: GraphicsScene, parent: None = None)[source]¶
Custom QGraphicsScene.
- class nodeworks.nodewidget.PreviewView(scene: GraphicsScene, parent: NodeWidget | None = None, view: GraphicsView | None = None)[source]¶
Custom QGraphicsScene.
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¶
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 asQtWidgets.QLineEdit
,QtWidgets.QPushButton
, etc.- insert (int):
the position to insert the wiget at.
- 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
- 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.
- 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
- 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
- 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
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)
- mousePressEvent(event)[source]¶
Capture mouse press events and find where the mouse was pressed on the object.
- 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
- 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.
- 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
- 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.
- removeConnection(removeconnection)[source]¶
Remove a specific connection. The connection should already be removed from the scene.
Parameters¶
- removeconnection (Connection):
the connection to be removed.
- 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.
- 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.
- 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.
NodeLibrary¶
The NodeLibrary provides methods for building and maintaining a collection of Nodes that can be added to a network.
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.