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

Class CreateGroupCommand

src/commands/create_group_command.py:20–221  ·  view source on GitHub ↗

Command for creating groups with full state preservation and undo/redo support.

Source from the content-addressed store, hash-verified

18
19
20class CreateGroupCommand(CommandBase):
21 """Command for creating groups with full state preservation and undo/redo support."""
22
23 def __init__(self, node_graph, group_properties: Dict[str, Any]):
24 """
25 Initialize create group command.
26
27 Args:
28 node_graph: The NodeGraph instance
29 group_properties: Dictionary containing group configuration:
30 - name: Group name
31 - description: Group description
32 - member_node_uuids: List of member node UUIDs
33 - auto_size: Whether to auto-size the group
34 - padding: Padding around member nodes
35 """
36 super().__init__(f"Create group '{group_properties.get('name', 'Group')}'")
37 self.node_graph = node_graph
38 self.group_properties = group_properties.copy()
39 self.created_group = None
40 self.group_uuid = str(uuid.uuid4())
41
42 # Store creation timestamp
43 self.group_properties["creation_timestamp"] = datetime.now().isoformat()
44
45 def execute(self) -> bool:
46 """Create the group and add to graph."""
47 try:
48 # Import here to avoid circular imports - try different import paths
49 Group = self._get_group_class()
50 if not Group:
51 self._show_error("Failed to import Group class. Please check your installation.")
52 return False
53
54 # Validate that all member nodes exist
55 member_nodes = self._get_member_nodes()
56 if len(member_nodes) != len(self.group_properties["member_node_uuids"]):
57 self._show_error(f"Some member nodes not found. Expected {len(self.group_properties['member_node_uuids'])}, found {len(member_nodes)}. Cannot create group.")
58 return False
59
60 # Create the group
61 self.created_group = Group(
62 name=self.group_properties["name"],
63 member_node_uuids=self.group_properties["member_node_uuids"]
64 )
65
66 # Set properties
67 self.created_group.uuid = self.group_uuid
68 self.created_group.description = self.group_properties.get("description", "")
69 self.created_group.creation_timestamp = self.group_properties["creation_timestamp"]
70 self.created_group.padding = self.group_properties.get("padding", 20.0)
71
72 # Auto-size if requested
73 if self.group_properties.get("auto_size", True):
74 self.created_group.calculate_bounds_from_members(self.node_graph)
75
76 # Add to graph first (needed for connection analysis)
77 self.node_graph.addItem(self.created_group)

Callers 8

executeMethod · 0.90
test_command_creationMethod · 0.90
test_command_executeMethod · 0.90
test_command_undoMethod · 0.90
test_command_redoMethod · 0.90

Calls

no outgoing calls

Tested by 6

test_command_creationMethod · 0.72
test_command_executeMethod · 0.72
test_command_undoMethod · 0.72
test_command_redoMethod · 0.72