@@ -210,14 +210,15 @@ def connected_ports(self):
210210 ports .append (node .inputs ()[port_name ])
211211 return ports
212212
213- def connect_to (self , port = None , push_undo = True ):
213+ def connect_to (self , port = None , push_undo = True , emit_signal = True ):
214214 """
215215 Create connection to the specified port and emits the
216216 :attr:`NodeGraph.port_connected` signal from the parent node graph.
217217
218218 Args:
219219 port (NodeGraphQt.Port): port object.
220220 push_undo (bool): register the command to the undo stack. (default: True)
221+ emit_signal (bool): emit the port connection signals. (default: True)
221222 """
222223 if not port :
223224 return
@@ -274,64 +275,69 @@ def connect_to(self, port=None, push_undo=True):
274275 if not port :
275276 if pre_conn_port :
276277 if push_undo :
277- undo_stack .push (PortDisconnectedCmd (self , port ))
278+ undo_stack .push (
279+ PortDisconnectedCmd (self , port , emit_signal )
280+ )
278281 undo_stack .push (NodeInputDisconnectedCmd (self , port ))
279282 undo_stack .endMacro ()
280283 else :
281- PortDisconnectedCmd (self , port ).redo ()
284+ PortDisconnectedCmd (self , port , emit_signal ).redo ()
282285 NodeInputDisconnectedCmd (self , port ).redo ()
283286 return
284287
285288 if graph .acyclic () and viewer .acyclic_check (self .view , port .view ):
286289 if pre_conn_port :
287290 if push_undo :
288- undo_stack .push (PortDisconnectedCmd (self , pre_conn_port ))
291+ undo_stack .push (
292+ PortDisconnectedCmd (self , pre_conn_port , emit_signal )
293+ )
289294 undo_stack .push (NodeInputDisconnectedCmd (
290- self , pre_conn_port ))
295+ self , pre_conn_port )
296+ )
291297 undo_stack .endMacro ()
292298 else :
293- PortDisconnectedCmd (self , pre_conn_port ).redo ()
299+ PortDisconnectedCmd (self , pre_conn_port , emit_signal ).redo ()
294300 NodeInputDisconnectedCmd (self , pre_conn_port ).redo ()
295301 return
296302
297303 trg_conn_ports = port .connected_ports ()
298304 if not port .multi_connection () and trg_conn_ports :
299305 dettached_port = trg_conn_ports [0 ]
300306 if push_undo :
301- undo_stack .push (PortDisconnectedCmd (port , dettached_port ))
307+ undo_stack .push (
308+ PortDisconnectedCmd (port , dettached_port , emit_signal )
309+ )
302310 undo_stack .push (NodeInputDisconnectedCmd (port , dettached_port ))
303311 else :
304- PortDisconnectedCmd (port , dettached_port ).redo ()
312+ PortDisconnectedCmd (port , dettached_port , emit_signal ).redo ()
305313 NodeInputDisconnectedCmd (port , dettached_port ).redo ()
306314 if pre_conn_port :
307315 if push_undo :
308- undo_stack .push (PortDisconnectedCmd (self , pre_conn_port ))
316+ undo_stack .push (
317+ PortDisconnectedCmd (self , pre_conn_port , emit_signal )
318+ )
309319 undo_stack .push (NodeInputDisconnectedCmd (self , pre_conn_port ))
310320 else :
311- PortDisconnectedCmd (self , pre_conn_port ).redo ()
321+ PortDisconnectedCmd (self , pre_conn_port , emit_signal ).redo ()
312322 NodeInputDisconnectedCmd (self , pre_conn_port ).redo ()
313323
314324 if push_undo :
315- undo_stack .push (PortConnectedCmd (self , port ))
325+ undo_stack .push (PortConnectedCmd (self , port , emit_signal ))
316326 undo_stack .push (NodeInputConnectedCmd (self , port ))
317327 undo_stack .endMacro ()
318328 else :
319- PortConnectedCmd (self , port ).redo ()
329+ PortConnectedCmd (self , port , emit_signal ).redo ()
320330 NodeInputConnectedCmd (self , port ).redo ()
321331
322- # emit "port_connected" signal from the parent graph.
323- ports = {p .type_ (): p for p in [self , port ]}
324- graph .port_connected .emit (ports [PortTypeEnum .IN .value ],
325- ports [PortTypeEnum .OUT .value ])
326-
327- def disconnect_from (self , port = None , push_undo = True ):
332+ def disconnect_from (self , port = None , push_undo = True , emit_signal = True ):
328333 """
329334 Disconnect from the specified port and emits the
330335 :attr:`NodeGraph.port_disconnected` signal from the parent node graph.
331336
332337 Args:
333338 port (NodeGraphQt.Port): port object.
334339 push_undo (bool): register the command to the undo stack. (default: True)
340+ emit_signal (bool): emit the port connection signals. (default: True)
335341 """
336342 if not port :
337343 return
@@ -344,19 +350,14 @@ def disconnect_from(self, port=None, push_undo=True):
344350 graph = self .node ().graph
345351 if push_undo :
346352 graph .undo_stack ().beginMacro ('disconnect port' )
347- graph .undo_stack ().push (PortDisconnectedCmd (self , port ))
353+ graph .undo_stack ().push (PortDisconnectedCmd (self , port , emit_signal ))
348354 graph .undo_stack ().push (NodeInputDisconnectedCmd (self , port ))
349355 graph .undo_stack ().endMacro ()
350356 else :
351- PortDisconnectedCmd (self , port ).redo ()
357+ PortDisconnectedCmd (self , port , emit_signal ).redo ()
352358 NodeInputDisconnectedCmd (self , port ).redo ()
353359
354- # emit "port_disconnected" signal from the parent graph.
355- ports = {p .type_ (): p for p in [self , port ]}
356- graph .port_disconnected .emit (ports [PortTypeEnum .IN .value ],
357- ports [PortTypeEnum .OUT .value ])
358-
359- def clear_connections (self , push_undo = True ):
360+ def clear_connections (self , push_undo = True , emit_signal = True ):
360361 """
361362 Disconnect from all port connections and emit the
362363 :attr:`NodeGraph.port_disconnected` signals from the node graph.
@@ -368,6 +369,7 @@ def clear_connections(self, push_undo=True):
368369
369370 Args:
370371 push_undo (bool): register the command to the undo stack. (default: True)
372+ emit_signal (bool): emit the port connection signals. (default: True)
371373 """
372374 if self .locked ():
373375 err = 'Can\' t clear connections because port "{}" is locked.'
@@ -381,17 +383,20 @@ def clear_connections(self, push_undo=True):
381383 undo_stack = graph .undo_stack ()
382384 undo_stack .beginMacro ('"{}" clear connections' )
383385 for cp in self .connected_ports ():
384- self .disconnect_from (cp )
386+ self .disconnect_from (cp , emit_signal = emit_signal )
385387 undo_stack .endMacro ()
386- else :
387- for cp in self .connected_ports ():
388- self .disconnect_from (cp , push_undo = False )
388+ return
389+
390+ for cp in self .connected_ports ():
391+ self .disconnect_from (
392+ cp , push_undo = False , emit_signal = emit_signal
393+ )
389394
390395 def add_accept_port_type (self , port_name , port_type , node_type ):
391396 """
392- Add a constrain to "accept" a pipe connection.
397+ Add a constraint to "accept" a pipe connection.
393398
394- Once a constrain has been added only ports of that type specified will
399+ Once a constraint has been added only ports of that type specified will
395400 be allowed a pipe connection.
396401
397402 `Implemented in` ``v0.6.0``
@@ -406,7 +411,7 @@ def add_accept_port_type(self, port_name, port_type, node_type):
406411 node_type (str): port node type.
407412 """
408413 # storing the connection constrain at the graph level instead of the
409- # port level so we don't serialize the same data for every port
414+ # port level, so we don't serialize the same data for every port
410415 # instance.
411416 self .node ().add_accept_port_type (
412417 port = self ,
@@ -432,9 +437,9 @@ def accepted_port_types(self):
432437
433438 def add_reject_port_type (self , port_name , port_type , node_type ):
434439 """
435- Add a constrain to "reject" a pipe connection.
440+ Add a constraint to "reject" a pipe connection.
436441
437- Once a constrain has been added only ports of that type specified will
442+ Once a constraint has been added only ports of that type specified will
438443 be rejected a pipe connection.
439444
440445 `Implemented in` ``v0.6.0``
0 commit comments