summaryrefslogtreecommitdiff
path: root/ui/windows/debug_window.py
diff options
context:
space:
mode:
authorChristian Kolset <ckolset@colostate.edu>2026-07-29 13:28:24 -0600
committerChristian Kolset <ckolset@colostate.edu>2026-07-29 13:28:24 -0600
commitcf33095f77e6ff902fb69932fa704eb6192b3418 (patch)
treea6a4629adb61190b74352a894e37f8efd585c6c1 /ui/windows/debug_window.py
parentb407a079000f6a4b04ecf38eca17c57719e7a7ec (diff)
Add Developer Mode setting, Debug window, and gate simulate behind it
New Settings > General > "Developer mode" checkbox (default on, so this repo's simulate-by-default workflow is unaffected out of the box) persisted through the existing core/app_settings.py load/save functions. Exposed to code that can't easily receive the settings dict via core.app_settings.is_developer_mode()/set_developer_mode(), a small in-memory cache MainWindow keeps in sync whenever settings are loaded or applied. Debug window (ui/windows/debug_window.py): minimal first pass per the plan — a live console. core/debug_log.py tees stdout/stderr into a ring buffer + Qt signal (installed once in main.py, before anything prints), so the window shows everything printed since app start, including from background poll threads, not just what's printed while it happens to be open. Its toolbar button is hidden unless developer mode is on. Simulate gating: every device's Simulation Mode checkbox/dropdown is now hidden when developer mode is off — ui/add_device_dialog.py (also covers the motion_capture camera panel, which shares this same checkbox rather than having its own), and the per-device config widgets in analog_input.py, arduino_device.py, digital_io.py, nidaqmx_device.py, serial_device.py. Hiding rather than force-clearing an already-simulating device's state — an existing simulated device keeps working if developer mode is turned off later; the option is just not offered again until it's back on. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'ui/windows/debug_window.py')
-rw-r--r--ui/windows/debug_window.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/ui/windows/debug_window.py b/ui/windows/debug_window.py
new file mode 100644
index 0000000..0e891ed
--- /dev/null
+++ b/ui/windows/debug_window.py
@@ -0,0 +1,65 @@
+"""
+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()