diff --git a/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.py b/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.py index 089101f..7573b3d 100644 --- a/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.py +++ b/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.py @@ -1,33 +1,52 @@ +from __future__ import annotations - -from typing import TypedDict -from bec_widgets.utils.error_popups import SafeSlot import os -from bec_widgets.utils.bec_widget import BECWidget -from bec_widgets.utils.ui_loader import UILoader -from qtpy.QtWidgets import QWidget, QPushButton, QLineEdit, QLabel, QVBoxLayout -from bec_qthemes import material_icon +from typing import TYPE_CHECKING, TypedDict + from bec_lib.logger import bec_logger +from bec_qthemes import material_icon +from bec_widgets.utils.bec_widget import BECWidget +from bec_widgets.utils.error_popups import SafeSlot +from bec_widgets.utils.ui_loader import UILoader +from qtpy.QtWidgets import QVBoxLayout, QWidget -logger = bec_logger.logger +logger = bec_logger.logger + +if TYPE_CHECKING: + from bec_widgets.widgets.plots.image.image import Image + from bec_widgets.widgets.utility.toggle.toggle import ToggleSwitch + from qtpy.QtWidgets import QLineEdit, QPushButton -# class OmnyAlignmentUIComponents(TypedDict): -# moveRightButton: QPushButton -# moveLeftButton: QPushButton -# moveUpButton: QPushButton -# moveDownButton: QPushButton -# image: Image +class OmnyAlignmentUIComponents(TypedDict): + moveRightButton: QPushButton + moveLeftButton: QPushButton + moveUpButton: QPushButton + moveDownButton: QPushButton + confirmButton: QPushButton + image: Image + sampleLineEdit: QLineEdit + messageLineEdit: QLineEdit + liveViewSwitch: ToggleSwitch class OmnyAlignment(BECWidget, QWidget): - USER_ACCESS = ["enable_live_view", "enable_live_view.setter", "user_message", "user_message.setter","sample_name", "sample_name.setter", "enable_move_buttons", "enable_move_buttons.setter"] + USER_ACCESS = [ + "enable_live_view", + "enable_live_view.setter", + "user_message", + "user_message.setter", + "sample_name", + "sample_name.setter", + "enable_move_buttons", + "enable_move_buttons.setter", + ] PLUGIN = True ui_file = "./omny_alignment.ui" + components: OmnyAlignmentUIComponents def __init__(self, parent=None, **kwargs): super().__init__(parent=parent, **kwargs) - self._load_ui() def _load_ui(self): @@ -38,102 +57,107 @@ class OmnyAlignment(BECWidget, QWidget): self.setLayout(layout) icon_options = {"size": (16, 16), "convert_to_pixmap": False} - self.ui.moveRightButton.setText("") - self.ui.moveRightButton.setIcon( + + self.components: OmnyAlignmentUIComponents = { + "moveRightButton": self.ui.moveRightButton, + "moveLeftButton": self.ui.moveLeftButton, + "moveUpButton": self.ui.moveUpButton, + "moveDownButton": self.ui.moveDownButton, + "confirmButton": self.ui.confirmButton, + "image": self.ui.image, + "sampleLineEdit": self.ui.sampleLineEdit, + "messageLineEdit": self.ui.messageLineEdit, + "liveViewSwitch": self.ui.liveViewSwitch, + } + self.components["moveRightButton"].setText("") + self.components["moveRightButton"].setIcon( material_icon(icon_name="keyboard_arrow_right", **icon_options) ) - self.ui.moveLeftButton.setText("") - self.ui.moveLeftButton.setIcon( + self.components["moveLeftButton"].setText("") + self.components["moveLeftButton"].setIcon( material_icon(icon_name="keyboard_arrow_left", **icon_options) ) - - self.ui.moveUpButton.setText("") - self.ui.moveUpButton.setIcon( + self.components["moveUpButton"].setText("") + self.components["moveUpButton"].setIcon( material_icon(icon_name="keyboard_arrow_up", **icon_options) ) - - self.ui.moveDownButton.setText("") - self.ui.moveDownButton.setIcon( + self.components["moveDownButton"].setText("") + self.components["moveDownButton"].setIcon( material_icon(icon_name="keyboard_arrow_down", **icon_options) ) - self.ui.confirmButton.setText("OK") - - - self.ui.liveViewSwitch.enabled.connect(self.on_live_view_enabled) + self.components["confirmButton"].setText("OK") + self.components["liveViewSwitch"].enabled.connect(self.on_live_view_enabled) @property def enable_live_view(self): - return self.ui.liveViewSwitch.checked - - @enable_live_view.setter - def enable_live_view(self, enable:bool): - self.ui.liveViewSwitch.checked = enable + return self.components["liveViewSwitch"].checked + @enable_live_view.setter + def enable_live_view(self, enable: bool): + self.components["liveViewSwitch"].checked = enable @property def user_message(self): - return self.ui.messageLineEdit.text() - + return self.components["messageLineEdit"].text() + @user_message.setter - def user_message(self, message:str): - self.ui.messageLineEdit.setText(message) + def user_message(self, message: str): + self.components["messageLineEdit"].setText(message) @property def sample_name(self): - return self.ui.sampleLineEdit.text() - - @sample_name.setter - def sample_name(self, message:str): - self.ui.sampleLineEdit.setText(message) + return self.components["sampleLineEdit"].text() + @sample_name.setter + def sample_name(self, message: str): + self.components["sampleLineEdit"].setText(message) @SafeSlot(bool) - def on_live_view_enabled(self, enabled:bool): - from bec_widgets.widgets.plots.image.image import Image + def on_live_view_enabled(self, enabled: bool): logger.info(f"Live view is enabled: {enabled}") - image: Image = self.ui.image + image = self.components["image"] if enabled: image.image("cam200") return - + image.disconnect_monitor("cam200") - - @property def enable_move_buttons(self): - move_up:QPushButton = self.ui.moveUpButton - move_down:QPushButton = self.ui.moveDownButton - move_left:QPushButton = self.ui.moveLeftButton - move_right:QPushButton = self.ui.moveRightButton - return move_up.isEnabled() and move_down.isEnabled() and move_left.isEnabled() and move_right.isEnabled() - + move_up: QPushButton = self.components["moveUpButton"] + move_down: QPushButton = self.components["moveDownButton"] + move_left: QPushButton = self.components["moveLeftButton"] + move_right: QPushButton = self.components["moveRightButton"] + return ( + move_up.isEnabled() + and move_down.isEnabled() + and move_left.isEnabled() + and move_right.isEnabled() + ) + @enable_move_buttons.setter - def enable_move_buttons(self, enabled:bool): - move_up:QPushButton = self.ui.moveUpButton - move_down:QPushButton = self.ui.moveDownButton - move_left:QPushButton = self.ui.moveLeftButton - move_right:QPushButton = self.ui.moveRightButton + def enable_move_buttons(self, enabled: bool): + move_up: QPushButton = self.components["moveUpButton"] + move_down: QPushButton = self.components["moveDownButton"] + move_left: QPushButton = self.components["moveLeftButton"] + move_right: QPushButton = self.components["moveRightButton"] move_up.setEnabled(enabled) move_down.setEnabled(enabled) move_left.setEnabled(enabled) move_right.setEnabled(enabled) - - - - -if __name__ == "__main__": - from qtpy.QtWidgets import QApplication +if __name__ == "__main__": # pragma: no cover import sys + from qtpy.QtWidgets import QApplication + app = QApplication(sys.argv) widget = OmnyAlignment() widget.show() - sys.exit(app.exec_()) \ No newline at end of file + sys.exit(app.exec_())