summaryrefslogtreecommitdiff
path: root/devices/serial_device.py
diff options
context:
space:
mode:
Diffstat (limited to 'devices/serial_device.py')
-rw-r--r--devices/serial_device.py41
1 files changed, 36 insertions, 5 deletions
diff --git a/devices/serial_device.py b/devices/serial_device.py
index 78f74a2..c3ce65f 100644
--- a/devices/serial_device.py
+++ b/devices/serial_device.py
@@ -27,7 +27,7 @@ from PyQt6.QtCore import Qt, QThread, pyqtSignal
from PyQt6.QtWidgets import (
QCheckBox, QComboBox, QDoubleSpinBox, QFormLayout, QGroupBox,
QHBoxLayout, QHeaderView, QLabel, QLineEdit, QListWidget,
- QListWidgetItem, QPushButton, QScrollArea, QSpinBox,
+ QListWidgetItem, QPushButton, QScrollArea, QSizePolicy, QSpinBox,
QStackedWidget, QTableWidget, QTableWidgetItem, QVBoxLayout, QWidget,
)
@@ -359,6 +359,30 @@ class SerialDevice(BaseDevice):
# ── Config widget ─────────────────────────────────────────────────────────────
+class _AdaptiveStack(QStackedWidget):
+ """QStackedWidget sized to its current panel only — no gap from hidden panels."""
+
+ def _current_height(self) -> int:
+ w = self.currentWidget()
+ if not w:
+ return 0
+ lyt = w.layout()
+ if lyt:
+ m = lyt.contentsMargins()
+ return lyt.sizeHint().height() + m.top() + m.bottom()
+ return w.sizeHint().height()
+
+ def sizeHint(self):
+ from PyQt6.QtCore import QSize
+ h = self._current_height()
+ w = self.currentWidget()
+ sw = w.sizeHint().width() if w else super().sizeHint().width()
+ return QSize(sw, h) if h > 0 else super().sizeHint()
+
+ def minimumSizeHint(self):
+ return self.sizeHint()
+
+
class SerialConfigWidget(QWidget):
def __init__(self, device: SerialDevice):
super().__init__()
@@ -400,7 +424,7 @@ class SerialConfigWidget(QWidget):
root.addWidget(conn_grp)
# ── Protocol-specific settings (stacked) ──────────────────────────
- self._proto_stack = QStackedWidget()
+ self._proto_stack = _AdaptiveStack()
self._generic_panel = _GenericPanel(device=self.device)
self._scpi_panel = _SCPIPanel(device=self.device)
self._modbus_panel = _ModbusPanel(device=self.device)
@@ -410,6 +434,10 @@ class SerialConfigWidget(QWidget):
self._modbus_panel, self._mark10_panel, self._cml_panel):
self._proto_stack.addWidget(panel)
self._proto_stack.setCurrentIndex(_STACK_IDX.get(self.device._fmt, 0))
+ sp = self._proto_stack.sizePolicy()
+ sp.setVerticalPolicy(QSizePolicy.Policy.Fixed)
+ self._proto_stack.setSizePolicy(sp)
+ self._proto_stack.currentChanged.connect(self._fix_stack_height)
root.addWidget(self._proto_stack)
# ── Port scanner ───────────────────────────────────────────────────
@@ -436,13 +464,16 @@ class SerialConfigWidget(QWidget):
scan_lay.addWidget(self._port_list)
scan_lay.addWidget(hint)
root.addWidget(scan_grp)
+ root.addStretch()
# ── Apply ──────────────────────────────────────────────────────────
apply_btn = QPushButton("Apply & Reconnect")
apply_btn.setObjectName("applyButton")
apply_btn.clicked.connect(self._apply)
root.addWidget(apply_btn)
- root.addStretch()
+
+ def _fix_stack_height(self, _: int):
+ self._proto_stack.updateGeometry()
def _on_fmt_changed(self, _):
fmt = _FORMAT_LABELS.get(self._fmt_cb.currentText(), "key:val")
@@ -513,7 +544,7 @@ class _GenericPanel(QWidget):
self._ch_spin = QSpinBox()
self._ch_spin.setRange(1, 32)
self._ch_spin.setValue(len(device.info.channels) if device._fmt in _GENERIC_FORMATS else 4)
- lay.addRow("Channels:", self._ch_spin)
+ lay.addRow("Signals:", self._ch_spin)
def collect(self) -> dict:
return {"num_channels": self._ch_spin.value()}
@@ -529,7 +560,7 @@ class _SCPIPanel(QWidget):
lay.setContentsMargins(0, 4, 0, 4)
lay.setSpacing(6)
- grp = QGroupBox("Channel Queries")
+ grp = QGroupBox("Signal Queries")
grp_lay = QVBoxLayout(grp)
self._table = QTableWidget()