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

Class CreateNodeCommand

src/commands/node/basic_operations.py:24–166  ·  view source on GitHub ↗

Command for creating nodes with full state preservation.

Source from the content-addressed store, hash-verified

22
23
24class CreateNodeCommand(CommandBase):
25 """Command for creating nodes with full state preservation."""
26
27 def __init__(self, node_graph, title: str, position: QPointF,
28 node_id: str = None, code: str = "", description: str = "",
29 size: list = None, colors: dict = None, gui_state: dict = None,
30 gui_code: str = "", gui_get_values_code: str = "", is_reroute: bool = False):
31 """
32 Initialize create node command.
33
34 Args:
35 node_graph: The NodeGraph instance
36 title: Node title/type
37 position: Position to create node at
38 node_id: Optional specific node ID (for undo consistency)
39 code: Initial code for the node
40 description: Node description
41 size: Node size as [width, height]
42 colors: Node colors as {"title": "#color", "body": "#color"}
43 gui_state: GUI widget states
44 gui_code: GUI definition code
45 gui_get_values_code: GUI state handler code
46 is_reroute: Whether this is a reroute node
47 """
48 super().__init__(f"Create '{title}' node")
49 self.node_graph = node_graph
50 self.title = title
51 self.position = position
52 self.node_id = node_id or str(uuid.uuid4())
53 self.code = code
54 self.node_description = description
55 self.size = size or [200, 150]
56 self.colors = colors or {}
57 self.gui_state = gui_state or {}
58 self.gui_code = gui_code
59 self.gui_get_values_code = gui_get_values_code
60 self.is_reroute = is_reroute
61 self.created_node = None
62
63 def execute(self) -> bool:
64 """Create the node and add to graph."""
65 try:
66 if self.is_reroute:
67 # Create reroute node
68 self.created_node = self.node_graph.create_node("", pos=(self.position.x(), self.position.y()), is_reroute=True, use_command=False)
69 self.created_node.uuid = self.node_id
70 else:
71 # Import here to avoid circular imports
72 from core.node import Node
73
74 # Create the node
75 self.created_node = Node(self.title)
76 self.created_node.uuid = self.node_id
77 self.created_node.description = self.node_description
78 self.created_node.setPos(self.position)
79
80 # Set code first so pins are generated
81 if self.code:

Callers 4

create_nodeMethod · 0.90
test_create_node_undoMethod · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by 2

test_create_node_undoMethod · 0.72