mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
feat(scan_control): added the ability to configure the scan control widget from designer
This commit is contained in:
@ -1,9 +1,11 @@
|
|||||||
from bec_lib.endpoints import MessageEndpoints
|
from bec_lib.endpoints import MessageEndpoints
|
||||||
|
from qtpy.QtCore import Property, Signal, Slot
|
||||||
from qtpy.QtWidgets import (
|
from qtpy.QtWidgets import (
|
||||||
QApplication,
|
QApplication,
|
||||||
QComboBox,
|
QComboBox,
|
||||||
QGridLayout,
|
QGridLayout,
|
||||||
QGroupBox,
|
QGroupBox,
|
||||||
|
QHBoxLayout,
|
||||||
QPushButton,
|
QPushButton,
|
||||||
QSizePolicy,
|
QSizePolicy,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
@ -18,6 +20,9 @@ from bec_widgets.widgets.stop_button.stop_button import StopButton
|
|||||||
|
|
||||||
class ScanControl(BECWidget, QWidget):
|
class ScanControl(BECWidget, QWidget):
|
||||||
|
|
||||||
|
scan_started = Signal()
|
||||||
|
scan_selected = Signal(str)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, parent=None, client=None, gui_id: str | None = None, allowed_scans: list | None = None
|
self, parent=None, client=None, gui_id: str | None = None, allowed_scans: list | None = None
|
||||||
):
|
):
|
||||||
@ -50,11 +55,26 @@ class ScanControl(BECWidget, QWidget):
|
|||||||
self.layout.addWidget(self.scan_selection_group)
|
self.layout.addWidget(self.scan_selection_group)
|
||||||
|
|
||||||
# Connect signals
|
# Connect signals
|
||||||
self.comboBox_scan_selection.currentIndexChanged.connect(self.on_scan_selected)
|
self.comboBox_scan_selection.currentIndexChanged.connect(self.on_scan_selection_changed)
|
||||||
self.button_run_scan.clicked.connect(self.run_scan)
|
self.button_run_scan.clicked.connect(self.run_scan)
|
||||||
|
|
||||||
|
# Add bundle button
|
||||||
|
self.button_add_bundle = QPushButton("Add Bundle")
|
||||||
|
self.button_add_bundle.setVisible(False)
|
||||||
|
# Remove bundle button
|
||||||
|
self.button_remove_bundle = QPushButton("Remove Bundle")
|
||||||
|
self.button_remove_bundle.setVisible(False)
|
||||||
|
|
||||||
|
bundle_layout = QHBoxLayout()
|
||||||
|
bundle_layout.addWidget(self.button_add_bundle)
|
||||||
|
bundle_layout.addWidget(self.button_remove_bundle)
|
||||||
|
self.layout.addLayout(bundle_layout)
|
||||||
|
|
||||||
self.button_add_bundle.clicked.connect(self.add_arg_bundle)
|
self.button_add_bundle.clicked.connect(self.add_arg_bundle)
|
||||||
self.button_remove_bundle.clicked.connect(self.remove_arg_bundle)
|
self.button_remove_bundle.clicked.connect(self.remove_arg_bundle)
|
||||||
|
|
||||||
|
self.scan_selected.connect(self.scan_select)
|
||||||
|
|
||||||
# Initialize scan selection
|
# Initialize scan selection
|
||||||
self.populate_scans()
|
self.populate_scans()
|
||||||
|
|
||||||
@ -69,21 +89,16 @@ class ScanControl(BECWidget, QWidget):
|
|||||||
scan_selection_group = QGroupBox("Scan Selection", self)
|
scan_selection_group = QGroupBox("Scan Selection", self)
|
||||||
self.scan_selection_layout = QGridLayout(scan_selection_group)
|
self.scan_selection_layout = QGridLayout(scan_selection_group)
|
||||||
self.comboBox_scan_selection = QComboBox(scan_selection_group)
|
self.comboBox_scan_selection = QComboBox(scan_selection_group)
|
||||||
|
|
||||||
# Run button
|
# Run button
|
||||||
self.button_run_scan = QPushButton("Start", scan_selection_group)
|
self.button_run_scan = QPushButton("Start", scan_selection_group)
|
||||||
self.button_run_scan.setStyleSheet("background-color: #559900; color: white")
|
self.button_run_scan.setStyleSheet("background-color: #559900; color: white")
|
||||||
# Stop button
|
# Stop button
|
||||||
self.button_stop_scan = StopButton(parent=scan_selection_group)
|
self.button_stop_scan = StopButton(parent=scan_selection_group)
|
||||||
# Add bundle button
|
|
||||||
self.button_add_bundle = QPushButton("Add Bundle", scan_selection_group)
|
|
||||||
# Remove bundle button
|
|
||||||
self.button_remove_bundle = QPushButton("Remove Bundle", scan_selection_group)
|
|
||||||
|
|
||||||
self.scan_selection_layout.addWidget(self.comboBox_scan_selection, 0, 0, 1, 2)
|
self.scan_selection_layout.addWidget(self.comboBox_scan_selection, 0, 0, 1, 2)
|
||||||
self.scan_selection_layout.addWidget(self.button_run_scan, 1, 0)
|
self.scan_selection_layout.addWidget(self.button_run_scan, 1, 0)
|
||||||
self.scan_selection_layout.addWidget(self.button_stop_scan, 1, 1)
|
self.scan_selection_layout.addWidget(self.button_stop_scan, 1, 1)
|
||||||
self.scan_selection_layout.addWidget(self.button_add_bundle, 2, 0)
|
|
||||||
self.scan_selection_layout.addWidget(self.button_remove_bundle, 2, 1)
|
|
||||||
|
|
||||||
return scan_selection_group
|
return scan_selection_group
|
||||||
|
|
||||||
@ -104,23 +119,65 @@ class ScanControl(BECWidget, QWidget):
|
|||||||
allowed_scans = self.allowed_scans
|
allowed_scans = self.allowed_scans
|
||||||
self.comboBox_scan_selection.addItems(allowed_scans)
|
self.comboBox_scan_selection.addItems(allowed_scans)
|
||||||
|
|
||||||
def on_scan_selected(self):
|
def on_scan_selection_changed(self, index: int):
|
||||||
"""Callback for scan selection combo box"""
|
"""Callback for scan selection combo box"""
|
||||||
self.reset_layout()
|
|
||||||
selected_scan_name = self.comboBox_scan_selection.currentText()
|
selected_scan_name = self.comboBox_scan_selection.currentText()
|
||||||
selected_scan_info = self.available_scans.get(selected_scan_name, {})
|
self.scan_selected.emit(selected_scan_name)
|
||||||
|
|
||||||
|
@Property(bool)
|
||||||
|
def hide_scan_control_buttons(self):
|
||||||
|
return not self.button_run_scan.isVisible()
|
||||||
|
|
||||||
|
@hide_scan_control_buttons.setter
|
||||||
|
def hide_scan_control_buttons(self, hide: bool):
|
||||||
|
self.show_scan_control_buttons(not hide)
|
||||||
|
|
||||||
|
@Slot(bool)
|
||||||
|
def show_scan_control_buttons(self, show: bool):
|
||||||
|
"""Shows or hides the scan control buttons."""
|
||||||
|
self.button_run_scan.setVisible(show)
|
||||||
|
self.button_stop_scan.setVisible(show)
|
||||||
|
|
||||||
|
show_group = show or self.button_run_scan.isVisible()
|
||||||
|
self.scan_selection_group.setVisible(show_group)
|
||||||
|
|
||||||
|
@Property(bool)
|
||||||
|
def hide_scan_selection_combobox(self):
|
||||||
|
return not self.comboBox_scan_selection.isVisible()
|
||||||
|
|
||||||
|
@hide_scan_selection_combobox.setter
|
||||||
|
def hide_scan_selection_combobox(self, hide: bool):
|
||||||
|
self.show_scan_selection_combobox(not hide)
|
||||||
|
|
||||||
|
@Slot(bool)
|
||||||
|
def show_scan_selection_combobox(self, show: bool):
|
||||||
|
"""Shows or hides the scan selection combobox."""
|
||||||
|
self.comboBox_scan_selection.setVisible(show)
|
||||||
|
|
||||||
|
show_group = show or self.button_run_scan.isVisible()
|
||||||
|
self.scan_selection_group.setVisible(show_group)
|
||||||
|
|
||||||
|
@Slot(str)
|
||||||
|
def scan_select(self, scan_name: str):
|
||||||
|
"""
|
||||||
|
Slot for scan selection. Updates the scan control layout based on the selected scan.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
scan_name(str): Name of the selected scan.
|
||||||
|
"""
|
||||||
|
self.reset_layout()
|
||||||
|
selected_scan_info = self.available_scans.get(scan_name, {})
|
||||||
|
|
||||||
gui_config = selected_scan_info.get("gui_config", {})
|
gui_config = selected_scan_info.get("gui_config", {})
|
||||||
self.arg_group = gui_config.get("arg_group", None)
|
self.arg_group = gui_config.get("arg_group", None)
|
||||||
self.kwarg_groups = gui_config.get("kwarg_groups", None)
|
self.kwarg_groups = gui_config.get("kwarg_groups", None)
|
||||||
|
|
||||||
if self.arg_box is None:
|
show_bundle_buttons = bool(self.arg_group["arg_inputs"])
|
||||||
self.button_add_bundle.setEnabled(False)
|
|
||||||
self.button_remove_bundle.setEnabled(False)
|
|
||||||
|
|
||||||
if len(self.arg_group["arg_inputs"]) > 0:
|
self.button_add_bundle.setVisible(show_bundle_buttons)
|
||||||
self.button_add_bundle.setEnabled(True)
|
self.button_remove_bundle.setVisible(show_bundle_buttons)
|
||||||
self.button_remove_bundle.setEnabled(True)
|
|
||||||
|
if show_bundle_buttons:
|
||||||
self.add_arg_group(self.arg_group)
|
self.add_arg_group(self.arg_group)
|
||||||
if len(self.kwarg_groups) > 0:
|
if len(self.kwarg_groups) > 0:
|
||||||
self.add_kwargs_boxes(self.kwarg_groups)
|
self.add_kwargs_boxes(self.kwarg_groups)
|
||||||
@ -151,9 +208,11 @@ class ScanControl(BECWidget, QWidget):
|
|||||||
self.arg_box.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
|
self.arg_box.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
|
||||||
self.layout.addWidget(self.arg_box)
|
self.layout.addWidget(self.arg_box)
|
||||||
|
|
||||||
|
@Slot()
|
||||||
def add_arg_bundle(self):
|
def add_arg_bundle(self):
|
||||||
self.arg_box.add_widget_bundle()
|
self.arg_box.add_widget_bundle()
|
||||||
|
|
||||||
|
@Slot()
|
||||||
def remove_arg_bundle(self):
|
def remove_arg_bundle(self):
|
||||||
self.arg_box.remove_widget_bundle()
|
self.arg_box.remove_widget_bundle()
|
||||||
|
|
||||||
@ -172,7 +231,9 @@ class ScanControl(BECWidget, QWidget):
|
|||||||
box.deleteLater()
|
box.deleteLater()
|
||||||
self.kwarg_boxes = []
|
self.kwarg_boxes = []
|
||||||
|
|
||||||
|
@Slot()
|
||||||
def run_scan(self):
|
def run_scan(self):
|
||||||
|
self.scan_started.emit()
|
||||||
args = []
|
args = []
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if self.arg_box is not None:
|
if self.arg_box is not None:
|
||||||
|
Reference in New Issue
Block a user