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

Class DeleteNodeCommand

src/commands/node/basic_operations.py:169–613  ·  view source on GitHub ↗

Command for deleting nodes with complete state preservation.

Source from the content-addressed store, hash-verified

167
168
169class DeleteNodeCommand(CommandBase):
170 """Command for deleting nodes with complete state preservation."""
171
172 def __init__(self, node_graph, node):
173 """
174 Initialize delete node command.
175
176 Args:
177 node_graph: The NodeGraph instance
178 node: Node to delete
179 """
180 super().__init__(f"Delete '{node.title}' node")
181 self.node_graph = node_graph
182 self.node = node
183 self.node_state = None
184 self.affected_connections = []
185 self.node_index = None
186
187 def execute(self) -> bool:
188 """Delete node after preserving complete state."""
189 try:
190 # Check if this node object is actually in the nodes list
191 found_in_list = False
192 node_in_list = None
193 for i, node in enumerate(self.node_graph.nodes):
194 if node is self.node: # Same object reference
195 found_in_list = True
196 node_in_list = node
197 self.node_index = i
198 break
199 elif hasattr(node, 'uuid') and hasattr(self.node, 'uuid') and node.uuid == self.node.uuid:
200 # Use the node that's actually in the list (UUID synchronization fix)
201 self.node = node
202 found_in_list = True
203 node_in_list = node
204 self.node_index = i
205 break
206
207 if not found_in_list:
208 print(f"Error: Node '{getattr(self.node, 'title', 'Unknown')}' not found in graph")
209 return False
210
211 # Preserve complete node state including colors and size
212 self.node_state = {
213 'id': self.node.uuid,
214 'title': self.node.title,
215 'description': getattr(self.node, 'description', ''),
216 'position': self.node.pos(),
217 'code': getattr(self.node, 'code', ''),
218 'gui_code': getattr(self.node, 'gui_code', ''),
219 'gui_get_values_code': getattr(self.node, 'gui_get_values_code', ''),
220 'function_name': getattr(self.node, 'function_name', None),
221 'width': getattr(self.node, 'width', 150),
222 'height': getattr(self.node, 'height', 150),
223 'base_width': getattr(self.node, 'base_width', 150),
224 'is_reroute': getattr(self.node, 'is_reroute', False),
225 # Preserve colors
226 'color_title_bar': getattr(self.node, 'color_title_bar', None),

Calls

no outgoing calls