summaryrefslogtreecommitdiff
path: root/ui/config_dialog.py
blob: 5a95821b53122f574bf2fb1695a596f8f6b4e75a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
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