Manages execution modes and controls for the node graph.
| 13 | from .graph_executor import GraphExecutor |
| 14 | from core.event_system import LiveGraphExecutor |
| 15 | class ExecutionController: |
| 16 | """Manages execution modes and controls for the node graph.""" |
| 17 | |
| 18 | def __init__(self, graph, output_log, get_venv_path_callback, |
| 19 | main_exec_button: QPushButton, status_label: QLabel, |
| 20 | button_style_callback=None, file_ops=None): |
| 21 | self.graph = graph |
| 22 | self.output_log = output_log |
| 23 | self.get_venv_path_callback = get_venv_path_callback |
| 24 | self.main_exec_button = main_exec_button |
| 25 | self.status_label = status_label |
| 26 | self.file_ops = file_ops |
| 27 | self.button_style_callback = button_style_callback |
| 28 | |
| 29 | # Execution systems |
| 30 | self.executor = GraphExecutor(graph, output_log, get_venv_path_callback) |
| 31 | self.live_executor = LiveGraphExecutor(graph, output_log, get_venv_path_callback) |
| 32 | |
| 33 | # Execution state |
| 34 | self.live_mode = False |
| 35 | self.live_active = False |
| 36 | |
| 37 | # Environment state tracking |
| 38 | self.venv_is_valid = False |
| 39 | self.last_venv_path = None # Cache for environment validation |
| 40 | |
| 41 | # UI update throttling |
| 42 | self._ui_update_in_progress = False |
| 43 | |
| 44 | # Initialize UI |
| 45 | self._update_ui_for_batch_mode() |
| 46 | self._check_environment_validity() |
| 47 | |
| 48 | def on_mode_changed(self, mode_id): |
| 49 | """Handle radio button change between Batch (0) and Live (1) modes.""" |
| 50 | self.live_mode = mode_id == 1 |
| 51 | self.output_log.clear() |
| 52 | |
| 53 | if self.live_mode: |
| 54 | self._update_ui_for_live_mode() |
| 55 | else: |
| 56 | self._update_ui_for_batch_mode() |
| 57 | |
| 58 | def on_main_button_clicked(self): |
| 59 | """Handle the main execution button based on current mode and state.""" |
| 60 | if not self.live_mode: |
| 61 | # Batch mode execution |
| 62 | self._execute_batch_mode() |
| 63 | else: |
| 64 | # Live mode - toggle between start/pause |
| 65 | if not self.live_active: |
| 66 | self._start_live_mode() |
| 67 | else: |
| 68 | self._pause_live_mode() |
| 69 | |
| 70 | def _update_ui_for_batch_mode(self): |
| 71 | """Update UI elements for batch mode.""" |
| 72 | self.live_executor.set_live_mode(False) |