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

Method execute

src/commands/node/basic_operations.py:187–317  ·  view source on GitHub ↗

Delete node after preserving complete state.

(self)

Source from the content-addressed store, hash-verified

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),
227 'color_body': getattr(self.node, 'color_body', None),
228 'color_title_text': getattr(self.node, 'color_title_text', None),
229 # Preserve GUI state
230 'gui_state': {}
231 }
232
233 # Try to capture GUI state if possible
234 try:
235 if hasattr(self.node, 'gui_widgets') and self.node.gui_widgets and self.node.gui_get_values_code:
236 scope = {"widgets": self.node.gui_widgets}
237 exec(self.node.gui_get_values_code, scope)
238 get_values_func = scope.get("get_values")
239 if callable(get_values_func):
240 self.node_state['gui_state'] = get_values_func(self.node.gui_widgets)
241 if DEBUG_NODE_COMMANDS:
242 print(f"DEBUG: Captured GUI state: {self.node_state['gui_state']}")
243 except Exception as e:
244 if DEBUG_NODE_COMMANDS:

Calls 3

_get_pin_indexMethod · 0.95
removeMethod · 0.80
_mark_executedMethod · 0.80