Restore node with complete state and reconnections.
(self)
| 317 | return False |
| 318 | |
| 319 | def undo(self) -> bool: |
| 320 | """Restore node with complete state and reconnections.""" |
| 321 | if not self.node_state: |
| 322 | print(f"Error: No node state to restore") |
| 323 | return False |
| 324 | |
| 325 | try: |
| 326 | # Import here to avoid circular imports |
| 327 | from core.node import Node |
| 328 | from PySide6.QtGui import QColor |
| 329 | |
| 330 | # Use local debug configuration |
| 331 | debug_enabled = DEBUG_NODE_COMMANDS |
| 332 | |
| 333 | # Recreate node with preserved state - check if it was a RerouteNode |
| 334 | if self.node_state.get('is_reroute', False): |
| 335 | # Recreate as RerouteNode |
| 336 | from core.reroute_node import RerouteNode |
| 337 | restored_node = RerouteNode() |
| 338 | restored_node.uuid = self.node_state['id'] |
| 339 | restored_node.setPos(self.node_state['position']) |
| 340 | # RerouteNodes don't have most of the properties that regular nodes have |
| 341 | else: |
| 342 | # Recreate as regular Node |
| 343 | restored_node = Node(self.node_state['title']) |
| 344 | restored_node.uuid = self.node_state['id'] |
| 345 | restored_node.description = self.node_state['description'] |
| 346 | restored_node.setPos(self.node_state['position']) |
| 347 | # Set code which will trigger pin updates |
| 348 | restored_node.set_code(self.node_state['code']) |
| 349 | # Set GUI code which will trigger GUI rebuild |
| 350 | restored_node.set_gui_code(self.node_state['gui_code']) |
| 351 | restored_node.set_gui_get_values_code(self.node_state['gui_get_values_code']) |
| 352 | restored_node.function_name = self.node_state['function_name'] |
| 353 | |
| 354 | # Only apply regular node properties if it's not a RerouteNode |
| 355 | if not self.node_state.get('is_reroute', False): |
| 356 | if debug_enabled: |
| 357 | print(f"DEBUG: Restoring regular node properties for '{self.node_state['title']}'") |
| 358 | print(f"DEBUG: Original size: {self.node_state['width']}x{self.node_state['height']}") |
| 359 | # Restore size BEFORE updating pins (important for layout) |
| 360 | restored_node.width = self.node_state['width'] |
| 361 | restored_node.height = self.node_state['height'] |
| 362 | restored_node.base_width = self.node_state['base_width'] |
| 363 | |
| 364 | # Restore colors |
| 365 | if self.node_state['color_title_bar']: |
| 366 | if isinstance(self.node_state['color_title_bar'], str): |
| 367 | restored_node.color_title_bar = QColor(self.node_state['color_title_bar']) |
| 368 | else: |
| 369 | restored_node.color_title_bar = self.node_state['color_title_bar'] |
| 370 | |
| 371 | if self.node_state['color_body']: |
| 372 | if isinstance(self.node_state['color_body'], str): |
| 373 | restored_node.color_body = QColor(self.node_state['color_body']) |
| 374 | else: |
| 375 | restored_node.color_body = self.node_state['color_body'] |
| 376 |