mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
fix(scan_progressbar): mapping of bec progress states to the progressbar enums
This commit is contained in:
@ -12,6 +12,22 @@ class ProgressState(Enum):
|
|||||||
INTERRUPTED = "interrupted"
|
INTERRUPTED = "interrupted"
|
||||||
COMPLETED = "completed"
|
COMPLETED = "completed"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_bec_status(cls, status: str) -> "ProgressState":
|
||||||
|
"""
|
||||||
|
Map a BEC status string (open, paused, aborted, halted, closed)
|
||||||
|
to the corresponding ProgressState.
|
||||||
|
Any unknown status falls back to NORMAL.
|
||||||
|
"""
|
||||||
|
mapping = {
|
||||||
|
"open": cls.NORMAL,
|
||||||
|
"paused": cls.PAUSED,
|
||||||
|
"aborted": cls.INTERRUPTED,
|
||||||
|
"halted": cls.PAUSED,
|
||||||
|
"closed": cls.COMPLETED,
|
||||||
|
}
|
||||||
|
return mapping.get(status.lower(), cls.NORMAL)
|
||||||
|
|
||||||
|
|
||||||
PROGRESS_STATE_COLORS = {
|
PROGRESS_STATE_COLORS = {
|
||||||
ProgressState.NORMAL: QColor("#2979ff"), # blue – normal progress
|
ProgressState.NORMAL: QColor("#2979ff"), # blue – normal progress
|
||||||
@ -19,7 +35,6 @@ PROGRESS_STATE_COLORS = {
|
|||||||
ProgressState.INTERRUPTED: QColor("#ff5252"), # red – interrupted
|
ProgressState.INTERRUPTED: QColor("#ff5252"), # red – interrupted
|
||||||
ProgressState.COMPLETED: QColor("#00e676"), # green – finished
|
ProgressState.COMPLETED: QColor("#00e676"), # green – finished
|
||||||
}
|
}
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
from qtpy.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
|
from qtpy.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
import enum
|
import enum
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from bec_lib.endpoints import MessageEndpoints
|
from bec_lib.endpoints import MessageEndpoints
|
||||||
@ -13,6 +14,7 @@ from qtpy.QtWidgets import QVBoxLayout, QWidget
|
|||||||
from bec_widgets.utils.bec_widget import BECWidget
|
from bec_widgets.utils.bec_widget import BECWidget
|
||||||
from bec_widgets.utils.error_popups import SafeProperty, SafeSlot
|
from bec_widgets.utils.error_popups import SafeProperty, SafeSlot
|
||||||
from bec_widgets.utils.ui_loader import UILoader
|
from bec_widgets.utils.ui_loader import UILoader
|
||||||
|
from bec_widgets.widgets.progress.bec_progressbar.bec_progressbar import ProgressState
|
||||||
|
|
||||||
logger = bec_logger.logger
|
logger = bec_logger.logger
|
||||||
|
|
||||||
@ -183,13 +185,17 @@ class ScanProgressBar(BECWidget, QWidget):
|
|||||||
logger.info(f"Set progress source to {text}")
|
logger.info(f"Set progress source to {text}")
|
||||||
self.ui.source_label.setText(text)
|
self.ui.source_label.setText(text)
|
||||||
|
|
||||||
def on_progress_update(self, msg_content, metadata):
|
@SafeSlot(dict, dict)
|
||||||
|
def on_progress_update(self, msg_content: dict, metadata: dict):
|
||||||
"""
|
"""
|
||||||
Update the progress bar based on the progress message.
|
Update the progress bar based on the progress message.
|
||||||
"""
|
"""
|
||||||
value = msg_content["value"]
|
value = msg_content["value"]
|
||||||
max_value = msg_content.get("max_value", 100)
|
max_value = msg_content.get("max_value", 100)
|
||||||
done = msg_content.get("done", False)
|
done = msg_content.get("done", False)
|
||||||
|
status: Literal["open", "paused", "aborted", "halted", "closed"] = metadata.get(
|
||||||
|
"status", "open"
|
||||||
|
)
|
||||||
|
|
||||||
if self.task is None:
|
if self.task is None:
|
||||||
return
|
return
|
||||||
@ -198,13 +204,13 @@ class ScanProgressBar(BECWidget, QWidget):
|
|||||||
self.update_labels()
|
self.update_labels()
|
||||||
|
|
||||||
self.progressbar.set_maximum(self.task.max_value)
|
self.progressbar.set_maximum(self.task.max_value)
|
||||||
|
self.progressbar.state = ProgressState.from_bec_status(status)
|
||||||
|
self.progressbar.set_value(self.task.value)
|
||||||
|
|
||||||
if done:
|
if done:
|
||||||
self.progressbar.set_value(self.task.max_value)
|
|
||||||
self.task = None
|
self.task = None
|
||||||
return
|
return
|
||||||
|
|
||||||
self.progressbar.set_value(self.task.value)
|
|
||||||
|
|
||||||
@SafeProperty(bool)
|
@SafeProperty(bool)
|
||||||
def show_elapsed_time(self):
|
def show_elapsed_time(self):
|
||||||
return self.ui.elapsed_time_label.isVisible()
|
return self.ui.elapsed_time_label.isVisible()
|
||||||
|
Reference in New Issue
Block a user