This commit is contained in:
1 parent
b7c82b65c1
commit
f1be7d39ed
3 files changed
+69
-13
No files matched your search
@@ -95,7 +95,8 @@ jobs:
|
||||
uv pip install --system -e ./bec/bec_ipython_client
|
||||
uv pip install --system -e ./bec/bec_server[dev]
|
||||
uv pip install --system -e ./bec_widgets[dev,pyside6]
|
||||
uv pip install --system -e ./mx_bec
|
||||
# MX-internal dependencies (aarecommon, aare_config, jfjoch_client, ...) come from gitea
|
||||
uv pip install --system --extra-index-url https://gitea.psi.ch/api/packages/mx/pypi/simple/ -e ./mx_bec
|
||||
|
||||
- name: Run Pytest with Coverage
|
||||
id: coverage
|
||||
|
||||
@@ -5,9 +5,11 @@ from bec_widgets.utils.bec_connector import ConnectionConfig
|
||||
from bec_widgets.utils.bec_widget import BECWidget
|
||||
from bec_widgets.utils.error_popups import SafeSlot
|
||||
from qtpy.QtWidgets import (
|
||||
QDoubleSpinBox,
|
||||
QFormLayout,
|
||||
QGroupBox,
|
||||
QHBoxLayout,
|
||||
QLineEdit,
|
||||
QPushButton,
|
||||
QSpinBox,
|
||||
QVBoxLayout,
|
||||
@@ -19,11 +21,36 @@ from mx_bec.messages import MXTaskExecutionMessage
|
||||
|
||||
logger = bec_logger.logger
|
||||
|
||||
# Hard-coded forms: task name -> [(argument, default value)]; the widget type follows the default.
|
||||
TASK_FORMS: dict[str, list[tuple[str, int | float | str]]] = {
|
||||
"run_optical_centering": [("sample_id", 0)],
|
||||
"run_grid_scan": [
|
||||
("n_x", 4),
|
||||
("n_y", 3),
|
||||
("step_x_um", 50.0),
|
||||
("step_y_um", 50.0),
|
||||
("exp_time_s", 0.1),
|
||||
("file_prefix", "grid"),
|
||||
("detector_distance_mm", 150.0),
|
||||
("transmission", 0.1),
|
||||
("energy_keV", 12.4),
|
||||
("beam_center_x_pxl", 0.0),
|
||||
("beam_center_y_pxl", 0.0),
|
||||
("beam_size_x_mm", 0.02),
|
||||
("beam_size_y_mm", 0.01),
|
||||
("ring_current_mA", 400.0),
|
||||
("flux_ph_s", 1e12),
|
||||
("sample_temperature_K", 100.0),
|
||||
("pgroup", "p16371"),
|
||||
("sample_name", "unknown_sample"),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
class MxTaskPanel(BECWidget, QWidget):
|
||||
"""
|
||||
Testing panel to submit tasks to the AareBec task request stream: one hard-coded form and
|
||||
"Run" button per task.
|
||||
"Run" button per task (see `TASK_FORMS`).
|
||||
"""
|
||||
|
||||
PLUGIN = True
|
||||
@@ -39,26 +66,53 @@ class MxTaskPanel(BECWidget, QWidget):
|
||||
**kwargs,
|
||||
) -> None:
|
||||
super().__init__(parent=parent, client=client, config=config, gui_id=gui_id, **kwargs)
|
||||
self._inputs: dict[str, dict[str, QSpinBox | QDoubleSpinBox | QLineEdit]] = {}
|
||||
layout = QVBoxLayout(self)
|
||||
layout.addWidget(self._optical_centering_box())
|
||||
for task, fields in TASK_FORMS.items():
|
||||
layout.addWidget(self._task_box(task, fields))
|
||||
layout.addStretch()
|
||||
|
||||
def _optical_centering_box(self) -> QGroupBox:
|
||||
box = QGroupBox("run_optical_centering", parent=self)
|
||||
self._sample_id = QSpinBox(parent=box)
|
||||
self._sample_id.setRange(0, 1_000_000)
|
||||
run = QPushButton("Run", parent=box)
|
||||
run.clicked.connect(self._run_optical_centering)
|
||||
def _task_box(self, task: str, fields: list[tuple[str, int | float | str]]) -> QGroupBox:
|
||||
box = QGroupBox(task, parent=self)
|
||||
form = QFormLayout()
|
||||
form.addRow("sample_id", self._sample_id)
|
||||
self._inputs[task] = {}
|
||||
for name, default in fields:
|
||||
widget = self._input(box, default)
|
||||
form.addRow(name, widget)
|
||||
self._inputs[task][name] = widget
|
||||
run = QPushButton("Run", parent=box)
|
||||
run.clicked.connect(lambda *_, task=task: self._run(task))
|
||||
layout = QHBoxLayout(box)
|
||||
layout.addLayout(form)
|
||||
layout.addWidget(run)
|
||||
return box
|
||||
|
||||
@SafeSlot()
|
||||
def _run_optical_centering(self):
|
||||
self.request_task("run_optical_centering", self._sample_id.value())
|
||||
@staticmethod
|
||||
def _input(
|
||||
parent: QWidget, default: int | float | str
|
||||
) -> QSpinBox | QDoubleSpinBox | QLineEdit:
|
||||
if isinstance(default, bool) or isinstance(default, str):
|
||||
return QLineEdit(str(default), parent=parent)
|
||||
if isinstance(default, int):
|
||||
box = QSpinBox(parent=parent)
|
||||
box.setRange(0, 1_000_000)
|
||||
box.setValue(default)
|
||||
return box
|
||||
box = QDoubleSpinBox(parent=parent)
|
||||
box.setDecimals(6)
|
||||
box.setRange(-1e15, 1e15)
|
||||
box.setValue(default)
|
||||
return box
|
||||
|
||||
def _values(self, task: str) -> dict[str, int | float | str]:
|
||||
return {
|
||||
name: widget.text() if isinstance(widget, QLineEdit) else widget.value()
|
||||
for name, widget in self._inputs[task].items()
|
||||
}
|
||||
|
||||
@SafeSlot(str)
|
||||
def _run(self, task: str):
|
||||
self.request_task(task, **self._values(task))
|
||||
|
||||
@SafeSlot(str)
|
||||
def request_task(self, name: str, *args, **kwargs):
|
||||
|
||||
@@ -16,6 +16,7 @@ dependencies = [
|
||||
"aarecommon",
|
||||
"aare_config",
|
||||
"aarelcinfer_client==0.1.1a8",
|
||||
"jfjoch_client>=1.0.0rc166", # only pre-releases exist; the rc specifier lets pip pick them
|
||||
"bec_lib>=3.130.3",
|
||||
"bec-server>=3.130.3",
|
||||
"bec-ipython-client>=3.130.3",
|
||||
|
||||
Reference in new issue
Block a user