""" ui/config_dialog.py — Device configuration dialog (tabbed). """ from PyQt6.QtWidgets import ( QDialog, QVBoxLayout, QHBoxLayout, QTabWidget, QWidget, QFormLayout, QScrollArea, QLabel, QLineEdit, QPushButton, ) from PyQt6.QtCore import Qt class DeviceConfigDialog(QDialog): def __init__(self, device, parent=None): super().__init__(parent) self.device = device self.setWindowTitle(f"Configure — {device.info.name} [{device.info.device_id}]") self.setMinimumSize(580, 520) self.resize(640, 580) self._build() def _build(self): layout = QVBoxLayout(self) layout.setSpacing(8) tabs = QTabWidget() # ── Tab 1: Device-specific widget ──────────────────────────── cfg_widget = self.device.get_config_widget() scroll = QScrollArea() scroll.setWidgetResizable(True) scroll.setHorizontalScrollBarPolicy( __import__("PyQt6.QtCore", fromlist=["Qt"]).Qt.ScrollBarPolicy.ScrollBarAsNeeded ) scroll.setMinimumWidth(460) scroll.setWidget(cfg_widget) tabs.addTab(scroll, "Hardware / Backend") # ── Tab 2: Device info ──────────────────────────────────────── tabs.addTab(self._info_tab(), "Info") layout.addWidget(tabs) btn_row = QHBoxLayout() btn_row.addStretch() close_btn = QPushButton("Close") close_btn.setDefault(True) close_btn.clicked.connect(self.accept) btn_row.addWidget(close_btn) layout.addLayout(btn_row) def _info_tab(self): w = QWidget() form = QFormLayout(w) info = self.device.info def _ro(v): e = QLineEdit(str(v)); e.setReadOnly(True); return e form.addRow("Device ID:", _ro(info.device_id)) def _on_name_edited(): info.name = name_edit.text().strip() or info.name self.setWindowTitle(f"Configure — {info.name} [{info.device_id}]") name_edit = QLineEdit(info.name) name_edit.editingFinished.connect(_on_name_edited) form.addRow("Name:", name_edit) form.addRow("Type:", _ro(info.device_type)) form.addRow("Description:", _ro(info.description)) form.addRow("Manufacturer:", _ro(info.manufacturer)) form.addRow("Model:", _ro(info.model)) form.addRow("Version:", _ro(info.version)) form.addRow("Status:", _ro(self.device.status.value)) form.addRow("Signals:", _ro(len(info.channels))) return w