Skip to content

Commit a4e11f7

Browse files
committed
documentation and clean up #285
1 parent 42cc7f7 commit a4e11f7

File tree

3 files changed

+101
-20
lines changed

3 files changed

+101
-20
lines changed

NodeGraphQt/base/port.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,23 @@ def clear_connections(self, push_undo=True):
378378
for cp in self.connected_ports():
379379
self.disconnect_from(cp, push_undo=False)
380380

381-
def add_accept_port_type(self, port_name, port_type, port_node_type):
381+
def add_accept_port_type(self, port_name, port_type, node_type):
382382
"""
383383
Add a constrain to "accept" a pipe connection.
384384
385385
Once a constrain has been added only ports of that type specified will
386386
be allowed a pipe connection.
387387
388+
`Implemented in` ``v0.6.0``
389+
388390
See Also:
389391
:meth:`NodeGraphQt.Port.add_reject_ports_type`,
390392
:meth:`NodeGraphQt.BaseNode.add_accept_port_type`
391393
392394
Args:
393395
port_name (str): name of the port.
394396
port_type (str): port type.
395-
port_node_type (str): port node type.
397+
node_type (str): port node type.
396398
"""
397399
# storing the connection constrain at the graph level instead of the
398400
# port level so we don't serialize the same data for every port
@@ -402,7 +404,7 @@ def add_accept_port_type(self, port_name, port_type, port_node_type):
402404
port_type_data={
403405
'port_name': port_name,
404406
'port_type': port_type,
405-
'node_type': port_node_type,
407+
'node_type': node_type,
406408
}
407409
)
408410

@@ -419,21 +421,23 @@ def accepted_port_types(self):
419421
"""
420422
return self.node().accepted_port_types(self)
421423

422-
def add_reject_port_type(self, port_name, port_type, port_node_type):
424+
def add_reject_port_type(self, port_name, port_type, node_type):
423425
"""
424426
Add a constrain to "reject" a pipe connection.
425427
426428
Once a constrain has been added only ports of that type specified will
427429
be rejected a pipe connection.
428430
431+
`Implemented in` ``v0.6.0``
432+
429433
See Also:
430434
:meth:`NodeGraphQt.Port.add_accept_ports_type`,
431435
:meth:`NodeGraphQt.BaseNode.add_reject_port_type`
432436
433437
Args:
434438
port_name (str): name of the port.
435439
port_type (str): port type.
436-
port_node_type (str): port node type.
440+
node_type (str): port node type.
437441
"""
438442
# storing the connection constrain at the graph level instead of the
439443
# port level so we don't serialize the same data for every port
@@ -443,7 +447,7 @@ def add_reject_port_type(self, port_name, port_type, port_node_type):
443447
port_type_data={
444448
'port_name': port_name,
445449
'port_type': port_type,
446-
'node_type': port_node_type,
450+
'node_type': node_type,
447451
}
448452
)
449453

NodeGraphQt/nodes/base_node.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -664,16 +664,22 @@ def add_accept_port_type(self, port, port_type_data):
664664
Once a constrain has been added only ports of that type specified will
665665
be allowed a pipe connection.
666666
667+
port type data example
668+
669+
.. highlight:: python
670+
.. code-block:: python
671+
{
672+
'port_name': 'foo'
673+
'port_type': PortTypeEnum.IN.value
674+
'node_type': 'io.github.jchanvfx.NodeClass'
675+
}
676+
677+
See Also:
678+
:meth:`NodeGraphQt.BaseNode.accepted_port_types`
679+
667680
Args:
668681
port (NodeGraphQt.Port): port to assign constrain to.
669682
port_type_data (dict): port type data to accept a connection
670-
eg.
671-
.. code-block:: python
672-
{
673-
'port_name': 'test 1'
674-
'port_type': PortTypeEnum.IN.value
675-
'node_type': 'io.github.jchanvfx.ExampleNode'
676-
}
677683
"""
678684
node_ports = self._inputs + self._outputs
679685
if port not in node_ports:
@@ -717,16 +723,22 @@ def add_reject_port_type(self, port, port_type_data):
717723
Once a constrain has been added only ports of that type specified will
718724
NOT be allowed a pipe connection.
719725
726+
port type data example
727+
728+
.. highlight:: python
729+
.. code-block:: python
730+
{
731+
'port_name': 'foo'
732+
'port_type': PortTypeEnum.IN.value
733+
'node_type': 'io.github.jchanvfx.NodeClass'
734+
}
735+
736+
See Also:
737+
:meth:`NodeGraphQt.Port.rejected_port_types`
738+
720739
Args:
721740
port (NodeGraphQt.Port): port to assign constrain to.
722741
port_type_data (dict): port type data to reject a connection
723-
eg.
724-
.. code-block:: python
725-
{
726-
'port_name': 'test 1'
727-
'port_type': PortTypeEnum.IN.value
728-
'node_type': 'io.github.jchanvfx.ExampleNode'
729-
}
730742
"""
731743
node_ports = self._inputs + self._outputs
732744
if port not in node_ports:

docs/examples/ex_port.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,68 @@ And here's another example function for drawing a Square port.
141141
painter.drawRect(rect)
142142
143143
painter.restore()
144+
145+
146+
Connection Constrains
147+
*********************
148+
149+
From version ``v0.6.0`` port object can now have pipe connection constraints the functions implemented are:
150+
151+
:meth:`NodeGraphQt.Port.add_accept_ports_type` and :meth:`NodeGraphQt.Port.add_reject_ports_type`
152+
153+
this can also be set on the ``BaseNode`` level as well with:
154+
:meth:`NodeGraphQt.BaseNode.add_accept_port_type`, :meth:`NodeGraphQt.BaseNode.add_accept_port_type`
155+
156+
Here's an example snippet to add pipe connection constraints to a port.
157+
158+
.. code-block:: python
159+
:linenos:
160+
161+
from NodeGraphQt import BaseNode
162+
from NodeGraphQt.constants import PortTypeEnum
163+
164+
165+
class BasicNodeA(BaseNode):
166+
167+
# unique node identifier.
168+
__identifier__ = 'io.github.jchanvfx'
169+
170+
# initial default node name.
171+
NODE_NAME = 'node A'
172+
173+
def __init__(self):
174+
super(BasicNode, self).__init__()
175+
176+
# create node output ports.
177+
self.add_output('output 1')
178+
self.add_output('output 2')
179+
180+
181+
class BasicNodeB(BaseNode):
182+
183+
# unique node identifier.
184+
__identifier__ = 'io.github.jchanvfx'
185+
186+
# initial default node name.
187+
NODE_NAME = 'node B'
188+
189+
def __init__(self):
190+
super(BasicNode, self).__init__()
191+
192+
# create node inputs.
193+
194+
# port "in A" will only accept pipe connections from port "output 1" under the node "BasicNodeA".
195+
in_port_a = self.add_input('in A')
196+
in_port_a.add_accept_port_type(
197+
port_name='output 1',
198+
port_type=PortTypeEnum.OUT.value,
199+
node_type='io.github.jchanvfx.BasicNodeA'
200+
)
201+
202+
# port "in A" will reject pipe connections from port "output 1" under the node "BasicNodeA".
203+
in_port_b = self.add_input('in B')
204+
in_port_b.add_reject_port_type(
205+
port_name='output 1',
206+
port_type=PortTypeEnum.OUT.value,
207+
node_type='io.github.jchanvfx.BasicNodeA'
208+
)

0 commit comments

Comments
 (0)