diff --git a/bec_widgets/applications/alignment/alignment_1d/alignment_1d.py b/bec_widgets/applications/alignment/alignment_1d/alignment_1d.py index 2f40caf7..ea8dbab5 100644 --- a/bec_widgets/applications/alignment/alignment_1d/alignment_1d.py +++ b/bec_widgets/applications/alignment/alignment_1d/alignment_1d.py @@ -8,45 +8,54 @@ from typing import Optional from bec_lib.device import Positioner as BECPositioner from bec_lib.device import Signal as BECSignal from bec_lib.endpoints import MessageEndpoints +from bec_lib.logger import bec_logger from qtpy.QtCore import QSize, Signal from qtpy.QtGui import QIcon -from qtpy.QtWidgets import QCheckBox, QDoubleSpinBox, QMainWindow, QPushButton, QSpinBox +from qtpy.QtWidgets import ( + QApplication, + QCheckBox, + QDoubleSpinBox, + QMainWindow, + QPushButton, + QSpinBox, +) import bec_widgets from bec_widgets.qt_utils.error_popups import SafeSlot as Slot from bec_widgets.qt_utils.toolbar import WidgetAction from bec_widgets.utils import UILoader +from bec_widgets.utils.bec_dispatcher import BECDispatcher from bec_widgets.utils.bec_widget import BECWidget from bec_widgets.utils.colors import get_accent_colors from bec_widgets.widgets.bec_progressbar.bec_progressbar import BECProgressBar from bec_widgets.widgets.device_line_edit.device_line_edit import DeviceLineEdit from bec_widgets.widgets.lmfit_dialog.lmfit_dialog import LMFitDialog from bec_widgets.widgets.positioner_box.positioner_box import PositionerBox +from bec_widgets.widgets.positioner_group.positioner_group import PositionerGroup from bec_widgets.widgets.stop_button.stop_button import StopButton from bec_widgets.widgets.toggle.toggle import ToggleSwitch from bec_widgets.widgets.waveform.waveform_widget import BECWaveformWidget MODULE_PATH = os.path.dirname(bec_widgets.__file__) +logger = bec_logger.logger -class Alignment1D(BECWidget, QMainWindow): +class Alignment1D: """Alignment GUI to perform 1D scans""" - # Emit a signal when a motion is ongoing - motion_is_active = Signal(bool) - def __init__(self, client=None, gui_id: Optional[str] = None) -> None: - """Initialise the widget + """Initialization Args: - parent: Parent widget. - config: Configuration of the widget. + config: Configuration of the application. client: BEC client object. gui_id: GUI ID. """ - super().__init__(client=client, gui_id=gui_id) - QMainWindow.__init__(self) - self.get_bec_shortcuts() + self.bec_dispatcher = BECDispatcher(client=client) + self.client = self.bec_dispatcher.client if client is None else client + QApplication.instance().aboutToQuit.connect(self.close) + self.dev = self.client.device_manager.devices + self._accent_colors = get_accent_colors() self.ui_file = "alignment_1d.ui" self.ui = None @@ -57,28 +66,25 @@ class Alignment1D(BECWidget, QMainWindow): def init_ui(self): """Initialise the UI from QT Designer file""" current_path = os.path.dirname(__file__) - self.ui = UILoader(self).loader(os.path.join(current_path, self.ui_file)) - self.setCentralWidget(self.ui) + self.ui = UILoader(None).loader(os.path.join(current_path, self.ui_file)) # Customize the plotting widget self.waveform = self.ui.findChild(BECWaveformWidget, "bec_waveform_widget") self._customise_bec_waveform_widget() # Setup comboboxes for motor and signal selection # FIXME after changing the filtering in the combobox - self._setup_motor_combobox() self._setup_signal_combobox() # Setup motor indicator self._setup_motor_indicator() - # Connect spinboxes to scan Control - self._setup_scan_control() # Setup progress bar self._setup_progress_bar() # Add actions buttons self._customise_buttons() - # Customize the positioner box - self._customize_positioner_box() # Hook scaninfo updates self.bec_dispatcher.connect_slot(self.scan_status_callback, MessageEndpoints.scan_status()) + def show(self): + return self.ui.show() + ############################## ############ SLOTS ########### ############################## @@ -87,10 +93,8 @@ class Alignment1D(BECWidget, QMainWindow): def scan_status_callback(self, content: dict, _) -> None: """This slot allows to enable/disable the UI critical components when a scan is running""" if content["status"] in ["open"]: - self.motion_is_active.emit(True) self.enable_ui(False) elif content["status"] in ["aborted", "halted", "closed"]: - self.motion_is_active.emit(False) self.enable_ui(True) @Slot(tuple) @@ -133,15 +137,11 @@ class Alignment1D(BECWidget, QMainWindow): def enable_ui(self, enable: bool) -> None: """Enable or disable the UI components""" # Enable/disable motor and signal selection - self.ui.device_combobox.setEnabled(enable) self.ui.device_combobox_2.setEnabled(enable) # Enable/disable DAP selection self.ui.dap_combo_box.setEnabled(enable) # Enable/disable Scan Button - self.ui.scan_button.setEnabled(enable) - # Positioner control line - # pylint: disable=protected-access - self.ui.positioner_box._toogle_enable_buttons(enable) + # self.ui.scan_button.setEnabled(enable) # Disable move to buttons in LMFitDialog self.ui.findChild(LMFitDialog).set_actions_enabled(enable) @@ -154,49 +154,20 @@ class Alignment1D(BECWidget, QMainWindow): fit_dialog = self.ui.findChild(LMFitDialog) fit_dialog.active_action_list = ["center", "center1", "center2"] fit_dialog.move_action.connect(self.move_to_center) - scan_button = self.ui.findChild(QPushButton, "scan_button") - scan_button.setStyleSheet( - f""" - QPushButton:enabled {{ background-color: {self._accent_colors.success.name()};color: white; }} - QPushButton:disabled {{ background-color: grey;color: white; }} - """ - ) stop_button = self.ui.findChild(StopButton) stop_button.button.setText("Stop and Clear Queue") stop_button.button.clicked.connect(self.clear_queue) def _customise_bec_waveform_widget(self) -> None: - """Customise the BEC Waveform Widget, i.e. clear the toolbar, add the DAP ROI selection to the toolbar. - We also move the scan_control widget which is fully hidden and solely used for setting up the scan parameters to the toolbar. - """ + """Customise the BEC Waveform Widget, i.e. clear the toolbar""" self.waveform.toolbar.clear() - toggle_switch = self.ui.findChild(ToggleSwitch, "toggle_switch") - scan_control = self.ui.scan_control - self.waveform.toolbar.populate_toolbar( - { - "label": WidgetAction(label="ENABLE DAP ROI", widget=toggle_switch), - "scan_control": WidgetAction(widget=scan_control), - }, - self.waveform, - ) def _setup_motor_indicator(self) -> None: """Setup the arrow item""" self.waveform.waveform.tick_item.add_to_plot() - positioner_box = self.ui.findChild(PositionerBox) + positioner_box = self.ui.findChild(PositionerGroup) positioner_box.position_update.connect(self.waveform.waveform.tick_item.set_position) - try: - pos = float(positioner_box.ui.readback.text()) - except ValueError: - pos = 0 - self.waveform.waveform.tick_item.set_position(pos) - - def _setup_motor_combobox(self) -> None: - """Setup motor selection""" - # FIXME after changing the filtering in the combobox - motors = [name for name in self.dev if isinstance(self.dev.get(name), BECPositioner)] - self.ui.device_combobox.setCurrentText(motors[0]) - self.ui.device_combobox.set_device_filter("Positioner") + self.waveform.waveform.tick_item.set_position(0) def _setup_signal_combobox(self) -> None: """Setup signal selection""" @@ -205,31 +176,6 @@ class Alignment1D(BECWidget, QMainWindow): self.ui.device_combobox_2.setCurrentText(signals[0]) self.ui.device_combobox_2.set_device_filter("Signal") - def _setup_scan_control(self) -> None: - """Setup scan control, connect spin and check boxes to the scan_control widget""" - # Connect motor - device_line_edit = self.ui.scan_control.arg_box.findChild(DeviceLineEdit) - self.ui.device_combobox.currentTextChanged.connect(device_line_edit.setText) - device_line_edit.setText(self.ui.device_combobox.currentText()) - # Connect start, stop, step, exp_time and relative check box - spin_boxes = self.ui.scan_control.arg_box.findChildren(QDoubleSpinBox) - start = self.ui.findChild(QDoubleSpinBox, "linescan_start") - start.valueChanged.connect(spin_boxes[0].setValue) - stop = self.ui.findChild(QDoubleSpinBox, "linescan_stop") - stop.valueChanged.connect(spin_boxes[1].setValue) - step = self.ui.findChild(QSpinBox, "linescan_step") - step.valueChanged.connect( - self.ui.scan_control.kwarg_boxes[0].findChildren(QSpinBox)[0].setValue - ) - exp_time = self.ui.findChild(QDoubleSpinBox, "linescan_exp_time") - exp_time.valueChanged.connect( - self.ui.scan_control.kwarg_boxes[1].findChildren(QDoubleSpinBox)[0].setValue - ) - relative = self.ui.findChild(QCheckBox, "linescan_relative") - relative.toggled.connect( - self.ui.scan_control.kwarg_boxes[0].findChildren(QCheckBox)[0].setChecked - ) - def _setup_progress_bar(self) -> None: """Setup progress bar""" # FIXME once the BECScanProgressBar is implemented @@ -238,18 +184,16 @@ class Alignment1D(BECWidget, QMainWindow): self.ui.bec_waveform_widget.new_scan.connect(self.reset_progress_bar) self.bec_dispatcher.connect_slot(self.update_progress_bar, MessageEndpoints.scan_progress()) - def _customize_positioner_box(self) -> None: - """Customize the positioner Box, i.e. remove the stop button""" - box = self.ui.findChild(PositionerBox) - box.ui.stop.setVisible(False) - box.ui.position_indicator.setFixedHeight(20) + def close(self): + logger.info("Disconnecting", repr(self.bec_dispatcher)) + self.bec_dispatcher.disconnect_all() + logger.info("Shutting down BEC Client", repr(self.client)) + self.client.shutdown() def main(): import sys - from qtpy.QtWidgets import QApplication # pylint: disable=ungrouped-imports - app = QApplication(sys.argv) icon = QIcon() icon.addFile( diff --git a/bec_widgets/applications/alignment/alignment_1d/alignment_1d.ui b/bec_widgets/applications/alignment/alignment_1d/alignment_1d.ui index 66218f47..3035f370 100644 --- a/bec_widgets/applications/alignment/alignment_1d/alignment_1d.ui +++ b/bec_widgets/applications/alignment/alignment_1d/alignment_1d.ui @@ -1,568 +1,260 @@ - Form - + mainWindow + 0 0 - 1335 - 939 + 1611 + 1019 - Form + Alignment tool - - - - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - true - - - BEC Servers - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - true - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - false - - - SLS Light On - - - true - - - true - - - false - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - false - - - BEAMLINE Checks - - - true - - - true - - - false - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 200 - 40 - - - - - 200 - 40 - - - - - - - - - - - - - 0 - 0 - - - - 0 - - - - Alignment Control - - - - 2 + + + + + + + 0 + 0 + + + + + + + + + + Qt::Orientation::Horizontal - - 2 + + + 40 + 20 + - - 2 + + + + + + true - - 2 + + BEC Servers - - - - - 0 - 0 - - - - line_scan - - - true - - - true - - - true - - - true - - - true - - - true - - - false - - - - - + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + true + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + false + + + SLS Light On + + + true + + + true + + + false + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + false + + + BEAMLINE Checks + + + true + + + true + + + false + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 200 + 40 + + + + + 200 + 40 + + + + + + + + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + + + + + + 0 + 0 + + + + 0 + + + + Alignment Control + + + + + + + 1 + 0 + + + - + + + + 1 + 0 + + - 450 - 95 + 0 + 0 - - - 450 - 16777215 - + + line_scan - - - 15 - true - - - + false - - Devices + + false + + + false + + + true + + + true + + + false + + + false - - - 8 - - - 8 - - - 8 - - - 8 - - - - - - - - Motor - - - - - - - - - - Monitor - - - - - - - - - - LMFit Model - - - - - - - - - - - - - - - - - 450 - 343 - - - - - 450 - 16777215 - - - - 0 - - - - LineScan - - - - - - - false - - - - Relative - - - - - - - 3 - - - -10000000.000000000000000 - - - 10000000.000000000000000 - - - 0.000000000000000 - - - - - - - - false - - - - Exposure Time - - - - - - - - false - - - - Start - - - - - - - - false - - - - Burst at each point - - - - - - - - - - - - - - - false - - - - Stop - - - - - - - 0 - - - 10000000 - - - 0 - - - - - - - - 0 - 40 - - - - - - - Run Scan - - - false - - - false - - - - - - - 3 - - - -10000000.000000000000000 - - - 10000000.000000000000000 - - - 0.000000000000000 - - - - - - - 1 - - - 10000000 - - - 1 - - - - - - - - false - - - - Steps - - - - - - - 3 - - - -10000000.000000000000000 - - - 10000000.000000000000000 - - - 0.000000000000000 - - - - - - - Qt::Orientation::Vertical - - - - 20 - 40 - - - - - - - - - MotorTweak - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - true - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - + @@ -578,11 +270,102 @@ - - - + + + + + + + 4 + 0 + + + + + + + + 0 + 0 + + + + + + + + + + Monitor + + + + + + + + + + + + + LMFit Model + + + + + + + + + + Enable ROI + + + + + + + + 3 + 0 + + + + Activate linear region select for LMFit + + + Qt::LayoutDirection::LeftToRight + + + false + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + 1 + + 600 @@ -595,104 +378,65 @@ - + - - 3 + + 0 0 - - Activate linear region select for LMFit + + + 0 + 190 + - - Qt::LayoutDirection::LeftToRight + + true - - false + + true + + + true - - - - - - - 0 - 0 - - - - - 0 - 190 - - - - true - - - true - - - true - - - - - - - - - - - Logbook - - - - 2 - - - 2 - - - 2 - - - 2 - - - - - https://scilog.psi.ch/login - - - - - + + + - - - - - - - - 0 - 25 - - - - - 16777215 - 25 - - - - - + + + Logbook + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + https://scilog.psi.ch/login + + + + + + + + + @@ -725,6 +469,11 @@ QWidget
lm_fit_dialog
+ + PositionerGroup + QWidget +
positioner_group
+
ScanControl QWidget @@ -755,90 +504,9 @@ QWidget
dap_combo_box
- - PositionerBox - QWidget -
positioner_box
-
- - device_combobox - device_combobox_2 - tabWidget_2 - linescan_start - linescan_stop - linescan_step - linescan_relative - linescan_exp_time - linescan_step_2 - scan_button - - - device_combobox_2 - currentTextChanged(QString) - dap_combo_box - select_y_axis(QString) - - - 297 - 170 - - - 467 - 170 - - - - - dap_combo_box - new_dap_config(QString,QString,QString) - bec_waveform_widget - add_dap(QString,QString,QString) - - - 467 - 170 - - - 1099 - 221 - - - - - scan_button - clicked() - scan_control - run_scan() - - - 455 - 511 - - - 16 - 441 - - - - - device_combobox_2 - currentTextChanged(QString) - bec_waveform_widget - plot(QString) - - - 297 - 170 - - - 1099 - 201 - - - toggle_switch enabled(bool) @@ -872,27 +540,26 @@ - device_combobox + device_combobox_2 currentTextChanged(QString) - positioner_box - set_positioner(QString) + bec_waveform_widget + plot(QString) - 109 - 155 + 297 + 170 - 160 - 286 + 1099 + 201 - + + dap_combo_box + new_dap_config(QString,QString,QString) + bec_waveform_widget + add_dap(QString,QString,QString) + + + 467 + 170 + + + 1099 + 221 + + + scan_control scan_axis(QString,double,double) @@ -937,5 +619,21 @@ + + scan_control + device_selected(QString) + positioner_group + set_positioners(QString) + + + 227 + 337 + + + 227 + 676 + + +