summaryrefslogtreecommitdiff
path: root/plugins/motion_capture/window.py
diff options
context:
space:
mode:
authorChristian Kolset <christian.kolset@gmail.com>2026-05-07 14:46:20 -0600
committerChristian Kolset <christian.kolset@gmail.com>2026-06-03 09:50:17 -0600
commit0a8d42501c1bf168bd852537bb3cd18490fac7ee (patch)
treee6e604cb7fc026fed8ffa65ea14929dfabdfbab9 /plugins/motion_capture/window.py
parent8e5d0aec942fb9c49040fc525f0d697fd24d7c2f (diff)
Motion capture: camera selection dropdown
Replace camera index spinbox with a combo listing detected cameras by name. On Linux enumerates /dev/video* and reads device names from sysfs (fast, no probing). Fallback probes cv2.VideoCapture indices 0-7 on other platforms. Simulation entry always appended as last option. Also adds explicit simulation mode (index -1) to tracker.start() and a rescan button (⟳) in both the main window and the Settings > Plugins widget. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'plugins/motion_capture/window.py')
-rw-r--r--plugins/motion_capture/window.py51
1 files changed, 41 insertions, 10 deletions
diff --git a/plugins/motion_capture/window.py b/plugins/motion_capture/window.py
index 082a8f6..40b436f 100644
--- a/plugins/motion_capture/window.py
+++ b/plugins/motion_capture/window.py
@@ -15,8 +15,8 @@ from __future__ import annotations
from PyQt6.QtCore import Qt, QTimer, pyqtSignal
from PyQt6.QtGui import QCloseEvent, QImage, QMouseEvent, QPixmap
from PyQt6.QtWidgets import (
- QDoubleSpinBox, QFrame, QHBoxLayout, QLabel, QPushButton,
- QSizePolicy, QSpinBox, QVBoxLayout, QWidget,
+ QComboBox, QDoubleSpinBox, QFrame, QHBoxLayout, QLabel, QPushButton,
+ QSizePolicy, QVBoxLayout, QWidget,
)
import numpy as np
@@ -92,11 +92,19 @@ class MotionCaptureWindow(QWidget):
ctrl.setContentsMargins(10, 6, 10, 6); ctrl.setSpacing(6)
ctrl.addWidget(QLabel("Camera:"))
- self._cam_spin = QSpinBox()
- self._cam_spin.setRange(0, 9); self._cam_spin.setValue(0)
- self._cam_spin.setObjectName("traceWidthSpin")
- self._cam_spin.setFixedWidth(52)
- ctrl.addWidget(self._cam_spin)
+ self._cam_combo = QComboBox()
+ self._cam_combo.setObjectName("channelPickerCb")
+ self._cam_combo.setMinimumWidth(200)
+ ctrl.addWidget(self._cam_combo)
+
+ self._refresh_btn = QPushButton("⟳")
+ self._refresh_btn.setObjectName("configButton")
+ self._refresh_btn.setFixedWidth(28)
+ self._refresh_btn.setToolTip("Rescan cameras")
+ self._refresh_btn.clicked.connect(self._scan_cameras)
+ ctrl.addWidget(self._refresh_btn)
+
+ self._scan_cameras() # populate on open
self._conn_btn = QPushButton("Connect")
self._conn_btn.setObjectName("applyButton")
@@ -136,6 +144,21 @@ class MotionCaptureWindow(QWidget):
# ── Actions ───────────────────────────────────────────────────────────
+ def _scan_cameras(self):
+ from tracker import list_cameras
+ current_idx = self.get_camera_index()
+ self._cam_combo.blockSignals(True)
+ self._cam_combo.clear()
+ self._cameras = list_cameras() # [(index, label), ...]
+ for _, label in self._cameras:
+ self._cam_combo.addItem(label)
+ # Restore selection by index if still present
+ for i, (idx, _) in enumerate(self._cameras):
+ if idx == current_idx:
+ self._cam_combo.setCurrentIndex(i)
+ break
+ self._cam_combo.blockSignals(False)
+
def _toggle_connect(self):
if self._connected:
self._tracker.stop()
@@ -150,7 +173,7 @@ class MotionCaptureWindow(QWidget):
self._sim_badge.setVisible(False)
self._status.setText("Disconnected")
else:
- ok = self._tracker.start(self._cam_spin.value())
+ ok = self._tracker.start(self.get_camera_index())
if ok:
self._connected = True
self._conn_btn.setText("Disconnect")
@@ -243,10 +266,18 @@ class MotionCaptureWindow(QWidget):
# ── State accessors (used by plugin for save/restore) ─────────────────
def get_camera_index(self) -> int:
- return self._cam_spin.value()
+ i = self._cam_combo.currentIndex()
+ cameras = getattr(self, "_cameras", [])
+ if 0 <= i < len(cameras):
+ return cameras[i][0]
+ return 0
def set_camera_index(self, v: int):
- self._cam_spin.setValue(v)
+ cameras = getattr(self, "_cameras", [])
+ for i, (idx, _) in enumerate(cameras):
+ if idx == v:
+ self._cam_combo.setCurrentIndex(i)
+ return
def get_px_per_mm(self) -> float:
return self._pxmm_spin.value()