diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2026-04-22 00:52:33 -0600 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2026-04-22 00:52:33 -0600 |
| commit | a00ed2a932fdb0f3103777ac3eac106701484ca2 (patch) | |
| tree | c62b3bdbf48dec8c6c706d619e867bf34653271e /ui/control_panel.py | |
| parent | 4db119fb9c04428e7aef6f1a278c1639aa867baf (diff) | |
Added feature/create-controls
Diffstat (limited to 'ui/control_panel.py')
| -rw-r--r-- | ui/control_panel.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/ui/control_panel.py b/ui/control_panel.py index d0f8637..efd4f17 100644 --- a/ui/control_panel.py +++ b/ui/control_panel.py @@ -467,7 +467,7 @@ class AnalogOutputControl(ControlWidget): class ControlPanel(QWidget): """ Left panel — output control widgets. - Header has Add button. Each widget has Edit and Remove buttons overlaid. + Header has Add button. Each widget has Edit, Remove, and reorder buttons. """ controls_changed = pyqtSignal() # emitted whenever widgets are added/edited/removed @@ -516,13 +516,24 @@ class ControlPanel(QWidget): # ── Widget management ───────────────────────────────────────────────────── def _make_wrapper(self, widget: ControlWidget, spec) -> QFrame: - """Wrap a ControlWidget with Edit / Remove buttons in the corner.""" + """Wrap a ControlWidget with Edit / Remove / reorder buttons.""" wrapper = QFrame(); wrapper.setObjectName("controlWidgetWrapper") wl = QVBoxLayout(wrapper); wl.setContentsMargins(0, 0, 0, 0); wl.setSpacing(0) wl.addWidget(widget) # Button row below each widget btn_row = QHBoxLayout(); btn_row.setContentsMargins(2, 1, 2, 1) + + up_btn = QPushButton("↑"); up_btn.setObjectName("traceRemoveBtn") + up_btn.setFixedSize(20, 20); up_btn.setToolTip("Move up") + dn_btn = QPushButton("↓"); dn_btn.setObjectName("traceRemoveBtn") + dn_btn.setFixedSize(20, 20); dn_btn.setToolTip("Move down") + + up_btn.clicked.connect(lambda: self._move(spec, -1)) + dn_btn.clicked.connect(lambda: self._move(spec, +1)) + + btn_row.addWidget(up_btn) + btn_row.addWidget(dn_btn) btn_row.addStretch() edit_btn = QPushButton("✎ Edit"); edit_btn.setObjectName("configButton") @@ -581,6 +592,25 @@ class ControlPanel(QWidget): for spec in specs: self._add_widget_from_spec(spec) + def _move(self, spec, direction: int): + """Move a control up (-1) or down (+1) in the list.""" + try: + idx = self._specs.index(spec) + except ValueError: + return + new_idx = idx + direction + if new_idx < 0 or new_idx >= len(self._specs): + return + + self._specs.insert(new_idx, self._specs.pop(idx)) + self._widgets.insert(new_idx, self._widgets.pop(idx)) + + wrapper = self._inner.itemAt(idx).widget() + self._inner.removeWidget(wrapper) + self._inner.insertWidget(new_idx, wrapper) + + self.controls_changed.emit() + # ── Slots ───────────────────────────────────────────────────────────────── def _on_add(self): |
