From 22b8f15fd594fe72645544d7744496379c3bada1 Mon Sep 17 00:00:00 2001 From: appleb_m Date: Wed, 10 Jun 2026 15:06:45 +0200 Subject: [PATCH] gui: updated autoamtion view and added mode switrching buttons --- src/aare/gui/main_window.py | 90 ++++++-- .../gui/panels/compact_automation_panel.py | 202 ++++++++++-------- src/aare/gui/widgets/automation_progress.py | 46 ++-- 3 files changed, 210 insertions(+), 128 deletions(-) diff --git a/src/aare/gui/main_window.py b/src/aare/gui/main_window.py index 1af8a7f0..648e820f 100644 --- a/src/aare/gui/main_window.py +++ b/src/aare/gui/main_window.py @@ -106,6 +106,13 @@ class MainWindow(QMainWindow): self._controls_help_dialog = None self._cleanup_done = False self._default_window_state = None + self._pre_automation_window_state = None + self._pre_automation_ref_tools_visible = False + self._pre_automation_left_column_visible = True + self._pre_automation_right_column_visible = True + self._in_compact_automation_view = False + self._enter_automation_view_action = None + self._return_main_view_action = None self._beamline_cam_addr = beamline_cam_addr self._gonio_cam_addr = gonio_cam_addr @@ -199,7 +206,7 @@ class MainWindow(QMainWindow): self.raster = RasterGridManager(geom=geom) self.rotation = RotationScanManager() - collection_controls_scroll = NoWheelScrollArea(top_widget) + self.collection_controls_scroll = NoWheelScrollArea(top_widget) self.left_column = QWidget(parent=top_widget) self.left_column_layout = QVBoxLayout(self.left_column) @@ -226,13 +233,13 @@ class MainWindow(QMainWindow): self.beamline_state_panel.hide() self.left_column_layout.addStretch() - top_widget_layout.addWidget(collection_controls_scroll) - collection_controls_scroll.setWidget(self.left_column) - collection_controls_scroll.setHorizontalScrollBarPolicy( + top_widget_layout.addWidget(self.collection_controls_scroll) + self.collection_controls_scroll.setWidget(self.left_column) + self.collection_controls_scroll.setHorizontalScrollBarPolicy( Qt.ScrollBarPolicy.ScrollBarAlwaysOff ) - collection_controls_scroll.setWidgetResizable(True) - collection_controls_scroll.setFixedWidth( + self.collection_controls_scroll.setWidgetResizable(True) + self.collection_controls_scroll.setFixedWidth( max( self.data_collection.set_width, self.loop_centering.sizeHint().width(), @@ -295,7 +302,7 @@ class MainWindow(QMainWindow): self.compact_automation_page.setStyleSheet( """ QWidget#compactAutomationPage { - background-color: #e8eefc; + background-color: rgb(216, 228, 253); } """ ) @@ -307,15 +314,15 @@ class MainWindow(QMainWindow): top_widget_layout.addWidget(self.video_tab) self._start_axis_camera_threads() - beamline_controls_scroll = NoWheelScrollArea(top_widget) + self.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( + self.beamline = BeamlineControls(self.beamline_controls_scroll, staff=self.__decoded_token.staff) + top_widget_layout.addWidget(self.beamline_controls_scroll) + self.beamline_controls_scroll.setWidget(self.beamline) + self.beamline_controls_scroll.setHorizontalScrollBarPolicy( Qt.ScrollBarPolicy.ScrollBarAlwaysOff ) - beamline_controls_scroll.setFixedWidth(self.beamline.set_width + 10) + self.beamline_controls_scroll.setFixedWidth(self.beamline.set_width + 10) self.tell_samples = TellSamplePanel(samples=SampleShortInfoList(s=[])) self.ref_tools_panel = ReferenceToolsPanel(samples=SampleShortInfoList(s=[])) @@ -478,6 +485,7 @@ class MainWindow(QMainWindow): self.setWindowTitle("AareGUI") self.create_menu_bar() + self._update_view_mode_actions() self._setup_global_shortcuts() self._capture_default_window_state() self._restore_window_state() @@ -916,6 +924,17 @@ class MainWindow(QMainWindow): key=lambda sample: sample.loc_str_sort(), ) + def _update_view_mode_actions(self) -> None: + in_automation_view = bool(self._in_compact_automation_view) + + if self._enter_automation_view_action is not None: + self._enter_automation_view_action.setVisible(not in_automation_view) + self._enter_automation_view_action.setEnabled(not in_automation_view) + + if self._return_main_view_action is not None: + self._return_main_view_action.setVisible(in_automation_view) + self._return_main_view_action.setEnabled(in_automation_view) + @Slot() def enter_compact_automation_view(self) -> None: self.job_list_panel.ensure_default_queue_from_samples( @@ -923,6 +942,12 @@ class MainWindow(QMainWindow): ) self._refresh_compact_queue_preview() + if not self._in_compact_automation_view: + self._pre_automation_window_state = self.saveState() + self._pre_automation_ref_tools_visible = self.ref_tools_dock.isVisible() + self._pre_automation_left_column_visible = self.collection_controls_scroll.isVisible() + self._pre_automation_right_column_visible = self.beamline_controls_scroll.isVisible() + self.tell_samples_dock.setVisible(False) self.job_list_dock.setVisible(False) self.manual_sample_dock.setVisible(False) @@ -937,12 +962,29 @@ class MainWindow(QMainWindow): if self.__decoded_token.staff: self.ref_tools_dock.setVisible(False) + self.collection_controls_scroll.setVisible(False) + self.beamline_controls_scroll.setVisible(False) + self.content_stack.setCurrentWidget(self.compact_automation_page) + self._in_compact_automation_view = True + self._update_view_mode_actions() @Slot() def _return_from_compact_automation_view(self) -> None: self.content_stack.setCurrentWidget(self._standard_main_page) - self.restore_default_view() + + if self._pre_automation_window_state is not None: + self.restoreState(self._pre_automation_window_state) + + self.collection_controls_scroll.setVisible(self._pre_automation_left_column_visible) + self.beamline_controls_scroll.setVisible(self._pre_automation_right_column_visible) + + if self.__decoded_token.staff: + self.ref_tools_dock.setVisible(self._pre_automation_ref_tools_visible) + + self._in_compact_automation_view = False + self._update_view_mode_actions() + self.job_list_dock.setVisible(True) self.tell_samples_dock.setVisible(True) self.job_list_dock.raise_() @@ -1025,6 +1067,16 @@ class MainWindow(QMainWindow): quit_action.triggered.connect(self.close) file_menu.addAction(quit_action) + self._enter_automation_view_action = QAction("Automation View", self) + self._enter_automation_view_action.setShortcut(QKeySequence("Ctrl+5")) + self._enter_automation_view_action.triggered.connect(self.enter_compact_automation_view) + menu_bar.addAction(self._enter_automation_view_action) + + self._return_main_view_action = QAction("Return to Main View", self) + self._return_main_view_action.setShortcut(QKeySequence("Ctrl+Shift+5")) + self._return_main_view_action.triggered.connect(self._return_from_compact_automation_view) + menu_bar.addAction(self._return_main_view_action) + view_menu = menu_bar.addMenu("View") if self._beamline_state_panel_enabled: @@ -1138,11 +1190,6 @@ class MainWindow(QMainWindow): beamline_combined_tab_action.triggered.connect(lambda: self.video_tab.setCurrentIndex(3)) view_menu.addAction(beamline_combined_tab_action) - compact_automation_action = QAction("Automation View", self) - compact_automation_action.setShortcut(QKeySequence("Ctrl+5")) - compact_automation_action.triggered.connect(self.enter_compact_automation_view) - view_menu.addAction(compact_automation_action) - view_menu.addSeparator() restore_default_view_action = QAction("Restore Default View", self) @@ -1194,6 +1241,11 @@ class MainWindow(QMainWindow): self.restoreState(self._default_window_state) self.content_stack.setCurrentWidget(self._standard_main_page) + self._in_compact_automation_view = False + self._update_view_mode_actions() + + self.collection_controls_scroll.setVisible(True) + self.beamline_controls_scroll.setVisible(True) self.tell_samples_dock.setVisible(True) self.job_list_dock.setVisible(True) diff --git a/src/aare/gui/panels/compact_automation_panel.py b/src/aare/gui/panels/compact_automation_panel.py index 3504ed77..3c64887f 100644 --- a/src/aare/gui/panels/compact_automation_panel.py +++ b/src/aare/gui/panels/compact_automation_panel.py @@ -37,48 +37,52 @@ class CompactAutomationPanel(QFrame): self.setStyleSheet( """ QFrame#compactAutomationPanel { - background: #edf3fb; + background: #d8e4fd; border: none; border-radius: 18px; } - QFrame#compactTopCard, + QFrame#compactCameraCard, + QFrame#compactControlsCard, QFrame#compactProgressCard, - QFrame#compactControlsCard { - background: #ffffff; - border: 1px solid #d9e4f2; + QFrame#compactQueueCard, + QFrame#compactQueueItem { + background: #e6eefc; + border: 1px solid #b9ccee; border-radius: 16px; } - QFrame#compactQueueItem { - background: #f7faff; - border: 1px solid #dbe6f5; - border-radius: 12px; - } - - QLabel#compactQueueTitle { - color: #4b5563; - font-size: 11px; - font-weight: 700; - text-transform: uppercase; - } - - QLabel#compactQueueValue { - color: #0f172a; + QLabel#compactSectionTitle { + background: transparent; + color: #17324d; font-size: 14px; font-weight: 700; } - QLabel#compactDashboardLabel { - color: #334155; + QLabel#compactSectionHint { + background: transparent; + color: #51657d; font-size: 12px; + } + + QLabel#compactQueueTitle { + background: transparent; + color: #51657d; + font-size: 11px; + font-weight: 700; + } + + QLabel#compactQueueValue { + background: transparent; + color: #10263a; + font-size: 14px; font-weight: 700; } QToolButton#compactMenuButton { - background: #eff6ff; - color: #1d4ed8; - border: 1px solid #bfdbfe; + background: #cbdcf8; + color: #17324d; + border: 1px solid #9fb9e5; border-radius: 14px; padding: 10px 14px; font-size: 18px; @@ -86,23 +90,19 @@ class CompactAutomationPanel(QFrame): } QToolButton#compactMenuButton:hover { - background: #dbeafe; - } - - QFrame#compactAutomationProgressStrip { - background: transparent; - border: none; + background: #bfd4f6; } QLabel#compactProgressSummary { - color: #1e293b; + background: transparent; + color: #17324d; font-size: 13px; padding: 2px 2px 6px 2px; } QLabel#compactProgressStep { - background: #f8fbff; - border: 1px solid #dbe6f5; + background: #dfe9fb; + border: 1px solid #bfd1ef; border-radius: 10px; padding: 8px 6px; } @@ -121,10 +121,11 @@ class CompactAutomationPanel(QFrame): background: #1d4ed8; } - QPushButton#compactSecondaryButton { - background: #ffffff; - color: #0f172a; - border: 1px solid #cbd5e1; + QPushButton#compactSecondaryButton, + QToolButton#compactSecondaryButton { + background: #dfe9fb; + color: #17324d; + border: 1px solid #b2c7eb; border-radius: 14px; padding: 14px 18px; font-size: 14px; @@ -133,17 +134,7 @@ class CompactAutomationPanel(QFrame): QPushButton#compactSecondaryButton:hover, QToolButton#compactSecondaryButton:hover { - background: #f8fafc; - } - - QToolButton#compactSecondaryButton { - background: #ffffff; - color: #0f172a; - border: 1px solid #cbd5e1; - border-radius: 14px; - padding: 14px 18px; - font-size: 14px; - font-weight: 700; + background: #d3e1f8; } """ ) @@ -152,44 +143,18 @@ class CompactAutomationPanel(QFrame): main_layout.setContentsMargins(18, 18, 18, 18) main_layout.setSpacing(12) - top_card = QFrame(self) - top_card.setObjectName("compactTopCard") - top_layout = QHBoxLayout(top_card) - top_layout.setContentsMargins(12, 12, 12, 12) - top_layout.setSpacing(10) + camera_card = QFrame(self) + camera_card.setObjectName("compactCameraCard") + camera_layout = QVBoxLayout(camera_card) + camera_layout.setContentsMargins(12, 12, 12, 12) + camera_layout.setSpacing(8) - self.current_card = self._build_queue_item("Current", "—") - self.next_card = self._build_queue_item("Next", "—") - self.next_next_card = self._build_queue_item("Then", "—") + camera_title = QLabel("Camera", self) + camera_title.setObjectName("compactSectionTitle") + camera_layout.addWidget(camera_title) + camera_layout.addWidget(camera_widget, 1) - top_layout.addWidget(self.current_card["frame"], 2) - top_layout.addWidget(self.next_card["frame"], 2) - top_layout.addWidget(self.next_next_card["frame"], 2) - - self.menu_button = QToolButton(self) - self.menu_button.setObjectName("compactMenuButton") - self.menu_button.setText("☰") - self.menu_button.setToolTip("Return to main view") - self.menu_button.clicked.connect(self.show_full_view_requested.emit) - top_layout.addWidget(self.menu_button, 0, Qt.AlignmentFlag.AlignTop) - - main_layout.addWidget(top_card) - main_layout.addWidget(camera_widget, 1) - - progress_card = QFrame(self) - progress_card.setObjectName("compactProgressCard") - progress_layout = QVBoxLayout(progress_card) - progress_layout.setContentsMargins(12, 10, 12, 10) - progress_layout.setSpacing(6) - - progress_title = QLabel("Automation progress", self) - progress_title.setObjectName("compactDashboardLabel") - progress_layout.addWidget(progress_title) - - self.progress_strip = CompactAutomationProgressStrip(self) - progress_layout.addWidget(self.progress_strip) - - main_layout.addWidget(progress_card) + main_layout.addWidget(camera_card, 1) controls_card = QFrame(self) controls_card.setObjectName("compactControlsCard") @@ -197,9 +162,31 @@ class CompactAutomationPanel(QFrame): controls_layout.setContentsMargins(12, 12, 12, 12) controls_layout.setSpacing(10) + controls_header = QHBoxLayout() + controls_header.setSpacing(10) + + controls_title_wrap = QVBoxLayout() + controls_title_wrap.setContentsMargins(0, 0, 0, 0) + controls_title_wrap.setSpacing(2) + controls_title = QLabel("Controls", self) - controls_title.setObjectName("compactDashboardLabel") - controls_layout.addWidget(controls_title) + controls_title.setObjectName("compactSectionTitle") + controls_hint = QLabel("Run and manage the automation queue.", self) + controls_hint.setObjectName("compactSectionHint") + + controls_title_wrap.addWidget(controls_title) + controls_title_wrap.addWidget(controls_hint) + + self.menu_button = QToolButton(self) + self.menu_button.setObjectName("compactMenuButton") + self.menu_button.setText("☰") + self.menu_button.setToolTip("Return to main view") + self.menu_button.clicked.connect(self.show_full_view_requested.emit) + + controls_header.addLayout(controls_title_wrap, 1) + controls_header.addWidget(self.menu_button, 0, Qt.AlignmentFlag.AlignTop) + + controls_layout.addLayout(controls_header) button_row = QHBoxLayout() button_row.setSpacing(10) @@ -212,7 +199,7 @@ class CompactAutomationPanel(QFrame): self.skip_button.setObjectName("compactSecondaryButton") self.skip_button.clicked.connect(self.skip_clicked.emit) - self.step_button = QPushButton("Step Through", self) + self.step_button = QPushButton("Step", self) self.step_button.setObjectName("compactSecondaryButton") self.step_button.setCheckable(True) self.step_button.toggled.connect(self._on_step_toggled) @@ -238,6 +225,45 @@ class CompactAutomationPanel(QFrame): controls_layout.addLayout(button_row) main_layout.addWidget(controls_card) + progress_card = QFrame(self) + progress_card.setObjectName("compactProgressCard") + progress_layout = QVBoxLayout(progress_card) + progress_layout.setContentsMargins(12, 12, 12, 12) + progress_layout.setSpacing(8) + + progress_title = QLabel("Progress", self) + progress_title.setObjectName("compactSectionTitle") + progress_layout.addWidget(progress_title) + + self.progress_strip = CompactAutomationProgressStrip(self) + progress_layout.addWidget(self.progress_strip) + + main_layout.addWidget(progress_card) + + queue_card = QFrame(self) + queue_card.setObjectName("compactQueueCard") + queue_layout = QVBoxLayout(queue_card) + queue_layout.setContentsMargins(12, 12, 12, 12) + queue_layout.setSpacing(10) + + queue_title = QLabel("Queue Preview", self) + queue_title.setObjectName("compactSectionTitle") + queue_layout.addWidget(queue_title) + + queue_row = QHBoxLayout() + queue_row.setSpacing(10) + + self.current_card = self._build_queue_item("Now", "—") + self.next_card = self._build_queue_item("Next", "—") + self.next_next_card = self._build_queue_item("Later", "—") + + queue_row.addWidget(self.current_card["frame"], 1) + queue_row.addWidget(self.next_card["frame"], 1) + queue_row.addWidget(self.next_next_card["frame"], 1) + + queue_layout.addLayout(queue_row) + main_layout.addWidget(queue_card) + def _build_queue_item(self, title: str, value: str) -> dict[str, QWidget | QLabel]: frame = QFrame(self) frame.setObjectName("compactQueueItem") diff --git a/src/aare/gui/widgets/automation_progress.py b/src/aare/gui/widgets/automation_progress.py index 2803fa0a..c700bf9c 100644 --- a/src/aare/gui/widgets/automation_progress.py +++ b/src/aare/gui/widgets/automation_progress.py @@ -18,16 +18,24 @@ class CompactAutomationProgressStrip(QFrame): self._queue_count = 0 self._running = False self._step_labels: dict[WorkflowStateKind, QLabel] = {} - self._summary_label: QLabel | None = None + self._timer = QTimer(self) self._timer.setInterval(1000) self._timer.timeout.connect(self._refresh_live_view) self.setObjectName("compactAutomationProgressStrip") + self.setStyleSheet( + """ + QFrame#compactAutomationProgressStrip { + background: transparent; + border: none; + } + """ + ) layout = QVBoxLayout(self) - layout.setContentsMargins(14, 12, 14, 12) - layout.setSpacing(10) + layout.setContentsMargins(0, 0, 0, 0) + layout.setSpacing(8) self._summary_label = QLabel("Automation idle", self) self._summary_label.setObjectName("compactProgressSummary") @@ -46,7 +54,6 @@ class CompactAutomationProgressStrip(QFrame): ): label = QLabel(self) label.setObjectName("compactProgressStep") - label.setMinimumWidth(90) label.setWordWrap(True) steps_row.addWidget(label, 1) self._step_labels[step] = label @@ -55,8 +62,7 @@ class CompactAutomationProgressStrip(QFrame): self._apply_empty_state() def _apply_empty_state(self) -> None: - if self._summary_label is not None: - self._summary_label.setText("Automation idle") + self._summary_label.setText("Automation idle") for step, label in self._step_labels.items(): label.setText(self._format_step_html(step, StepStatus.PENDING)) @@ -97,9 +103,9 @@ class CompactAutomationProgressStrip(QFrame): icon = self._step_icon(status) title = self._step_title(step) return ( - f"
" - f"
{icon}
" - f"
{title}
" + f"
" + f"
{icon}
" + f"
{title}
" f"
" ) @@ -120,6 +126,7 @@ class CompactAutomationProgressStrip(QFrame): return "N/A" return datetime.fromtimestamp(epoch_seconds).strftime("%H:%M:%S") + @Slot() def _refresh_live_view(self) -> None: if self._progress is not None: self.set_progress(self._progress) @@ -163,19 +170,16 @@ class CompactAutomationProgressStrip(QFrame): elif self._running: state_text = "Running" state_color = "#2563eb" - elif not self._running: - state_text = "Paused" - state_color = "#c2410c" - if self._summary_label is not None: - self._summary_label.setText( - f"Status: {state_text}" - f"    Current: {current_sample}" - f"    Queue: {self._queue_count}" - f"    ETA: {self._format_duration(queue_remaining)}" - f"    Done by: {self._format_eta(eta)}" - ) + self._summary_label.setText( + f"Status: " + f"{state_text}" + f"    Now: {current_sample}" + f"    Queue: {self._queue_count}" + f"    ETA: {self._format_duration(queue_remaining)}" + f"    Done: {self._format_eta(eta)}" + ) states = {step.step: step.status for step in progress.steps} for step, label in self._step_labels.items(): - label.setText(self._format_step_html(step, states.get(step, StepStatus.PENDING))) + label.setText(self._format_step_html(step, states.get(step, StepStatus.PENDING))) \ No newline at end of file