diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2026-08-02 01:38:09 -0600 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2026-08-02 01:38:09 -0600 |
| commit | fa0304793a4525db68cb53b527d695bfa2c65966 (patch) | |
| tree | 1d10c2cd030e34324fbebe1f093588de2e310dee | |
| parent | a3aa1df99df8f413cac2ba6020b7cd0dec6d2390 (diff) | |
Remove Debug window feature
Debug button, DebugWindow, and the stdout/stderr tee (core/debug_log.py)
weren't wanted. developer_mode toggle stays — still gates device
Simulation Mode checkboxes and verbose terminal logging.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
| -rw-r--r-- | core/debug_log.py | 65 | ||||
| -rw-r--r-- | main.py | 2 | ||||
| -rw-r--r-- | ui/main_window.py | 26 | ||||
| -rw-r--r-- | ui/windows/debug_window.py | 65 | ||||
| -rw-r--r-- | ui/windows/settings_window.py | 6 |
5 files changed, 4 insertions, 160 deletions
diff --git a/core/debug_log.py b/core/debug_log.py deleted file mode 100644 index 86a8a59..0000000 --- a/core/debug_log.py +++ /dev/null @@ -1,65 +0,0 @@ -""" -core/debug_log.py - -Tees stdout/stderr into an in-memory ring buffer + Qt signal so the Debug -window can show everything the app has printed since startup — including -messages from background poll threads (e.g. "[CMLLayer] poll error: ...") — -not just whatever gets printed while the window happens to be open. - -install() should be called once, early, before anything prints. The real -streams are still written to, so running from a terminal is unaffected. -""" - -from __future__ import annotations - -import sys -from collections import deque -from typing import Optional - -from PyQt6.QtCore import QObject, pyqtSignal - - -class _Broadcaster(QObject): - line_written = pyqtSignal(str) - - -class _StreamTee: - def __init__(self, real_stream, lines: deque, broadcaster: _Broadcaster): - self._real = real_stream - self._lines = lines - self._broadcaster = broadcaster - - def write(self, text: str) -> None: - self._real.write(text) - if text: - self._lines.append(text) - self._broadcaster.line_written.emit(text) - - def flush(self) -> None: - self._real.flush() - - def isatty(self) -> bool: - return False - - -_lines: Optional[deque] = None -_broadcaster: Optional[_Broadcaster] = None - - -def install(max_lines: int = 2000) -> None: - """Redirect sys.stdout/sys.stderr through the tee. Safe to call once.""" - global _lines, _broadcaster - if _broadcaster is not None: - return - _lines = deque(maxlen=max_lines) - _broadcaster = _Broadcaster() - sys.stdout = _StreamTee(sys.stdout, _lines, _broadcaster) - sys.stderr = _StreamTee(sys.stderr, _lines, _broadcaster) - - -def get_broadcaster() -> Optional[_Broadcaster]: - return _broadcaster - - -def get_history() -> str: - return "".join(_lines) if _lines is not None else "" @@ -13,13 +13,11 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from PyQt6.QtWidgets import QApplication from ui.main_window import MainWindow -from core.debug_log import install as install_debug_log def main(): app = QApplication(sys.argv) app.setApplicationName("LabDAQ") - install_debug_log() # tee stdout/stderr for the Debug window, before anything prints qss = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ui", "style_dark.qss") if os.path.exists(qss): diff --git a/ui/main_window.py b/ui/main_window.py index 01e0505..1ee8b7f 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -108,7 +108,6 @@ from ui.profile_manager_ui import ProfileButton from ui.windows.config_window import ConfigWindow from ui.windows.plot_window import build_default_layout from ui.windows.settings_window import SettingsWindow -from ui.windows.debug_window import DebugWindow from plugins.plugin_manager import PluginManager from plugins.base_plugin import PluginContext @@ -133,7 +132,6 @@ class MainWindow(QMainWindow): self._elapsed = 0 self._win_config = None self._win_settings = None - self._win_debug = None _plugins_dir = os.path.join(os.path.dirname(os.path.dirname( os.path.abspath(__file__))), "plugins") @@ -254,12 +252,6 @@ class MainWindow(QMainWindow): set_btn.clicked.connect(lambda c: self._open_settings()) tb.addWidget(set_btn); self._btn_settings = set_btn - debug_btn = QPushButton("🐞 Debug") - debug_btn.setObjectName("toolbarSectionBtn"); debug_btn.setCheckable(True) - debug_btn.clicked.connect(lambda c: self._open_debug()) - tb.addWidget(debug_btn); self._btn_debug = debug_btn - debug_btn.setVisible(False) # shown/hidden by _update_debug_btn_visibility per developer-mode setting - # ── Central ─────────────────────────────────────────────────────── central = QWidget(); self.setCentralWidget(central) @@ -500,12 +492,6 @@ class MainWindow(QMainWindow): self._win_config.tabs.setCurrentIndex(tab) self._show_win(self._win_config, "right") - def _open_debug(self): - if self._win_debug is None: - self._win_debug = DebugWindow(self) - self._win_debug.closed.connect(lambda: self._btn_debug.setChecked(False)) - self._show_win(self._win_debug, "right") - def _on_config_closed(self): self._act_devices.setChecked(False) self._act_channels.setChecked(False) @@ -721,16 +707,6 @@ class MainWindow(QMainWindow): level = logging.DEBUG if enabled else logging.WARNING logging.getLogger().setLevel(level) set_developer_mode(enabled) - self._update_debug_btn_visibility() - - def _update_debug_btn_visibility(self): - from core.app_settings import is_developer_mode - on = is_developer_mode() - self._btn_debug.setVisible(on) - if not on: - self._btn_debug.setChecked(False) - if self._win_debug: - self._win_debug.hide() def _on_settings(self, cfg: dict): self._settings.update(cfg) @@ -744,7 +720,7 @@ class MainWindow(QMainWindow): self._time_lbl.setText(f"{h:02d}:{m:02d}:{s:02d}") def closeEvent(self, event): - for w in (self._win_config, self._win_settings, self._win_debug): + for w in (self._win_config, self._win_settings): if w: w.close() for plugin in list(self._plugin_mgr.get_loaded()): try: diff --git a/ui/windows/debug_window.py b/ui/windows/debug_window.py deleted file mode 100644 index 0e891ed..0000000 --- a/ui/windows/debug_window.py +++ /dev/null @@ -1,65 +0,0 @@ -""" -ui/windows/debug_window.py - -DEBUG window — developer-mode only. - -Minimal first pass: a live console showing everything the app has printed -via core.debug_log (stdout/stderr tee), so debugging doesn't require a -terminal. Not wired to any other diagnostics yet — extend as needed. -""" - -from PyQt6.QtWidgets import ( - QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, - QTextEdit, QFrame, -) -from PyQt6.QtCore import Qt, pyqtSignal -from PyQt6.QtGui import QFont, QCloseEvent - -from core.debug_log import get_broadcaster, get_history - - -class DebugWindow(QWidget): - closed = pyqtSignal() - - def __init__(self, parent=None): - super().__init__(parent, Qt.WindowType.Window | Qt.WindowType.Tool) - self.setWindowTitle("Debug") - self.setMinimumSize(560, 420) - self.resize(700, 500) - self._build() - - broadcaster = get_broadcaster() - if broadcaster is not None: - broadcaster.line_written.connect(self._append) - - def _build(self): - root = QVBoxLayout(self); root.setContentsMargins(0, 0, 0, 0); root.setSpacing(0) - - hdr = QWidget(); hdr.setObjectName("devWindowTitleBar"); hdr.setFixedHeight(44) - hl = QHBoxLayout(hdr); hl.setContentsMargins(14, 0, 14, 0) - title = QLabel("DEBUG"); title.setObjectName("devWindowTitle") - hl.addWidget(title, 1) - clear_btn = QPushButton("Clear"); clear_btn.setObjectName("configButton") - clear_btn.clicked.connect(lambda: self._console.clear()) - hl.addWidget(clear_btn) - root.addWidget(hdr) - - div = QFrame(); div.setFrameShape(QFrame.Shape.HLine) - div.setObjectName("devWindowDivider"); root.addWidget(div) - - self._console = QTextEdit(); self._console.setObjectName("codeEditor") - self._console.setReadOnly(True) - mono = QFont("IBM Plex Mono, Consolas, Monospace") - mono.setStyleHint(QFont.StyleHint.Monospace) - self._console.setFont(mono) - self._console.setPlainText(get_history()) - self._console.verticalScrollBar().setValue(self._console.verticalScrollBar().maximum()) - root.addWidget(self._console, 1) - - def _append(self, text: str): - self._console.insertPlainText(text) - sb = self._console.verticalScrollBar() - sb.setValue(sb.maximum()) - - def closeEvent(self, e: QCloseEvent): - self.closed.emit(); e.accept() diff --git a/ui/windows/settings_window.py b/ui/windows/settings_window.py index 09b7a1a..a1d9de1 100644 --- a/ui/windows/settings_window.py +++ b/ui/windows/settings_window.py @@ -113,9 +113,9 @@ class SettingsWindow(QWidget): self._dev_chk = QCheckBox() self._dev_chk.setChecked(self.cfg["developer_mode"]) self._dev_chk.setToolTip( - "Controls whether the Debug window and each device's Simulation\n" - "Mode option are available, and enables verbose DEBUG output in\n" - "the terminal. Off = real-hardware-only, no debug tools." + "Controls whether each device's Simulation Mode option is\n" + "available, and enables verbose DEBUG output in the terminal.\n" + "Off = real-hardware-only, no debug tools." ) lay.addRow("Developer mode:", self._dev_chk) |
