MCPcopy Index your code
hub / github.com/bhowiebkr/PyFlowGraph / remove_node

Method remove_node

src/core/node_graph.py:544–624  ·  view source on GitHub ↗

Remove a node, optionally using command pattern for undo/redo.

(self, node, use_command=True)

Source from the content-addressed store, hash-verified

542 return node
543
544 def remove_node(self, node, use_command=True):
545 """Remove a node, optionally using command pattern for undo/redo."""
546 print(f"\n=== NODE GRAPH REMOVE_NODE START ===")
547 print(f"DEBUG: remove_node called with use_command={use_command}")
548 print(f"DEBUG: Node to remove: '{getattr(node, 'title', 'Unknown')}' (ID: {id(node)})")
549 print(f"DEBUG: Graph has {len(self.nodes)} nodes before removal")
550 print(f"DEBUG: Scene has {len(self.items())} items before removal")
551
552 if use_command:
553 print(f"DEBUG: Using command pattern for removal")
554 # Use command pattern
555 command = DeleteNodeCommand(self, node)
556 result = self.execute_command(command)
557 print(f"DEBUG: Command execution returned: {result}")
558 print(f"=== NODE GRAPH REMOVE_NODE END (COMMAND) ===\n")
559 return result
560 else:
561 print(f"DEBUG: Direct removal (bypassing command pattern)")
562 # Direct removal (for internal use by commands)
563 # First, remove all connections to/from this node
564 connections_to_remove = []
565 for connection in list(self.connections):
566 if (hasattr(connection, 'start_pin') and connection.start_pin.node == node or
567 hasattr(connection, 'end_pin') and connection.end_pin.node == node):
568 connections_to_remove.append(connection)
569 print(f"DEBUG: Found connection to remove: {connection}")
570
571 print(f"DEBUG: Removing {len(connections_to_remove)} connections first")
572
573 # Remove connections first
574 for connection in connections_to_remove:
575 print(f"DEBUG: Removing connection: {connection}")
576 result = self.remove_connection(connection, use_command=False)
577 print(f"DEBUG: Connection removal returned: {result}")
578
579 # Then remove and destroy all pins
580 if hasattr(node, "pins"):
581 print(f"DEBUG: Node has {len(node.pins)} pins to clean up")
582 for pin in list(node.pins):
583 # Clean up pin without trying to remove connections (already done)
584 print(f"DEBUG: Cleaning up pin: {pin}")
585 pin.connections.clear() # Clear the connections list
586 pin.destroy() # This will safely handle scene removal
587 print(f"DEBUG: Pin cleaned up")
588
589 # Clear all pin lists
590 if hasattr(node, 'pins'):
591 node.pins.clear()
592 print(f"DEBUG: Cleared pins list")
593 if hasattr(node, 'input_pins'):
594 node.input_pins.clear()
595 print(f"DEBUG: Cleared input_pins list")
596 if hasattr(node, 'output_pins'):
597 node.output_pins.clear()
598 print(f"DEBUG: Cleared output_pins list")
599 if hasattr(node, 'execution_pins'):
600 node.execution_pins.clear()
601 print(f"DEBUG: Cleared execution_pins list")

Calls 6

execute_commandMethod · 0.95
remove_connectionMethod · 0.95
DeleteNodeCommandClass · 0.90
clearMethod · 0.80
removeMethod · 0.80
destroyMethod · 0.45