diff --git a/src/gui/main_window.py b/src/gui/main_window.py index 7df3855..b6a9fee 100644 --- a/src/gui/main_window.py +++ b/src/gui/main_window.py @@ -82,6 +82,7 @@ class MainWindow(ctk.CTk): self._zynq_jtag_present: bool = False self._zynq_jtag_info = None self._uart_monitor: UartMonitor | None = None + self._uart_window: UartMonitorWindow | None = None self._flash_phase: str = "" # StringVar references for config sync @@ -1148,6 +1149,12 @@ class MainWindow(ctk.CTk): def _start_uart_monitor(self) -> None: """Start background serial monitoring if UART is available.""" + # If UART window is already monitoring, don't start a second instance + if (self._uart_window + and self._uart_window.winfo_exists() + and self._uart_window.is_monitoring): + self._log_message(" [UART] Already monitoring via UART window") + return if not self._uart_available or not self._config: return port = self._config.serial_port @@ -1191,6 +1198,9 @@ class MainWindow(ctk.CTk): def _on_close(self) -> None: """Handle window close event: save config and cleanup.""" self._stop_uart_monitor() + if self._uart_window and self._uart_window.winfo_exists(): + self._uart_window.destroy() + self._uart_window = None if self._config: self._sync_config_from_ui() # Sync UI values first # Save to user config file (config.yaml) @@ -1206,7 +1216,7 @@ class MainWindow(ctk.CTk): """Open the UART Monitor window.""" port = self._port_var.get() baudrate = self._config.serial_baudrate if self._config else 115200 - UartMonitorWindow(self, port=port, baudrate=baudrate) + self._uart_window = UartMonitorWindow(self, port=port, baudrate=baudrate) def _test_serial_version(self) -> None: """Test serial port by sending 'ver()' command and parsing response.""" diff --git a/src/gui/widgets.py b/src/gui/widgets.py index 9d447a9..cb5f2c5 100644 --- a/src/gui/widgets.py +++ b/src/gui/widgets.py @@ -1024,6 +1024,11 @@ class UartMonitorWindow(ctk.CTkToplevel): # ── Window Close ─────────────────────────────────────────── + @property + def is_monitoring(self) -> bool: + """True if the UART monitor thread is currently running.""" + return self._monitor is not None and self._monitor.is_running() + def _on_close(self) -> None: """Cleanup UartMonitor and destroy window.""" if self._monitor: