|
1 | 1 | Node Examples |
2 | 2 | ############# |
| 3 | + |
| 4 | +Creating Nodes |
| 5 | +************** |
| 6 | + |
| 7 | +| Creating is done simply by calling the :func:`NodeGraphQt.NodeGraph.create_node` function. |
| 8 | +| (`see example below` ``line22``) |
| 9 | +
|
| 10 | +.. code-block:: python |
| 11 | + :linenos: |
| 12 | +
|
| 13 | + from NodeGraphQt import BaseNode, NodeGraph, QtWidgets |
| 14 | +
|
| 15 | + class MyNode(BaseNode): |
| 16 | +
|
| 17 | + __identifier__ = 'com.chantasticvfx' |
| 18 | + NODE_NAME = 'my node' |
| 19 | +
|
| 20 | + def __init__(self): |
| 21 | + super(MyNode, self).__init__() |
| 22 | + self.add_input('foo') |
| 23 | + self.add_input('hello') |
| 24 | + self.add_output('bar') |
| 25 | + self.add_output('world') |
| 26 | +
|
| 27 | + if __name__ == '__main__': |
| 28 | + app = QtWidgets.QApplication([]) |
| 29 | +
|
| 30 | + node_graph = NodeGraph() |
| 31 | + node_graph.register_node(MyNode) |
| 32 | + node_graph.widget.show() |
| 33 | +
|
| 34 | + # here we create a couple nodes in the node graph. |
| 35 | + node_a = node_graph.create_node('com.chantasticvfx.MyNode', name='node a') |
| 36 | + node_b = node_graph.create_node('com.chantasticvfx.MyNode', name='node b', pos=[300, 100]) |
| 37 | +
|
| 38 | + app.exec_() |
| 39 | +
|
| 40 | +
|
| 41 | +Connecting Nodes |
| 42 | +**************** |
| 43 | + |
| 44 | +There a multiple ways for connecting node ports here are a few examples below. |
| 45 | + |
| 46 | +connecting nodes by the port index: |
| 47 | + |
| 48 | +.. code-block:: python |
| 49 | +
|
| 50 | + node_b.set_input(0, node_a.output(0)) |
| 51 | +
|
| 52 | +connect nodes by the port name: |
| 53 | + |
| 54 | +.. code-block:: python |
| 55 | +
|
| 56 | + node_a.outputs()['bar'].connect_to(node_b.inputs()['foo']) |
| 57 | +
|
| 58 | +connecting nodes with the port objects: |
| 59 | + |
| 60 | +.. code-block:: python |
| 61 | +
|
| 62 | + # node_a "bar" output port. |
| 63 | + port_a = node_a.output(0) |
| 64 | + # node_b "foo" input port. |
| 65 | + port_b = node_b.inputs()['foo'] |
| 66 | + # make the connection. |
| 67 | + port_a.connect_to(port_b) |
| 68 | +
|
| 69 | +
|
| 70 | +See functions: |
| 71 | + - :func:`NodeGraphQt.BaseNode.input`, |
| 72 | + - :func:`NodeGraphQt.BaseNode.output` |
| 73 | + - :func:`NodeGraphQt.BaseNode.set_input`, |
| 74 | + - :func:`NodeGraphQt.BaseNode.set_output`, |
| 75 | + - :func:`NodeGraphQt.BaseNode.inputs`, |
| 76 | + - :func:`NodeGraphQt.BaseNode.outputs` |
| 77 | + - :func:`NodeGraphQt.Port.connect_to`, |
| 78 | + - :func:`NodeGraphQt.Port.disconnect_from` |
| 79 | + |
| 80 | + |
| 81 | +Properties Bin Setup |
| 82 | +******************** |
| 83 | + |
0 commit comments