Skip to content

Commit 68a26b9

Browse files
authored
Merge pull request #345 from jchanvfx/accept_constrain_bug_#342
updated port accept validation logic. #342
2 parents dc8fbb6 + 6c8c6ae commit 68a26b9

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

NodeGraphQt/widgets/viewer.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def mousePressEvent(self, event):
467467
# update the recorded node positions.
468468
self._node_positions.update({n: n.xy_pos for n in selection})
469469

470-
# show selection selection marquee.
470+
# show selection marquee.
471471
if self.LMB_state and not items:
472472
rect = QtCore.QRect(self._previous_pos, QtCore.QSize())
473473
rect = rect.normalized()
@@ -893,7 +893,7 @@ def sceneMouseReleaseEvent(self, event):
893893

894894
def _validate_accept_connection(self, from_port, to_port):
895895
"""
896-
Check if a pipe connection is allowed if there are a constrains set
896+
Check if a pipe connection is allowed if there are a constraints set
897897
on the ports.
898898
899899
Args:
@@ -903,27 +903,34 @@ def _validate_accept_connection(self, from_port, to_port):
903903
Returns:
904904
bool: true to allow connection.
905905
"""
906+
accept_validation = []
907+
906908
to_ptype = to_port.port_type
907909
from_ptype = from_port.port_type
908910

909-
to_data = self.accept_connection_types.get(to_port.node.type_) or {}
910-
constraints = to_data.get(to_ptype, {}).get(to_port.name, {})
911-
accept_data = constraints.get(from_port.node.type_, {})
912-
913-
accepted_pnames = accept_data.get(from_ptype)
914-
if accepted_pnames:
915-
if from_port.name in accepted_pnames:
916-
return True
917-
return False
918-
911+
# validate the start.
919912
from_data = self.accept_connection_types.get(from_port.node.type_) or {}
920913
constraints = from_data.get(from_ptype, {}).get(from_port.name, {})
921914
accept_data = constraints.get(to_port.node.type_, {})
915+
accepted_pnames = accept_data.get(to_ptype, {})
916+
if constraints:
917+
if to_port.name in accepted_pnames:
918+
accept_validation.append(True)
919+
else:
920+
accept_validation.append(False)
922921

923-
accepted_pnames = accept_data.get(to_ptype)
924-
if accepted_pnames:
922+
# validate the end.
923+
to_data = self.accept_connection_types.get(to_port.node.type_) or {}
924+
constraints = to_data.get(to_ptype, {}).get(to_port.name, {})
925+
accept_data = constraints.get(from_port.node.type_, {})
926+
accepted_pnames = accept_data.get(from_ptype, {})
927+
if constraints:
925928
if from_port.name in accepted_pnames:
926-
return True
929+
accept_validation.append(True)
930+
else:
931+
accept_validation.append(False)
932+
933+
if False in accept_validation:
927934
return False
928935
return True
929936

examples/nodes/basic_nodes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ def __init__(self):
6767
self.set_color(10, 24, 38)
6868

6969
# create node inputs
70-
self.add_input('in 1')
70+
p = self.add_input('in 1')
71+
p.add_accept_port_type(
72+
port_name='single 1',
73+
port_type='out',
74+
node_type='nodes.basic.BasicNodeB'
75+
)
76+
7177
self.add_input('in 2')
7278
self.add_input('in 3', multi_input=True)
7379
self.add_input('in 4', display_name=False)

0 commit comments

Comments
 (0)