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

Class DeleteGroupCommand

src/commands/delete_group_command.py:20–171  ·  view source on GitHub ↗

Command for deleting groups with complete state preservation.

Source from the content-addressed store, hash-verified

18
19
20class DeleteGroupCommand(CommandBase):
21 """Command for deleting groups with complete state preservation."""
22
23 def __init__(self, node_graph, group):
24 """
25 Initialize delete group command.
26
27 Args:
28 node_graph: The NodeGraph instance
29 group: Group to delete
30 """
31 super().__init__(f"Delete group '{group.name}'")
32 self.node_graph = node_graph
33 self.group = group
34 self.group_state = None
35 self.group_index = None
36
37 def execute(self) -> bool:
38 """Delete group after preserving complete state."""
39 try:
40 # Find group in the graph's groups list
41 found_in_list = False
42 for i, group in enumerate(getattr(self.node_graph, 'groups', [])):
43 if group is self.group: # Same object reference
44 found_in_list = True
45 self.group_index = i
46 break
47 elif hasattr(group, 'uuid') and hasattr(self.group, 'uuid') and group.uuid == self.group.uuid:
48 # Use the group that's actually in the list (UUID synchronization fix)
49 self.group = group
50 found_in_list = True
51 self.group_index = i
52 break
53
54 if not found_in_list:
55 print(f"Warning: Group '{getattr(self.group, 'name', 'Unknown')}' not found in graph groups list")
56 # Still try to remove from scene if it exists there
57
58 # Preserve complete group state for restoration
59 self.group_state = {
60 'uuid': self.group.uuid,
61 'name': self.group.name,
62 'description': getattr(self.group, 'description', ''),
63 'member_node_uuids': self.group.member_node_uuids.copy(),
64 'position': self.group.pos(),
65 'width': self.group.width,
66 'height': self.group.height,
67 'padding': getattr(self.group, 'padding', 20.0),
68 'creation_timestamp': getattr(self.group, 'creation_timestamp', ''),
69 'is_expanded': getattr(self.group, 'is_expanded', True),
70 # Preserve colors
71 'color_background': getattr(self.group, 'color_background', None),
72 'color_border': getattr(self.group, 'color_border', None),
73 'color_title_bg': getattr(self.group, 'color_title_bg', None),
74 'color_title_text': getattr(self.group, 'color_title_text', None),
75 'color_selection': getattr(self.group, 'color_selection', None)
76 }
77

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected