211 lines
9.6 KiB
Python
211 lines
9.6 KiB
Python
import jwt
|
|
from PySide6.QtCore import Qt, Slot, Signal
|
|
from PySide6.QtGui import QAction
|
|
from PySide6.QtWidgets import (
|
|
QMainWindow,
|
|
QWidget,
|
|
QSplitter,
|
|
QHBoxLayout,
|
|
QVBoxLayout,
|
|
QMessageBox,
|
|
QApplication, )
|
|
from aaredaqlib.coordinate import Coordinate, SmargonCoordinate
|
|
from aaredaqlib.models import SampleShortInfoList, TokenData
|
|
from aaredaqlib.sample_geometry import SampleGeometryModel
|
|
|
|
from aaregui.panels.beamline_controls import BeamlineControls
|
|
from aaregui.panels.data_collection_settings import DataCollectionSettings
|
|
from aaregui.panels.raster_data_collection import RasterDataCollectionPanel
|
|
from aaregui.panels.sample_queue_panel import SampleQueuePanel
|
|
from aaregui.panels.status_panel import StatusPanel
|
|
from aaregui.panels.tell_sample_panel import TellSamplePanel
|
|
from aaregui.scan_logic.raster_grid_manager import RasterGridManager
|
|
from aaregui.threads.camera_thread import SampleCameraThread
|
|
from aaregui.threads.daq_worker import DAQWorker
|
|
from aaregui.widgets.camera_image import SampleCameraImageLabel
|
|
from aaregui.widgets.no_wheel_scroll_area import NoWheelScrollArea
|
|
from aaregui.widgets.status_bar import StatusBar
|
|
|
|
|
|
# Subclass QMainWindow to define the behavior of your application
|
|
class MainWindow(QMainWindow):
|
|
sample_geometry = Signal(SampleGeometryModel)
|
|
|
|
def __init__(self, base_url: str | None,
|
|
token: str,
|
|
default_image: str | None,
|
|
zmq_addr: str | None):
|
|
super().__init__()
|
|
self.__base_url = base_url
|
|
self.__token = token
|
|
|
|
# Decode the JWT without signature verification
|
|
self.__decoded_token = TokenData(**jwt.decode(token, options={"verify_signature": False}))
|
|
print(self.__decoded_token)
|
|
|
|
self.setStyleSheet("background-color: rgb(216, 228, 253);")
|
|
|
|
top_widget = QWidget(parent=self)
|
|
top_widget_layout = QHBoxLayout(top_widget)
|
|
top_widget.setLayout(top_widget_layout)
|
|
|
|
geom = SampleGeometryModel(beam_location_pxl=Coordinate(x=1000,y=1000),
|
|
pixel_in_mm=0.001,
|
|
aerotech=Coordinate(),
|
|
smargon=SmargonCoordinate(sh_mm=Coordinate(), phi_deg=0, chi_deg=0),
|
|
omega_deg=0,
|
|
beam_size_mm=Coordinate(x=0.01, y=0.01),
|
|
aerotech_meas=Coordinate()
|
|
)
|
|
|
|
self.data_collection = DataCollectionSettings(s=geom, parent=top_widget)
|
|
top_widget_layout.addWidget(self.data_collection)
|
|
|
|
self.raster = RasterGridManager(geom=geom)
|
|
self.camera_image = SampleCameraImageLabel(geom=geom, raster=self.raster, parent=top_widget, default_image=default_image)
|
|
|
|
top_widget_layout.addWidget(self.camera_image)
|
|
|
|
beamline_controls_scroll = NoWheelScrollArea(top_widget)
|
|
|
|
self.beamline = BeamlineControls(beamline_controls_scroll, staff=self.__decoded_token.staff)
|
|
top_widget_layout.addWidget(beamline_controls_scroll)
|
|
beamline_controls_scroll.setWidget(self.beamline)
|
|
beamline_controls_scroll.setHorizontalScrollBarPolicy(
|
|
Qt.ScrollBarPolicy.ScrollBarAlwaysOff
|
|
)
|
|
beamline_controls_scroll.setFixedWidth(self.beamline.set_width + 10)
|
|
bottom_widget_splitter = QSplitter(Qt.Orientation.Horizontal, parent=self)
|
|
|
|
bottom_widget = QWidget(self)
|
|
|
|
self.tell_samples = TellSamplePanel(parent=bottom_widget, samples=SampleShortInfoList(s = []))
|
|
bottom_widget_splitter.addWidget(self.tell_samples)
|
|
self.job_list_panel = SampleQueuePanel(parent=bottom_widget)
|
|
bottom_widget_splitter.addWidget(self.job_list_panel)
|
|
|
|
self.status_panel = StatusPanel(parent=bottom_widget)
|
|
bottom_widget_splitter.addWidget(self.status_panel)
|
|
|
|
bottom_widget_layout = QVBoxLayout(bottom_widget)
|
|
bottom_widget.setLayout(bottom_widget_layout)
|
|
bottom_widget_layout.addWidget(bottom_widget_splitter)
|
|
|
|
splitter = QSplitter(Qt.Orientation.Vertical, parent=self)
|
|
splitter.addWidget(top_widget)
|
|
splitter.addWidget(bottom_widget)
|
|
|
|
self.setCentralWidget(splitter)
|
|
|
|
self.setWindowTitle("AareGUI")
|
|
self.create_menu_bar()
|
|
|
|
self.status_bar = StatusBar(self.__decoded_token, parent=self)
|
|
self.setStatusBar(self.status_bar)
|
|
|
|
self.daq = DAQWorker(base_url=self.__base_url, token=self.__token)
|
|
self.daq.spreadsheet.connect(self.tell_samples.new_sample_list)
|
|
self.daq.update.connect(self.beamline.omega_panel.update_daq_status)
|
|
self.daq.update.connect(self.beamline.smargon_panel.update_daq_status)
|
|
self.daq.update.connect(self.data_collection.helical.update_daq_status)
|
|
self.daq.update.connect(self.beamline.illumination_panel.update_daq_status)
|
|
self.daq.update.connect(self.status_panel.update_daq_status)
|
|
self.daq.update.connect(self.camera_image.update_daq_status)
|
|
self.daq.update.connect(self.tell_samples.update_daq_status)
|
|
self.daq.update.connect(self.beamline.abr_tweak.update_daq_status)
|
|
self.daq.update.connect(self.status_bar.update_daq_status)
|
|
self.daq.update.connect(self.beamline.samcam.update_daq_status)
|
|
self.beamline.samcam.changed.connect(self.daq.samcam_settings)
|
|
self.beamline.state_panel.sample_exchange.clicked.connect(self.daq.sample_exchange)
|
|
self.beamline.state_panel.sample_alignment.clicked.connect(self.daq.sample_alignment)
|
|
self.beamline.state_panel.dewar_exchange.clicked.connect(self.daq.dewar_exchange)
|
|
self.beamline.loopctr.background.clicked.connect(self.daq.alc_background)
|
|
self.beamline.loopctr.find_tip.clicked.connect(self.daq.center_loop)
|
|
self.camera_image.smargon.connect(self.daq.move_smargon)
|
|
self.beamline.smargon_panel.smargon.connect(self.daq.move_smargon)
|
|
|
|
self.beamline.omega_panel.set_omega.connect(self.daq.set_omega)
|
|
self.camera_image.set_omega.connect(self.daq.set_omega)
|
|
self.beamline.zoom_panel.zoom.connect(self.daq.zoom)
|
|
self.beamline.illumination_panel.light.connect(self.daq.light)
|
|
self.beamline.abr_tweak.abr_tweak.connect(self.daq.abr_tweak)
|
|
self.beamline.abr_tweak.abr_save.connect(self.daq.abr_save)
|
|
|
|
self.beamline.beam_center.beam_center_clear.connect(self.daq.beam_center_clear)
|
|
self.camera_image.update_beam_center.connect(self.daq.beam_center_mark)
|
|
|
|
if zmq_addr is not None:
|
|
self.camera_thread = SampleCameraThread(zmq_url=zmq_addr)
|
|
self.camera_thread.camera_image.connect(self.camera_image.update_pixmap)
|
|
self.camera_thread.start()
|
|
else:
|
|
self.camera_thread = None
|
|
|
|
QApplication.instance().aboutToQuit.connect(self.cleanup)
|
|
|
|
#
|
|
# self.data_collection.helical.helical_scan.connect(self.worker.helical_scan)
|
|
# self.data_collection.helical.update_bookmarks.connect(
|
|
# self.camera_image.update_bookmarks
|
|
# )
|
|
#
|
|
|
|
self.camera_image.run_raster.connect(self.daq.raster_scan)
|
|
self.data_collection.standard_data_collection.connect(self.daq.standard_scan)
|
|
|
|
self.data_collection.helical.show_helical_start.connect(self.camera_image.show_helical_start)
|
|
self.data_collection.helical.show_helical_end.connect(self.camera_image.show_helical_end)
|
|
|
|
self.camera_image.autofocus.connect(self.daq.autofocus)
|
|
|
|
self.camera_image.set_helical_start.connect(self.data_collection.helical.set_start_point)
|
|
self.camera_image.set_helical_end.connect(self.data_collection.helical.set_end_point)
|
|
self.job_list_panel.auto_scan.connect(self.daq.automated_scan)
|
|
self.daq.automated_scan_done.connect(self.job_list_panel.automated_scan_done)
|
|
self.job_list_panel.unmount.connect(self.daq.unmount)
|
|
|
|
self.tell_samples.mount.connect(self.daq.mount)
|
|
self.tell_samples.unmount.connect(self.daq.unmount)
|
|
|
|
self.data_collection.raster.grid_size_updated.connect(self.raster.update_grid_size)
|
|
self.status_bar.set_pgroup.connect(self.daq.set_pgroup)
|
|
self.status_bar.end_session.connect(self.daq.end_session)
|
|
self.status_bar.force_session.connect(self.daq.force_session)
|
|
self.status_bar.dewar_exchange.connect(self.daq.dewar_exchange)
|
|
self.status_bar.sample_exchange.connect(self.daq.sample_exchange)
|
|
self.status_bar.sample_alignment.connect(self.daq.sample_alignment)
|
|
self.status_bar.close_shutter.connect(self.daq.close_shutter)
|
|
|
|
def create_menu_bar(self):
|
|
"""Create a menu bar with File->Quit and Help->About."""
|
|
# Main menu bar
|
|
menu_bar = self.menuBar()
|
|
|
|
# File menu
|
|
file_menu = menu_bar.addMenu("File")
|
|
quit_action = QAction("&Quit", self) # Action for 'Quit'
|
|
quit_action.triggered.connect(self.close) # Connect to window's `close` method
|
|
file_menu.addAction(quit_action)
|
|
|
|
# Help menu
|
|
help_menu = menu_bar.addMenu("Help")
|
|
about_action = QAction("About", self) # Action for 'About'
|
|
about_action.triggered.connect(self.show_about_dialog)
|
|
help_menu.addAction(about_action)
|
|
|
|
def show_about_dialog(self):
|
|
QMessageBox.about(
|
|
self,
|
|
"About",
|
|
"Aare Macromolecular Crystallography GUI\nVersion: 1.0\nCopyright: Paul Scherrer Insitute 2024-2025",
|
|
)
|
|
|
|
@Slot(str)
|
|
def display_error(self, msg: str):
|
|
self.status_bar.setStyleSheet("color: red;")
|
|
self.status_bar.showMessage(f'<span style="color: red; "> {msg} </span>', 10000)
|
|
|
|
def cleanup(self):
|
|
if self.camera_thread is not None:
|
|
self.camera_thread.stop()
|