Skip to content

Commit b0faeb5

Browse files
committed
wip fix scan colorcoding
1 parent 57260f7 commit b0faeb5

5 files changed

Lines changed: 32 additions & 9 deletions

File tree

bec_widgets/widgets/progress/bec_progressbar/bec_progressbar.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ class ProgressState(Enum):
2020
@classmethod
2121
def from_bec_status(cls, status: str) -> "ProgressState":
2222
"""
23-
Map a BEC status string (open, paused, aborted, halted, closed)
23+
Map a BEC status string (open, paused, aborted, halt/halted, closed, user_completed)
2424
to the corresponding ProgressState.
2525
Any unknown status falls back to NORMAL.
2626
"""
2727
mapping = {
2828
"open": cls.NORMAL,
2929
"paused": cls.PAUSED,
3030
"aborted": cls.INTERRUPTED,
31+
"halt": cls.PAUSED,
3132
"halted": cls.PAUSED,
3233
"closed": cls.COMPLETED,
34+
"user_completed": cls.PAUSED,
3335
}
3436
return mapping.get(status.lower(), cls.NORMAL)
3537

@@ -339,6 +341,7 @@ def _sync_progressbar(self) -> None:
339341

340342
def _setup_style_sheet(self, *, chunk_radius: int) -> None:
341343
radius = int(round(self._corner_radius))
344+
chunk_color = self._state_colors[self._current_visual_state()].name()
342345
self.progressbar.setStyleSheet(f"""
343346
QProgressBar {{
344347
background-color: palette(mid);
@@ -348,7 +351,7 @@ def _setup_style_sheet(self, *, chunk_radius: int) -> None:
348351
text-align: center;
349352
}}
350353
QProgressBar::chunk {{
351-
background-color: palette(highlight);
354+
background-color: {chunk_color};
352355
border-radius: {chunk_radius}px;
353356
}}
354357
""")
@@ -385,6 +388,16 @@ def _calculate_chunk_radius(self, target_radius: int) -> int:
385388
return min(target_radius, max(1, int(fill_width / 2)))
386389

387390
def _apply_state_style(self) -> None:
391+
chunk_radius = self._chunk_radius
392+
if chunk_radius is None:
393+
target_radius = self._target_chunk_radius()
394+
chunk_radius = (
395+
self._calculate_chunk_radius(target_radius)
396+
if self._enable_dynamic_stylesheet
397+
else target_radius
398+
)
399+
self._chunk_radius = chunk_radius
400+
self._setup_style_sheet(chunk_radius=chunk_radius)
388401
color = self._state_colors[self._current_visual_state()]
389402
palette = self.progressbar.palette()
390403
palette.setColor(QPalette.ColorRole.Highlight, color)

bec_widgets/widgets/progress/progress_backend.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ProgressSnapshot:
2525
value: float
2626
max_value: float
2727
done: bool
28-
status: Literal["open", "paused", "aborted", "halted", "closed"]
28+
status: Literal["open", "paused", "aborted", "halt", "halted", "closed", "user_completed"]
2929
device: str | None = None
3030
scan_id: str | None = None
3131
scan_number: int | None = None
@@ -200,7 +200,9 @@ def current_snapshot(
200200
value: float,
201201
max_value: float,
202202
done: bool,
203-
status: Literal["open", "paused", "aborted", "halted", "closed"] = "open",
203+
status: Literal[
204+
"open", "paused", "aborted", "halt", "halted", "closed", "user_completed"
205+
] = "open",
204206
is_new_scan: bool = False,
205207
) -> ProgressSnapshot:
206208
source = self._progress_source or ProgressSource.SCAN_PROGRESS
@@ -257,9 +259,9 @@ def process_progress_message(
257259
done = msg_content.get("done", False)
258260
value = msg_content.get("value", 0)
259261
max_value = msg_content.get("max_value", 100)
260-
status: Literal["open", "paused", "aborted", "halted", "closed"] = metadata.get(
261-
"status", "open"
262-
)
262+
status: Literal[
263+
"open", "paused", "aborted", "halt", "halted", "closed", "user_completed"
264+
] = metadata.get("status", "open")
263265
if done and source == ProgressSource.DEVICE_PROGRESS:
264266
value = max_value
265267
scan_id = metadata.get("scan_id") or metadata.get("RID")

bec_widgets/widgets/progress/scan_progressbar/scan_progressbar.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ def _on_progress_snapshot(self, snapshot: ProgressSnapshot):
149149
self.update_labels()
150150
self.update_source_label(snapshot.source, device=snapshot.device)
151151
self.progressbar.set_maximum(snapshot.max_value)
152-
self.progressbar.state = ProgressState.from_bec_status(snapshot.status)
152+
state = ProgressState.from_bec_status(snapshot.status)
153+
self.progressbar.state = state
153154
self.progressbar.set_value(snapshot.value)
154155

155156
@SafeProperty(bool)

tests/unit_tests/test_bec_progressbar.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ def test_progressbar_uses_static_stylesheet_with_palette_state_color(progressbar
6363

6464
style_sheet = progressbar.progressbar.styleSheet()
6565
assert "QProgressBar::chunk" in style_sheet
66-
assert "background-color: palette(highlight);" in style_sheet
66+
assert (
67+
f"background-color: {progressbar._state_colors[ProgressState.PAUSED].name()};"
68+
in style_sheet
69+
)
6770
assert "background-color: palette(mid);" in style_sheet
6871
assert "border-radius: 7px;" in style_sheet
6972
assert (
@@ -171,8 +174,10 @@ def test_progress_state_from_bec_status():
171174
"open": ProgressState.NORMAL,
172175
"paused": ProgressState.PAUSED,
173176
"aborted": ProgressState.INTERRUPTED,
177+
"halt": ProgressState.PAUSED,
174178
"halted": ProgressState.PAUSED,
175179
"closed": ProgressState.COMPLETED,
180+
"user_completed": ProgressState.PAUSED,
176181
"UNKNOWN": ProgressState.NORMAL, # fallback
177182
}
178183
for text, expected in mapping.items():

tests/unit_tests/test_scan_progress_bar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ def test_on_progress_update(qtbot, scan_progressbar):
125125
("open", 10, 100, ProgressState.NORMAL),
126126
("paused", 25, 100, ProgressState.PAUSED),
127127
("aborted", 30, 100, ProgressState.INTERRUPTED),
128+
("halt", 40, 100, ProgressState.PAUSED),
128129
("halted", 40, 100, ProgressState.PAUSED),
129130
("closed", 100, 100, ProgressState.COMPLETED),
131+
("user_completed", 40, 100, ProgressState.PAUSED),
130132
],
131133
)
132134
def test_state_mapping_during_updates(

0 commit comments

Comments
 (0)