1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-03-30 05:18:36 +02:00

fix(admin-widget): Cleanup and minor improvements

This commit is contained in:
2026-03-16 16:02:55 +01:00
committed by Christian Appel
parent 48c9c83bb0
commit 0c6f3f8352
6 changed files with 43 additions and 23 deletions

View File

@@ -197,9 +197,6 @@ class BECMainApp(BECMainWindow):
idx = self._view_index.get(vid)
if idx is None or not (0 <= idx < self.stack.count()):
return
# if vid == "dark_mode":
# # Special handling for dark mode toggle item
# return
# Determine current view
current_index = self.stack.currentIndex()
current_view = (

View File

@@ -20,18 +20,12 @@ class AdminView(ViewBase):
*,
view_id: str | None = None,
title: str | None = None,
**kwargs,
):
super().__init__(parent=parent, content=content, view_id=view_id, title=title)
self.admin_widget = BECAtlasAdminView(parent=self)
self.set_content(self.admin_widget)
@SafeSlot()
def on_enter(self) -> None:
"""Called after the view becomes current/visible.
Default implementation does nothing. Override in subclasses.
"""
@SafeSlot()
def on_exit(self) -> None:
"""Called before the view is hidden.

View File

@@ -251,10 +251,14 @@ class BECAtlasAdminView(BECWidget, QWidget):
authenticated = Signal(bool)
def __init__(
self, parent=None, atlas_url: str = "https://bec-atlas-dev.psi.ch/api/v1", client=None
self,
parent=None,
atlas_url: str = "https://bec-atlas-dev.psi.ch/api/v1",
client=None,
**kwargs,
):
super().__init__(parent=parent, client=client)
super().__init__(parent=parent, client=client, **kwargs)
# State variables
self._current_deployment_info: DeploymentInfoMessage | None = None

View File

@@ -236,9 +236,11 @@ class BECAtlasHTTPService(QWidget):
):
self.authenticated.emit(self.auth_user_info.model_dump())
else:
self._show_warning(
text=f"User {self.auth_user_info.email} does not have access to the active deployment {data.get('name', '<unknown>')}."
)
if self.auth_user_info is not None:
warning_text = f"User {self.auth_user_info.email} does not have access to the active deployment {data.get('name', '<unknown>')}."
else:
warning_text = "Authenticated user information is missing. Cannot verify access to the active deployment."
self._show_warning(warning_text)
self.logout() # Logout to clear auth info and stop timer since user does not have access
response = HTTPResponse(request_url=request_url, headers=headers, status=status, data=data)

View File

@@ -185,6 +185,20 @@ class ExperimentMatCard(BECWidget, QWidget):
def _emit_next_experiment(self):
self.experiment_selected.emit(self.experiment_info)
def clear_experiment_info(self):
"""
Clear the experiment information displayed on the card and disable the activate button.
"""
self._card_pgroup.setText("-")
self._card_title_value.setText("-")
self._card_name.setText("-")
self._card_start.setText("-")
self._card_end.setText("-")
self._abstract_text = ""
self._abstract_label.setText("")
self.experiment_info = {}
self._activate_button.setEnabled(False)
def set_experiment_info(self, info: ExperimentInfoMessage | dict):
"""
Set the experiment information to display on the card.
@@ -217,7 +231,7 @@ class ExperimentMatCard(BECWidget, QWidget):
self._card_title.setText(title)
if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
import sys
from bec_qthemes import apply_theme

View File

@@ -98,7 +98,6 @@ class ExperimentSelection(QWidget):
self._build_table_tab()
self._tabs.currentChanged.connect(self._on_tab_changed)
# main_layout.addStretch()
button_layout = QHBoxLayout()
main_layout.addLayout(button_layout)
@@ -110,10 +109,20 @@ class ExperimentSelection(QWidget):
self._tabs.setCurrentWidget(self._card_tab)
def set_experiment_infos(self, experiment_infos: list[dict]):
"""
Update the experiment information displayed in the view. It will in addition determine
the next experiment to be shown in the card view. If no next experiment can be determined,
the card view will be cleared.
Args:
experiment_infos (list[dict]): A list of experiment information dictionaries.
"""
self._experiment_infos = experiment_infos
self._next_experiment = self._select_next_experiment(self._experiment_infos)
if self._next_experiment:
self._card_tab.set_experiment_info(self._next_experiment)
else:
self._card_tab.clear_experiment_info()
self._apply_table_filters()
def _setup_search(self, layout: QVBoxLayout):
@@ -194,11 +203,11 @@ class ExperimentSelection(QWidget):
self._table.setStyleSheet("QTableWidget::item { padding: 4px; }")
header = self._table.horizontalHeader()
header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
header.setSectionResizeMode(1, QHeaderView.Stretch)
header.setSectionResizeMode(2, QHeaderView.ResizeToContents)
header.setSectionResizeMode(3, QHeaderView.ResizeToContents)
header.setSectionResizeMode(4, QHeaderView.ResizeToContents)
header.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
header.setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(3, QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(4, QHeaderView.ResizeMode.ResizeToContents)
self._table.itemSelectionChanged.connect(self._update_selection_state)
hor_layout.addWidget(self._table, stretch=5)
@@ -338,7 +347,7 @@ class ExperimentSelection(QWidget):
self._apply_row_filter(current_text)
if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
from qtpy.QtWidgets import QApplication
experiment_infos = [