MCPcopy Create free account
hub / github.com/bhowiebkr/PyFlowGraph / undo

Method undo

src/commands/node/basic_operations.py:126–158  ·  view source on GitHub ↗

Remove the created node.

(self)

Source from the content-addressed store, hash-verified

124 return False
125
126 def undo(self) -> bool:
127 """Remove the created node."""
128 if not self.created_node or self.created_node not in self.node_graph.nodes:
129 return False
130
131 try:
132 # Remove all connections to this node first
133 connections_to_remove = []
134 for connection in list(self.node_graph.connections):
135 if (hasattr(connection, 'start_pin') and connection.start_pin.node == self.created_node or
136 hasattr(connection, 'end_pin') and connection.end_pin.node == self.created_node):
137 connections_to_remove.append(connection)
138
139 for connection in connections_to_remove:
140 # Remove from connections list first
141 if connection in self.node_graph.connections:
142 self.node_graph.connections.remove(connection)
143 # Remove from scene if it's still there
144 if connection.scene() == self.node_graph:
145 self.node_graph.removeItem(connection)
146
147 # Remove node from graph
148 if self.created_node in self.node_graph.nodes:
149 self.node_graph.nodes.remove(self.created_node)
150 if self.created_node.scene() == self.node_graph:
151 self.node_graph.removeItem(self.created_node)
152
153 self._mark_undone()
154 return True
155
156 except Exception as e:
157 print(f"Failed to undo node creation: {e}")
158 return False
159
160 def get_memory_usage(self) -> int:
161 """Estimate memory usage of this command."""

Callers 1

test_create_node_undoMethod · 0.95

Calls 2

removeMethod · 0.80
_mark_undoneMethod · 0.80

Tested by 1

test_create_node_undoMethod · 0.76