diff --git a/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py b/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py index 521ce2f..5460f2b 100644 --- a/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py +++ b/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py @@ -1,6 +1,6 @@ from __future__ import annotations -from qtpy.QtCore import Qt +from qtpy.QtCore import Qt, QTimer from qtpy.QtWidgets import QDoubleSpinBox from qtpy.QtWidgets import QPushButton from qtpy.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QLineEdit, QSizePolicy, QFrame @@ -36,6 +36,8 @@ class XRayEye(BECWidget, QWidget): # Connection to redis endpoints self.bec_dispatcher.connect_slot(self.device_updates,MessageEndpoints.device_readback("omny_xray_gui")) self.connect_motors() + QTimer.singleShot(0,self._init_gui_trigger) + def _init_ui(self): self.core_layout = QHBoxLayout(self) @@ -95,7 +97,6 @@ class XRayEye(BECWidget, QWidget): self.step_size_vertical.setValue(1.0) # Submit button self.submit_button = QPushButton("Submit", parent=self) - self.submit_button.setStyleSheet("""background-color: #4CAF50; color: white; padding: 5px 10px; border: none; border-radius: 4px;""") # Add to layout form step_size_form.addWidget(QLabel("Horizontal", parent=self),0,0) step_size_form.addWidget(self.step_size_horizontal,0,1) @@ -149,6 +150,10 @@ class XRayEye(BECWidget, QWidget): sep.setFrameShadow(QFrame.Sunken) sep.setLineWidth(1) return sep + + def _init_gui_trigger(self): + self.dev.omny_xray_gui.read() + ################################################################################ # Device Connection logic ################################################################################ @@ -161,6 +166,7 @@ class XRayEye(BECWidget, QWidget): if motor in self.dev: self.bec_dispatcher.connect_slot(self.on_tomo_angle_readback,MessageEndpoints.device_readback(motor)) logger.info(f"Succesfully connected to {motor}") + ################################################################################ # Properties ported from the original OmnyAlignment, can be adjusted as needed ################################################################################ @@ -239,6 +245,18 @@ class XRayEye(BECWidget, QWidget): def set_message(self, msg: str): self.message_line_edit.setText(msg) + @SafeSlot(str) + def set_sample_name(self, msg: str): + self.sample_name_line_edit.setText(msg) + + @SafeSlot(int) + def enable_submit_button(self, enable: int): + """If -1 disable else enable""" + if enable == -1: + self.submit_button.setEnabled(False) + else: + self.submit_button.setEnabled(True) + @SafeSlot(bool,bool) def on_tomo_angle_readback(self,data:dict,meta:dict): print(f"data: {data}") @@ -255,22 +273,27 @@ class XRayEye(BECWidget, QWidget): self.on_motors_enable(bool(enable_x_motor),bool(enable_y_motor)) - #TODO check if all data are passed correctly + # Signals from epics gui device # send message send_message = signals.get("omny_xray_gui_send_message").get('value') self.set_message(send_message) - + # sample name + sample_message = signals.get("omny_xray_gui_sample_name").get('value') + self.set_sample_name(sample_message) # enable frame acquisition update_frame_acq = signals.get("omny_xray_gui_update_frame_acq").get('value') self.on_live_view_enabled(bool(update_frame_acq)) + # enable submit button + enable_submit_button = signals.get("omny_xray_gui_submit").get('value') + self.enable_submit_button(enable_submit_button) - print(f"signals: {signals}") - print(f"data: {data}") - print(f"meta: {meta}") @SafeSlot() def submit(self): """Execute submit action by submit button.""" + if self.roi_manager.single_active_roi is None: + logger.warning("No active ROI") + return roi_coordinates = self.roi_manager.single_active_roi.get_coordinates() roi_center_x = roi_coordinates['center_x'] roi_center_y = roi_coordinates['center_y'] @@ -279,15 +302,22 @@ class XRayEye(BECWidget, QWidget): roi_width = roi_coordinates['width'] roi_height = roi_coordinates['height'] elif isinstance(self.roi_manager.single_active_roi,CircularROI): - roi_diameter = roi_coordinates['diameter'] - roi_radius = roi_coordinates['radius'] - elif isinstance(self.roi_manager.single_active_roi,EllipticalROI): - roi_major = roi_coordinates['major'] - roi_minor = roi_coordinates['minor'] + roi_width = roi_coordinates['diameter'] + roi_height =roi_coordinates['radius'] else: logger.warning("Unsupported ROI type for submit action.") return - #TODO submit angles somewhere + + print(f"current roi: {roi_center_x},{roi_center_y}, {roi_width},{roi_height}") + # submit roi coordinates + step = int(self.dev.omny_xray_gui.step.read().get("omny_xray_gui_step").get('value')) + + xval_x = getattr(self.dev.omny_xray_gui.xval_x,f"xval_x_{step}").set(roi_center_x) + xval_y = getattr(self.dev.omny_xray_gui.yval_y,f"yval_y_{step}").set(roi_center_y) + width_x = getattr(self.dev.omny_xray_gui.width_x,f"width_x_{step}").set(roi_width) + width_y = getattr(self.dev.omny_xray_gui.width_y,f"width_y_{step}").set(roi_height) + self.dev.omny_xray_gui.submit.set(1) + if __name__ == "__main__":