mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
feat: adapt BECQueue and BECStatusBox widgets to use CompactPopupWidget
This commit is contained in:
@ -2,10 +2,11 @@ from __future__ import annotations
|
||||
|
||||
from bec_lib.endpoints import MessageEndpoints
|
||||
from bec_qthemes import material_icon
|
||||
from qtpy.QtCore import Property, Qt, Slot
|
||||
from qtpy.QtCore import Property, Qt, Signal, Slot
|
||||
from qtpy.QtGui import QColor
|
||||
from qtpy.QtWidgets import QHeaderView, QLabel, QTableWidget, QTableWidgetItem, QVBoxLayout, QWidget
|
||||
|
||||
from bec_widgets.qt_utils.compact_popup import CompactPopupWidget
|
||||
from bec_widgets.qt_utils.toolbar import ModularToolBar, SeparatorAction, WidgetAction
|
||||
from bec_widgets.utils.bec_connector import ConnectionConfig
|
||||
from bec_widgets.utils.bec_widget import BECWidget
|
||||
@ -15,7 +16,7 @@ from bec_widgets.widgets.button_resume.button_resume import ResumeButton
|
||||
from bec_widgets.widgets.stop_button.stop_button import StopButton
|
||||
|
||||
|
||||
class BECQueue(BECWidget, QWidget):
|
||||
class BECQueue(BECWidget, CompactPopupWidget):
|
||||
"""
|
||||
Widget to display the BEC queue.
|
||||
"""
|
||||
@ -31,6 +32,8 @@ class BECQueue(BECWidget, QWidget):
|
||||
"COMPLETED": "blue",
|
||||
}
|
||||
|
||||
queue_busy = Signal(bool)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
parent: QWidget | None = None,
|
||||
@ -40,22 +43,24 @@ class BECQueue(BECWidget, QWidget):
|
||||
refresh_upon_start: bool = True,
|
||||
):
|
||||
super().__init__(client, config, gui_id)
|
||||
QWidget.__init__(self, parent=parent)
|
||||
self.layout = QVBoxLayout(self)
|
||||
CompactPopupWidget.__init__(self, parent=parent, layout=QVBoxLayout)
|
||||
self.layout.setSpacing(0)
|
||||
self.layout.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
# Set up the toolbar
|
||||
self.set_toolbar()
|
||||
|
||||
# Set up the table
|
||||
self.table = QTableWidget(self)
|
||||
self.layout.addWidget(self.table)
|
||||
# self.layout.addWidget(self.table)
|
||||
self.table.setColumnCount(4)
|
||||
self.table.setHorizontalHeaderLabels(["Scan Number", "Type", "Status", "Cancel"])
|
||||
header = self.table.horizontalHeader()
|
||||
header.setSectionResizeMode(QHeaderView.Stretch)
|
||||
|
||||
self.addWidget(self.table)
|
||||
self.label = "BEC Queue"
|
||||
self.tooltip = "BEC Queue status"
|
||||
|
||||
self.bec_dispatcher.connect_slot(self.update_queue, MessageEndpoints.scan_queue_status())
|
||||
self.reset_content()
|
||||
if refresh_upon_start:
|
||||
@ -78,7 +83,7 @@ class BECQueue(BECWidget, QWidget):
|
||||
target_widget=self,
|
||||
)
|
||||
|
||||
self.layout.addWidget(self.toolbar)
|
||||
self.addWidget(self.toolbar)
|
||||
|
||||
@Property(bool)
|
||||
def hide_toolbar(self):
|
||||
@ -109,6 +114,9 @@ class BECQueue(BECWidget, QWidget):
|
||||
Refresh the queue.
|
||||
"""
|
||||
msg = self.client.connector.get(MessageEndpoints.scan_queue_status())
|
||||
if msg is None:
|
||||
# msg is None if no scan has been run yet (fresh start)
|
||||
return
|
||||
self.update_queue(msg.content, msg.metadata)
|
||||
|
||||
@Slot(dict, dict)
|
||||
@ -152,6 +160,13 @@ class BECQueue(BECWidget, QWidget):
|
||||
if scan_ids:
|
||||
scan_ids = ", ".join(scan_ids)
|
||||
self.set_row(index, scan_numbers, scan_types, status, scan_ids)
|
||||
busy = (
|
||||
False
|
||||
if all(item.get("status") in ("STOPPED", "COMPLETED", "IDLE") for item in queue_info)
|
||||
else True
|
||||
)
|
||||
self.set_global_state("warning" if busy else "default")
|
||||
self.queue_busy.emit(busy)
|
||||
|
||||
def format_item(self, content: str, status=False) -> QTableWidgetItem:
|
||||
"""
|
||||
|
@ -13,8 +13,8 @@ from bec_lib.utils.import_utils import lazy_import_from
|
||||
from qtpy.QtCore import QObject, QTimer, Signal, Slot
|
||||
from qtpy.QtWidgets import QHBoxLayout, QTreeWidget, QTreeWidgetItem, QWidget
|
||||
|
||||
from bec_widgets.qt_utils.compact_popup import CompactPopupWidget
|
||||
from bec_widgets.utils.bec_widget import BECWidget
|
||||
from bec_widgets.utils.colors import set_theme
|
||||
from bec_widgets.widgets.bec_status_box.status_item import StatusItem
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -64,7 +64,7 @@ class BECServiceStatusMixin(QObject):
|
||||
self._service_update_timer.deleteLater()
|
||||
|
||||
|
||||
class BECStatusBox(BECWidget, QWidget):
|
||||
class BECStatusBox(BECWidget, CompactPopupWidget):
|
||||
"""An autonomous widget to display the status of BEC services.
|
||||
|
||||
Args:
|
||||
@ -83,15 +83,13 @@ class BECStatusBox(BECWidget, QWidget):
|
||||
def __init__(
|
||||
self,
|
||||
parent=None,
|
||||
box_name: str = "BEC Server",
|
||||
box_name: str = "BEC Servers",
|
||||
client: BECClient = None,
|
||||
bec_service_status_mixin: BECServiceStatusMixin = None,
|
||||
gui_id: str = None,
|
||||
):
|
||||
super().__init__(client=client, gui_id=gui_id)
|
||||
QWidget.__init__(self, parent=parent)
|
||||
self.tree = QTreeWidget(self)
|
||||
self.layout = QHBoxLayout(self)
|
||||
CompactPopupWidget.__init__(self, parent=parent, layout=QHBoxLayout)
|
||||
|
||||
self.box_name = box_name
|
||||
self.status_container = defaultdict(lambda: {"info": None, "item": None, "widget": None})
|
||||
@ -100,11 +98,13 @@ class BECStatusBox(BECWidget, QWidget):
|
||||
bec_service_status_mixin = BECServiceStatusMixin(self, client=self.client)
|
||||
self.bec_service_status = bec_service_status_mixin
|
||||
|
||||
self.label = box_name
|
||||
self.tooltip = "BEC servers health status"
|
||||
self.init_ui()
|
||||
self.bec_service_status.services_update.connect(self.update_service_status)
|
||||
self.bec_core_state.connect(self.update_top_item_status)
|
||||
self.tree.itemDoubleClicked.connect(self.on_tree_item_double_clicked)
|
||||
self.layout.addWidget(self.tree)
|
||||
self.addWidget(self.tree)
|
||||
|
||||
def init_ui(self) -> None:
|
||||
"""Init the UI for the BECStatusBox widget, should only take place once."""
|
||||
@ -121,6 +121,7 @@ class BECStatusBox(BECWidget, QWidget):
|
||||
|
||||
def init_ui_tree_widget(self) -> None:
|
||||
"""Initialise the tree widget for the status box."""
|
||||
self.tree = QTreeWidget(self)
|
||||
self.tree.setHeaderHidden(True)
|
||||
# TODO probably here is a problem still with setting the stylesheet
|
||||
self.tree.setStyleSheet(
|
||||
@ -163,6 +164,7 @@ class BECStatusBox(BECWidget, QWidget):
|
||||
status (BECStatus): The state of the core services.
|
||||
"""
|
||||
self.status_container[self.box_name]["info"].status = status
|
||||
self.set_global_state("emergency" if status == "NOTCONNECTED" else "success")
|
||||
self.service_update.emit(self.status_container[self.box_name]["info"])
|
||||
|
||||
def _update_status_container(
|
||||
@ -308,6 +310,8 @@ if __name__ == "__main__": # pragma: no cover
|
||||
|
||||
from qtpy.QtWidgets import QApplication
|
||||
|
||||
from bec_widgets.utils.colors import set_theme
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
set_theme("dark")
|
||||
main_window = BECStatusBox()
|
||||
|
Reference in New Issue
Block a user