From c40ce539556be16dfed7f36e7cda283cc9fa6681 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Mon, 15 Jun 2026 22:07:09 +0200 Subject: [PATCH] fix: abort button should use request id --- .../buttons/button_abort/button_abort.py | 17 ++++++------ .../widgets/services/bec_queue/bec_queue.py | 27 +++++++++++++------ 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/bec_widgets/widgets/control/buttons/button_abort/button_abort.py b/bec_widgets/widgets/control/buttons/button_abort/button_abort.py index f6414527..60d6721c 100644 --- a/bec_widgets/widgets/control/buttons/button_abort/button_abort.py +++ b/bec_widgets/widgets/control/buttons/button_abort/button_abort.py @@ -12,7 +12,7 @@ logger = bec_logger.logger class AbortButton(BECWidget, QWidget): - """A button that abort the scan.""" + """A button that abort the request.""" PLUGIN = True ICON_NAME = "cancel" @@ -25,11 +25,12 @@ class AbortButton(BECWidget, QWidget): config=None, gui_id=None, toolbar=False, - scan_id=None, + request_id=None, **kwargs, ): super().__init__(parent=parent, client=client, gui_id=gui_id, config=config, **kwargs) self.get_bec_shortcuts() + self.request_id = request_id self.layout = QHBoxLayout(self) self.layout.setSpacing(0) @@ -39,7 +40,7 @@ class AbortButton(BECWidget, QWidget): if toolbar: icon = material_icon("cancel", color="#666666", filled=True) self.button = QToolButton(icon=icon) - self.button.setToolTip("Abort the scan") + self.button.setToolTip("Abort the request") else: self.button = QPushButton() self.button.setText("Abort") @@ -47,8 +48,6 @@ class AbortButton(BECWidget, QWidget): self.layout.addWidget(self.button) - self.scan_id = scan_id - @SafeSlot() def abort_scan( self, @@ -57,10 +56,10 @@ class AbortButton(BECWidget, QWidget): Abort the scan. Args: - scan_id(str|None): The scan id to abort. If None, the current scan will be aborted. + request_id(str|None): The request id to abort. If None, the current scan will be aborted. """ - if self.scan_id is not None: - logger.info(f"Aborting scan with scan_id: {self.scan_id}") - self.queue.request_scan_abortion(scan_id=self.scan_id) + if self.request_id is not None: + logger.info(f"Aborting scan with request_id: {self.request_id}") + self.queue.request_scan_abortion(request_id=self.request_id) else: self.queue.request_scan_abortion() diff --git a/bec_widgets/widgets/services/bec_queue/bec_queue.py b/bec_widgets/widgets/services/bec_queue/bec_queue.py index 5ac32814..6b75a6ea 100644 --- a/bec_widgets/widgets/services/bec_queue/bec_queue.py +++ b/bec_widgets/widgets/services/bec_queue/bec_queue.py @@ -176,6 +176,7 @@ class BECQueue(BECWidget, CompactPopupWidget): scan_names = [] scan_ids = [] user_metadatas = [] + request_ids = [] status = item.status for request_block in blocks: scan_type = request_block.msg.scan_type @@ -193,6 +194,8 @@ class BECQueue(BECWidget, CompactPopupWidget): scan_id = request_block.scan_id if scan_id: scan_ids.append(scan_id) + if request_block.RID: + request_ids.append(request_block.RID) if scan_types: scan_types = ", ".join(scan_types) if scan_numbers: @@ -208,7 +211,15 @@ class BECQueue(BECWidget, CompactPopupWidget): tooltip = json.dumps(user_metadatas, indent=2) if scan_ids: scan_ids = ", ".join(scan_ids) - self.set_row(index, scan_numbers, scan_names, scan_types, status, scan_ids, tooltip) + self.set_row( + index, + scan_numbers, + scan_names, + scan_types, + status, + tooltip, + abort_request_id=request_ids[0] if request_ids else None, + ) busy = ( False if all(item.status in ("STOPPED", "COMPLETED", "IDLE") for item in queue_info) @@ -249,8 +260,8 @@ class BECQueue(BECWidget, CompactPopupWidget): scan_name: str, scan_type: str, status: str, - scan_id: str, tooltip: str = "", + abort_request_id: str = "", ): """ Set the row of the table. @@ -261,10 +272,10 @@ class BECQueue(BECWidget, CompactPopupWidget): scan_name (str): The scan name. scan_type (str): The scan type. status (str): The status. - scan_id (str): The scan id. tooltip (str): Optional tooltip to display (pretty-printed user metadata). + abort_request_id (str): request id to abort. """ - abort_button = self._create_abort_button(scan_id) + abort_button = self._create_abort_button(abort_request_id) abort_button.button.clicked.connect(self.delete_selected_row) self.table.setItem(index, 0, self.format_item(scan_number, tooltip=tooltip)) @@ -273,17 +284,17 @@ class BECQueue(BECWidget, CompactPopupWidget): self.table.setItem(index, 3, self.format_item(status, status=True, tooltip=tooltip)) self.table.setCellWidget(index, 4, abort_button) - def _create_abort_button(self, scan_id: str) -> AbortButton: + def _create_abort_button(self, request_id: str) -> AbortButton: """ - Create an abort button with styling for BEC Queue widget for certain scan_id. + Create an abort button with styling for BEC Queue widget for certain request_id. Args: - scan_id(str): The scan id to abort. + request_id(str): The request id to abort. Returns: AbortButton: The abort button. """ - abort_button = AbortButton(parent=self, scan_id=scan_id) + abort_button = AbortButton(parent=self, request_id=request_id) abort_button.button.setText("") abort_button.button.setIcon(