1616from NodeGraphQt .base .port import Port
1717from NodeGraphQt .constants import (DRAG_DROP_ID ,
1818 PIPE_LAYOUT_CURVED ,
19- PIPE_LAYOUT_STRAIGHT , PIPE_LAYOUT_ANGLE )
19+ PIPE_LAYOUT_STRAIGHT ,
20+ PIPE_LAYOUT_ANGLE ,
21+ IN_PORT , OUT_PORT )
2022from NodeGraphQt .widgets .viewer import NodeViewer
2123
2224
@@ -73,6 +75,9 @@ def _wire_signals(self):
7375 self ._viewer .node_selected .connect (self ._on_node_selected )
7476 self ._viewer .data_dropped .connect (self ._on_node_data_dropped )
7577
78+ # node events.
79+ self .port_connected .connect (self ._on_port_connected )
80+
7681 def _toggle_tab_search (self ):
7782 """
7883 toggle the tab search widget.
@@ -96,6 +101,22 @@ def _on_property_bin_changed(self, node_id, prop_name, prop_value):
96101 if node .get_property (prop_name ) != prop_value :
97102 node .set_property (prop_name , prop_value )
98103
104+ def _on_port_connected (self , src_port , tgt_port ):
105+ """
106+ called when a port connection has been made.
107+ (executes the "on_input_connected" method on the node.)
108+
109+ Args:
110+ src_port (NodeGraphQt.Port): source port.
111+ tgt_port (NodeGraphQt.Port): target port.
112+ """
113+ if tgt_port .type_ () == IN_PORT :
114+ node = tgt_port .node ()
115+ node .on_input_connected (tgt_port , src_port )
116+ elif tgt_port .type_ () == OUT_PORT :
117+ node = src_port .node ()
118+ node .on_input_connected (src_port , tgt_port )
119+
99120 def _on_node_double_clicked (self , node_id ):
100121 """
101122 called when a node in the viewer is double click.
@@ -177,7 +198,7 @@ def _on_connection_changed(self, disconnected, connected):
177198 return
178199
179200 label = 'connect node(s)' if connected else 'disconnect node(s)'
180- ptypes = {'in' : 'inputs' , 'out' : 'outputs' }
201+ ptypes = {IN_PORT : 'inputs' , OUT_PORT : 'outputs' }
181202
182203 self ._undo_stack .beginMacro (label )
183204 for p1_view , p2_view in disconnected :
@@ -204,7 +225,7 @@ def _on_connection_sliced(self, ports):
204225 """
205226 if not ports :
206227 return
207- ptypes = {'in' : 'inputs' , 'out' : 'outputs' }
228+ ptypes = {IN_PORT : 'inputs' , OUT_PORT : 'outputs' }
208229 self ._undo_stack .beginMacro ('slice connections' )
209230 for p1_view , p2_view in ports :
210231 node1 = self ._model .nodes [p1_view .node .id ]
0 commit comments