This commit is contained in:
1 parent
bd445867ac
commit
797f29e1fc
1 file changed
+68
@@ -0,0 +1,68 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from bec_lib.logger import bec_logger
|
||||
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 (
|
||||
QFormLayout,
|
||||
QGroupBox,
|
||||
QHBoxLayout,
|
||||
QPushButton,
|
||||
QSpinBox,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
)
|
||||
|
||||
from mx_bec.endpoints import TaskEndpoints
|
||||
from mx_bec.messages import MXTaskExecutionMessage
|
||||
|
||||
logger = bec_logger.logger
|
||||
|
||||
|
||||
class MxTaskPanel(BECWidget, QWidget):
|
||||
"""
|
||||
Testing panel to submit tasks to the AareBec task request stream: one hard-coded form and
|
||||
"Run" button per task.
|
||||
"""
|
||||
|
||||
PLUGIN = True
|
||||
ICON_NAME = "play_arrow"
|
||||
USER_ACCESS = ["request_task"]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
parent: QWidget | None = None,
|
||||
client=None,
|
||||
config: ConnectionConfig | None = None,
|
||||
gui_id: str | None = None,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
super().__init__(parent=parent, client=client, config=config, gui_id=gui_id, **kwargs)
|
||||
layout = QVBoxLayout(self)
|
||||
layout.addWidget(self._optical_centering_box())
|
||||
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)
|
||||
form = QFormLayout()
|
||||
form.addRow("sample_id", self._sample_id)
|
||||
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())
|
||||
|
||||
@SafeSlot(str)
|
||||
def request_task(self, name: str, *args, **kwargs):
|
||||
"""Submit a task request to the AareBec service."""
|
||||
msg = MXTaskExecutionMessage(name=name, args=args, kwargs=kwargs)
|
||||
logger.info(f"Requesting task: {msg}")
|
||||
self.client.connector.xadd(TaskEndpoints.task_request(), {"data": msg})
|
||||
Reference in new issue
Block a user