@@ -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
@@ -104,9 +106,6 @@ def __init__(
104106 self .progressbar .setMinimumHeight (0 )
105107 self .progressbar .setSizePolicy (QSizePolicy .Policy .Expanding , QSizePolicy .Policy .Ignored )
106108
107- # Backwards-compatible alias used by existing tests and downstream code.
108- self .center_label = self .progressbar
109-
110109 self ._layout = QVBoxLayout (self )
111110 self ._layout .setContentsMargins (self ._padding_left_right , 0 , self ._padding_left_right , 0 )
112111 self ._layout .setSpacing (0 )
@@ -339,6 +338,7 @@ def _sync_progressbar(self) -> None:
339338
340339 def _setup_style_sheet (self , * , chunk_radius : int ) -> None :
341340 radius = int (round (self ._corner_radius ))
341+ chunk_color = self ._state_colors [self ._current_visual_state ()].name ()
342342 self .progressbar .setStyleSheet (f"""
343343 QProgressBar {{
344344 background-color: palette(mid);
@@ -348,7 +348,7 @@ def _setup_style_sheet(self, *, chunk_radius: int) -> None:
348348 text-align: center;
349349 }}
350350 QProgressBar::chunk {{
351- background-color: palette(highlight) ;
351+ background-color: { chunk_color } ;
352352 border-radius: { chunk_radius } px;
353353 }}
354354 """ )
@@ -377,6 +377,11 @@ def _initial_chunk_radius(self) -> int:
377377 return 0 if self ._enable_dynamic_stylesheet else self ._target_chunk_radius ()
378378
379379 def _calculate_chunk_radius (self , target_radius : int ) -> int :
380+ """
381+ This whole chunk logic is to calculater radius based on the current size.
382+ If the radius is smaller than size of the progressbar it is just not applied.
383+ The chunk stylesheet logic is smoothing it as much as possible.
384+ """
380385 if target_radius <= 0 or self ._maximum <= 0 :
381386 return 0
382387 fill_width = self .progressbar .width () * min (1.0 , max (0.0 , self ._value / self ._maximum ))
@@ -385,6 +390,16 @@ def _calculate_chunk_radius(self, target_radius: int) -> int:
385390 return min (target_radius , max (1 , int (fill_width / 2 )))
386391
387392 def _apply_state_style (self ) -> None :
393+ chunk_radius = self ._chunk_radius
394+ if chunk_radius is None :
395+ target_radius = self ._target_chunk_radius ()
396+ chunk_radius = (
397+ self ._calculate_chunk_radius (target_radius )
398+ if self ._enable_dynamic_stylesheet
399+ else target_radius
400+ )
401+ self ._chunk_radius = chunk_radius
402+ self ._setup_style_sheet (chunk_radius = chunk_radius )
388403 color = self ._state_colors [self ._current_visual_state ()]
389404 palette = self .progressbar .palette ()
390405 palette .setColor (QPalette .ColorRole .Highlight , color )
@@ -406,20 +421,23 @@ def _get_label(self) -> str:
406421if __name__ == "__main__" : # pragma: no cover
407422 app = QApplication (sys .argv )
408423
409- progressBar = BECProgressBar ()
410- progressBar .show ()
411- progressBar .set_minimum (- 100 )
412- progressBar .set_maximum (0 )
424+ progress_bar = BECProgressBar ()
425+ progress_bar .setWindowTitle ("BEC Progress Bar" )
426+ progress_bar .resize (360 , 48 )
427+ progress_bar .set_minimum (- 100 )
428+ progress_bar .set_maximum (0 )
429+ progress_bar .set_value (- 100 )
430+ progress_bar .show ()
413431
414432 # Example of setting values
415433 def update_progress ():
416- value = progressBar ._user_value + 2.5
417- if value > progressBar ._user_maximum :
418- value = - 100 # progressBar._maximum / progressBar._upsampling_factor
419- progressBar .set_value (value )
434+ value = progress_bar ._user_value + 2.5
435+ if value > progress_bar ._user_maximum :
436+ value = progress_bar . _user_minimum
437+ progress_bar .set_value (value )
420438
421- timer = QTimer ()
439+ timer = QTimer (progress_bar )
422440 timer .timeout .connect (update_progress )
423- timer .start (200 ) # Update every half second
441+ timer .start (200 )
424442
425443 sys .exit (app .exec ())
0 commit comments