GUI: moved loop centering and ml box buttosn to under data collection settings. Reduced size of beamline state panel

This commit is contained in:
2026-05-11 16:07:14 +02:00
parent c4c8214957
commit 8413599eaa
4 changed files with 44 additions and 106 deletions
+11 -3
View File
@@ -26,6 +26,7 @@ from aare.gui.panels.beamline_state_panel import BeamlineStatePanel
from aare.gui.panels.data_collection_settings import DataCollectionSettings
from aare.gui.panels.developer_help_dialog import DeveloperHelpDialog
from aare.gui.panels.beamline_recovery_panel import BeamlineRecoveryDialog
from aare.gui.panels.loop_centering_panel import LoopCenteringPanel
from aare.gui.panels.manual_sample_panel import ManualSamplePanel
from aare.gui.panels.prediction_metrics_panel import PredictionMetricsPanel
from aare.gui.panels.reference_tools_panel import ReferenceToolsPanel
@@ -183,9 +184,12 @@ class MainWindow(QMainWindow):
raster_mgr=self.raster,
diffraction=diffraction)
self.loop_centering = LoopCenteringPanel(parent=self.left_column)
self.beamline_state_panel = BeamlineStatePanel(parent=self.left_column)
self.left_column_layout.addWidget(self.data_collection)
self.left_column_layout.addWidget(self.loop_centering)
self.left_column_layout.addWidget(self.beamline_state_panel)
self.left_column_layout.addStretch()
@@ -196,7 +200,11 @@ class MainWindow(QMainWindow):
)
collection_controls_scroll.setWidgetResizable(True)
collection_controls_scroll.setFixedWidth(
max(self.data_collection.set_width, self.beamline_state_panel.set_width) + 10
max(
self.data_collection.set_width,
self.loop_centering.sizeHint().width(),
self.beamline_state_panel.set_width,
) + 10
)
self.video_tab = QTabWidget(parent=top_widget)
@@ -429,8 +437,8 @@ class MainWindow(QMainWindow):
self.beamline.samcam.changed.connect(self.daq.samcam_settings)
self.beamline.samcam.screenshot_requested.connect(self.daq.send_screenshot_db)
self.beamline.loopctr.find_tip.clicked.connect(self.daq.center_loop)
self.beamline.loopctr.bounding_box.clicked.connect(self.daq.ml_bounding_box)
self.loop_centering.find_tip.clicked.connect(self.daq.center_loop)
self.loop_centering.bounding_box.clicked.connect(self.daq.ml_bounding_box)
self.daq.raster_generated_by_ml.connect(self.raster.update_active_grid_request)
self.sample_camera.smargon.connect(self.daq.move_smargon)
-4
View File
@@ -5,7 +5,6 @@ from aare.gui.panels.beam_center_panel import BeamCenterWidget
from aare.gui.panels.beam_mark_panel import BeamMarkWidget
from aare.gui.panels.beam_size_panel import BeamSizeWidget
from aare.gui.panels.illumination_panel import IlluminationPanel
from aare.gui.panels.loop_centering_panel import LoopCenteringPanel
from aare.gui.panels.omega_panel import OmegaPanel
from aare.gui.panels.samcam_panel import SamcamPanel
from aare.gui.panels.smargon_panel import SmargonPanel
@@ -34,9 +33,6 @@ class BeamlineControls(QFrame):
self.smargon_panel = SmargonPanel(parent=self)
self.v_layout.addWidget(self.smargon_panel)
self.loopctr = LoopCenteringPanel(self)
self.v_layout.addWidget(self.loopctr)
self.samcam = SamcamPanel(self)
self.v_layout.addWidget(self.samcam)
+30 -96
View File
@@ -1,7 +1,7 @@
from collections import deque
from dataclasses import dataclass
from PySide6.QtCore import QPoint, QRect, Qt, Signal, Slot, QSettings
from PySide6.QtCore import QPoint, QRect, Qt, Signal, Slot
from PySide6.QtGui import QColor, QPainter, QPen
from PySide6.QtWidgets import QFrame, QLabel, QPushButton
@@ -55,7 +55,7 @@ class BeamlineStatePanel(QFrame):
robot_sample_exchange = Signal()
set_width = 400
map_height = 560
map_height = 470
station_radius = 8
def __init__(self, parent=None):
@@ -65,13 +65,10 @@ class BeamlineStatePanel(QFrame):
self.setFixedWidth(self.set_width)
self.setMinimumHeight(self.map_height)
self._settings = QSettings("PSI", "AareGUI")
self._current_state: BeamlineStateEnum | None = None
self._hovered_state: BeamlineStateEnum | None = None
self._pending_target_state: BeamlineStateEnum | None = None
self._last_stable_state: BeamlineStateEnum | None = None
self._view_mode: str = self._settings.value("beamline_state_panel/view_mode", "metro", type=str)
self._line_color = QColor(111, 129, 160)
self._line_current = QColor(0, 126, 229)
@@ -109,26 +106,15 @@ class BeamlineStatePanel(QFrame):
BeamlineStateEnum.XrayFluorescence: "rgba(236, 72, 153, 0.14)",
}
self._metro_stations = [
StationSpec(BeamlineStateEnum.DewarTransfer, "Dewar transfer", 96, 126, True, "Dewar transfer mode"),
StationSpec(BeamlineStateEnum.SampleExchange, "Manual sample exchange", 96, 186, True, "Manual sample exchange mode"),
StationSpec(BeamlineStateEnum.RobotSampleExchange, "Robot sample exchange", 96, 246, True, "Robot-assisted sample exchange"),
StationSpec(BeamlineStateEnum.SampleAlignment, "Sample alignment", 96, 316, True, "Sample centring and alignment mode"),
StationSpec(BeamlineStateEnum.BeamLocation, "Beam location", 250, 316, True, "Beam location mode"),
StationSpec(BeamlineStateEnum.DataCollection, "Data collection", 96, 396, True, "Measurement / collection mode"),
StationSpec(BeamlineStateEnum.XtalSnapshot, "Crystal snapshot", 250, 396, True, "Crystal snapshot mode"),
StationSpec(BeamlineStateEnum.XrayFluorescence, "XRF", 96, 476, True, "X-ray fluorescence mode"),
]
self._line_stations = [
StationSpec(BeamlineStateEnum.DewarTransfer, "Dewar transfer", 54, 170, True, "Dewar transfer mode"),
StationSpec(BeamlineStateEnum.SampleExchange, "Manual sample exchange", 54, 220, True, "Manual sample exchange mode"),
StationSpec(BeamlineStateEnum.RobotSampleExchange, "Robot sample exchange", 54, 270, True, "Robot-assisted sample exchange"),
StationSpec(BeamlineStateEnum.SampleAlignment, "Sample alignment", 54, 320, True, "Sample centring and alignment mode"),
StationSpec(BeamlineStateEnum.BeamLocation, "Beam location", 54, 370, True, "Beam location mode"),
StationSpec(BeamlineStateEnum.DataCollection, "Data collection", 54, 420, True, "Measurement / collection mode"),
StationSpec(BeamlineStateEnum.XtalSnapshot, "Crystal snapshot", 54, 470, True, "Crystal snapshot mode"),
StationSpec(BeamlineStateEnum.XrayFluorescence, "XRF", 54, 520, True, "X-ray fluorescence mode"),
self._stations = [
StationSpec(BeamlineStateEnum.DewarTransfer, "Dewar transfer", 54, 140, True, "Dewar transfer mode"),
StationSpec(BeamlineStateEnum.SampleExchange, "Manual sample exchange", 54, 176, True, "Manual sample exchange mode"),
StationSpec(BeamlineStateEnum.RobotSampleExchange, "Robot sample exchange", 54, 212, True, "Robot-assisted sample exchange"),
StationSpec(BeamlineStateEnum.SampleAlignment, "Sample alignment", 54, 248, True, "Sample centring and alignment mode"),
StationSpec(BeamlineStateEnum.BeamLocation, "Beam location", 54, 284, True, "Beam location mode"),
StationSpec(BeamlineStateEnum.DataCollection, "Data collection", 54, 320, True, "Measurement / collection mode"),
StationSpec(BeamlineStateEnum.XtalSnapshot, "Crystal snapshot", 54, 356, True, "Crystal snapshot mode"),
StationSpec(BeamlineStateEnum.XrayFluorescence, "XRF", 54, 392, True, "X-ray fluorescence mode"),
]
self._segments = [
@@ -168,7 +154,7 @@ class BeamlineStatePanel(QFrame):
self.tell_label.setStyleSheet("""
QLabel {
color: rgb(55, 67, 87);
font-size: 13px;
font-size: 15px;
font-weight: 600;
padding-left: 4px;
background: transparent;
@@ -177,25 +163,6 @@ class BeamlineStatePanel(QFrame):
self.tell_label.move(14, 86)
self.tell_label.adjustSize()
self.view_toggle = QPushButton(self)
self.view_toggle.setCheckable(False)
self.view_toggle.setStyleSheet("""
QPushButton {
background-color: rgb(240, 244, 252);
color: rgb(55, 67, 87);
border: 1px solid rgb(160, 175, 200);
border-radius: 8px;
padding: 4px 10px;
font-size: 12px;
font-weight: 600;
}
QPushButton:hover {
background-color: rgb(228, 236, 248);
}
""")
self.view_toggle.clicked.connect(self._toggle_view_mode)
self._update_toggle_text()
self._build_station_widgets()
self._position_station_widgets()
@@ -213,11 +180,8 @@ class BeamlineStatePanel(QFrame):
graph.setdefault(b, set()).add(a)
return graph
def _stations(self) -> list[StationSpec]:
return self._metro_stations if self._view_mode == "metro" else self._line_stations
def _station_map(self) -> dict[BeamlineStateEnum, StationSpec]:
return {station.state: station for station in self._stations()}
return {station.state: station for station in self._stations}
def _path_segments_between(
self,
@@ -270,7 +234,7 @@ class BeamlineStatePanel(QFrame):
return set()
def _build_station_widgets(self) -> None:
for station in self._metro_stations:
for station in self._stations:
if station.clickable:
widget: QLabel | QPushButton = HoverableButton(station.label, self)
widget.setFlat(True)
@@ -295,44 +259,14 @@ class BeamlineStatePanel(QFrame):
widget.setText(station.label)
widget.adjustSize()
label_x = station.x + 18
label_x = station.x + 20
label_y = station.y - 12
if self._view_mode == "metro":
if state == BeamlineStateEnum.SampleAlignment:
label_x = station.x + 24
label_y = station.y + 8
elif state == BeamlineStateEnum.DataCollection:
label_x = station.x + 24
label_y = station.y + 8
elif state == BeamlineStateEnum.BeamLocation:
label_y = station.y - 18
elif state == BeamlineStateEnum.XtalSnapshot:
label_y = station.y - 14
elif state == BeamlineStateEnum.XrayFluorescence:
label_y = station.y - 14
else:
label_x = station.x + 20
label_y = station.y - 12
widget.move(label_x, label_y)
widget.show()
self._apply_station_highlight()
def _update_toggle_text(self) -> None:
self.view_toggle.setText("View: Metro" if self._view_mode == "metro" else "View: Line")
self.view_toggle.adjustSize()
self.view_toggle.move(self.set_width - 118, 58)
@Slot()
def _toggle_view_mode(self) -> None:
self._view_mode = "line" if self._view_mode == "metro" else "metro"
self._settings.setValue("beamline_state_panel/view_mode", self._view_mode)
self._update_toggle_text()
self._position_station_widgets()
self.update()
def _emit_for_state(self, state: BeamlineStateEnum) -> None:
self._pending_target_state = state
self._hovered_state = None
@@ -366,7 +300,7 @@ class BeamlineStatePanel(QFrame):
self._apply_station_highlight()
def _apply_station_highlight(self) -> None:
for station in self._stations():
for station in self._stations:
widget = self._station_widgets[station.state]
is_current = station.state == self._current_state
is_hovered = station.state == self._hovered_state
@@ -383,7 +317,7 @@ class BeamlineStatePanel(QFrame):
border-radius: 10px;
background: {self._label_current_bg};
color: rgb(0, 92, 170);
font-size: 13px;
font-size: 14px;
font-weight: 700;
text-align: left;
padding: 2px 6px 2px 8px;
@@ -399,7 +333,7 @@ class BeamlineStatePanel(QFrame):
border-radius: 10px;
background: {self._label_hover_bg};
color: rgb(115, 88, 0);
font-size: 13px;
font-size: 14px;
font-weight: 700;
text-align: left;
padding: 2px 6px 2px 8px;
@@ -415,7 +349,7 @@ class BeamlineStatePanel(QFrame):
border-radius: 10px;
background: {label_bg};
color: {label_color};
font-size: 13px;
font-size: 14px;
font-weight: 600;
text-align: left;
padding: 2px 6px 2px 8px;
@@ -431,7 +365,7 @@ class BeamlineStatePanel(QFrame):
border-radius: 10px;
background: {self._label_current_bg};
color: rgb(0, 92, 170);
font-size: 13px;
font-size: 14px;
font-weight: 700;
padding: 2px 6px 2px 8px;
}}
@@ -442,7 +376,7 @@ class BeamlineStatePanel(QFrame):
border-radius: 10px;
background: {self._label_hover_bg};
color: rgb(115, 88, 0);
font-size: 13px;
font-size: 14px;
font-weight: 700;
padding: 2px 6px 2px 8px;
}}
@@ -453,7 +387,7 @@ class BeamlineStatePanel(QFrame):
border-radius: 10px;
background: {label_bg};
color: {label_color};
font-size: 13px;
font-size: 14px;
font-weight: 600;
padding: 2px 6px 2px 8px;
}}
@@ -481,7 +415,7 @@ class BeamlineStatePanel(QFrame):
return self._line_color
def _draw_segment(self, painter: QPainter, start: QPoint, end: QPoint, color: QColor) -> None:
pen = QPen(color, 4)
pen = QPen(color, 3)
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
painter.setPen(pen)
painter.drawLine(start, end)
@@ -504,14 +438,14 @@ class BeamlineStatePanel(QFrame):
painter.setPen(QPen(self._station_hover, 3))
painter.setBrush(self._station_hover)
elif station.state == self._current_state:
painter.setPen(QPen(self._station_current_ring, 4))
painter.setPen(QPen(self._station_current_ring, 3))
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawEllipse(
QRect(
center.x() - self.station_radius - 4,
center.y() - self.station_radius - 4,
(self.station_radius + 4) * 2,
(self.station_radius + 4) * 2,
center.x() - self.station_radius - 3,
center.y() - self.station_radius - 3,
(self.station_radius + 3) * 2,
(self.station_radius + 3) * 2,
)
)
painter.setPen(QPen(self._station_current, 2))
@@ -535,7 +469,7 @@ class BeamlineStatePanel(QFrame):
color = self._segment_color(start_state, end_state)
self._draw_segment(painter, start, end, color)
for station in self._stations():
for station in self._stations:
self._draw_station(painter, station)
@Slot(DAQStatusModel)
@@ -567,7 +501,7 @@ class BeamlineStatePanel(QFrame):
self.tell_label.setStyleSheet(f"""
QLabel {{
color: {tell_color};
font-size: 13px;
font-size: 15px;
font-weight: 600;
padding-left: 4px;
background: transparent;
+3 -3
View File
@@ -8,12 +8,12 @@ class LoopCenteringPanel(QWidget):
super().__init__(parent)
grid_layout = QGridLayout(self)
grid_layout.addWidget(TitleLabel("Loop centering", self), 0, 0, 1, 3)
grid_layout.addWidget(TitleLabel("Loop centering", self), 0, 0, 1, 2)
grid_layout.setColumnStretch(0, 1)
grid_layout.setColumnStretch(1, 1)
self.find_tip = QPushButton("Center", parent=self)
grid_layout.addWidget(self.find_tip, 1, 0)
self.bounding_box = QPushButton("Box", parent=self)
grid_layout.addWidget(self.bounding_box, 1, 2)
self.bounding_box = QPushButton("Make Raster Grid", parent=self)
grid_layout.addWidget(self.bounding_box, 1, 1)