@@ -420,6 +420,29 @@ def DisplayLineGraph(self, x: int, y: int, width: int, height: int,
420420
421421 self .DisplayPILImage (graph_image , x , y )
422422
423+ def DrawRadialDecoration (self , draw : ImageDraw , angle : float , radius : float , width : float , color : Tuple [int , int , int ] = (0 , 0 , 0 )):
424+ i_cos = math .cos (angle * math .pi / 180 )
425+ i_sin = math .sin (angle * math .pi / 180 )
426+ x_f = (i_cos * (radius - width / 2 )) + radius
427+ if math .modf (x_f ) == 0.5 :
428+ if i_cos > 0 :
429+ x_f = math .floor (x_f )
430+ else :
431+ x_f = math .ceil (x_f )
432+ else :
433+ x_f = math .floor (x_f + 0.5 )
434+
435+ y_f = (i_sin * (radius - width / 2 )) + radius
436+ if math .modf (y_f ) == 0.5 :
437+ if i_sin > 0 :
438+ y_f = math .floor (y_f )
439+ else :
440+ y_f = math .ceil (y_f )
441+ else :
442+ y_f = math .floor (y_f + 0.5 )
443+ draw .ellipse ([x_f - width / 2 , y_f - width / 2 , x_f + width / 2 , y_f - 1 + width / 2 - 1 ], outline = color , fill = color , width = 1 )
444+
445+
423446 def DisplayRadialProgressBar (self , xc : int , yc : int , radius : int , bar_width : int ,
424447 min_value : int = 0 ,
425448 max_value : int = 100 ,
@@ -436,7 +459,12 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
436459 font_color : Tuple [int , int , int ] = (0 , 0 , 0 ),
437460 bar_color : Tuple [int , int , int ] = (0 , 0 , 0 ),
438461 background_color : Tuple [int , int , int ] = (255 , 255 , 255 ),
439- background_image : str = None ):
462+ background_image : str = None ,
463+ custom_bbox : Tuple [int , int , int , int ] = (0 , 0 , 0 , 0 ),
464+ text_offset : Tuple [int , int ] = (0 ,0 ),
465+ bar_background_color : Tuple [int , int , int ] = (0 , 0 , 0 ),
466+ draw_bar_background : bool = False ,
467+ bar_decoration : str = "" ):
440468 # Generate a radial progress bar and display it
441469 # Provide the background image path to display progress bar with transparent background
442470
@@ -449,6 +477,9 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
449477 if isinstance (font_color , str ):
450478 font_color = tuple (map (int , font_color .split (', ' )))
451479
480+ if isinstance (bar_background_color , str ):
481+ bar_background_color = tuple (map (int , bar_background_color .split (', ' )))
482+
452483 if angle_start % 361 == angle_end % 361 :
453484 if clockwise :
454485 angle_start += 0.1
@@ -500,6 +531,23 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
500531 ecart = 360 - angle_start + angle_end
501532 else :
502533 ecart = angle_end - angle_start
534+
535+ # draw bar background
536+ if draw_bar_background :
537+ if angle_end < angle_start :
538+ angleE = angle_start + ecart
539+ angleS = angle_start
540+ else :
541+ angleS = angle_start
542+ angleE = angle_start + ecart
543+ draw .arc ([0 , 0 , diameter - 1 , diameter - 1 ], angleS , angleE , fill = bar_background_color , width = bar_width )
544+
545+ # draw bar decoration
546+ if bar_decoration == "Ellipse" :
547+ self .DrawRadialDecoration (draw = draw , angle = angle_end , radius = radius , width = bar_width , color = bar_background_color )
548+ self .DrawRadialDecoration (draw = draw , angle = angle_start , radius = radius , width = bar_width , color = bar_color )
549+ self .DrawRadialDecoration (draw = draw , angle = angle_start + pct * ecart , radius = radius , width = bar_width , color = bar_color )
550+
503551 #
504552 # solid bar case
505553 if angle_sep == 0 :
@@ -533,6 +581,25 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
533581 ecart = angle_start - angle_end
534582 else :
535583 ecart = 360 - angle_end + angle_start
584+
585+ # draw bar background
586+ if draw_bar_background :
587+ if angle_end < angle_start :
588+ angleE = angle_start
589+ angleS = angle_start - ecart
590+ else :
591+ angleS = angle_start - ecart
592+ angleE = angle_start
593+ draw .arc ([0 , 0 , diameter - 1 , diameter - 1 ], angleS , angleE , fill = bar_background_color , width = bar_width )
594+
595+
596+ # draw bar decoration
597+ if bar_decoration == "Ellipse" :
598+ self .DrawRadialDecoration (draw = draw , angle = angle_end , radius = radius , width = bar_width , color = bar_background_color )
599+ self .DrawRadialDecoration (draw = draw , angle = angle_start , radius = radius , width = bar_width , color = bar_color )
600+ self .DrawRadialDecoration (draw = draw , angle = angle_start - pct * ecart , radius = radius , width = bar_width , color = bar_color )
601+
602+ #
536603 # solid bar case
537604 if angle_sep == 0 :
538605 if angle_end < angle_start :
@@ -568,10 +635,14 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
568635 font = ImageFont .truetype ("./res/fonts/" + font , font_size )
569636 left , top , right , bottom = font .getbbox (text )
570637 w , h = right - left , bottom - top
571- draw .text ((radius - w / 2 , radius - top - h / 2 ), text ,
638+ draw .text ((radius - w / 2 + text_offset [ 0 ] , radius - top - h / 2 + text_offset [ 1 ] ), text ,
572639 font = font , fill = font_color )
573640
574- self .DisplayPILImage (bar_image , xc - radius , yc - radius )
641+ if custom_bbox [0 ] != 0 or custom_bbox [1 ] != 0 or custom_bbox [2 ] != 0 or custom_bbox [3 ] != 0 :
642+ bar_image = bar_image .crop (box = custom_bbox )
643+
644+ self .DisplayPILImage (bar_image , xc - radius + custom_bbox [0 ], yc - radius + custom_bbox [1 ])
645+ # self.DisplayPILImage(bar_image, xc - radius, yc - radius)
575646
576647 # Load image from the filesystem, or get from the cache if it has already been loaded previously
577648 def open_image (self , bitmap_path : str ) -> Image :
0 commit comments