@@ -445,6 +445,29 @@ def DisplayLineGraph(self, x: int, y: int, width: int, height: int,
445445
446446 self .DisplayPILImage (graph_image , x , y )
447447
448+ def DrawRadialDecoration (self , draw : ImageDraw , angle : float , radius : float , width : float , color : Tuple [int , int , int ] = (0 , 0 , 0 )):
449+ i_cos = math .cos (angle * math .pi / 180 )
450+ i_sin = math .sin (angle * math .pi / 180 )
451+ x_f = (i_cos * (radius - width / 2 )) + radius
452+ if math .modf (x_f ) == 0.5 :
453+ if i_cos > 0 :
454+ x_f = math .floor (x_f )
455+ else :
456+ x_f = math .ceil (x_f )
457+ else :
458+ x_f = math .floor (x_f + 0.5 )
459+
460+ y_f = (i_sin * (radius - width / 2 )) + radius
461+ if math .modf (y_f ) == 0.5 :
462+ if i_sin > 0 :
463+ y_f = math .floor (y_f )
464+ else :
465+ y_f = math .ceil (y_f )
466+ else :
467+ y_f = math .floor (y_f + 0.5 )
468+ 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 )
469+
470+
448471 def DisplayRadialProgressBar (self , xc : int , yc : int , radius : int , bar_width : int ,
449472 min_value : int = 0 ,
450473 max_value : int = 100 ,
@@ -461,7 +484,12 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
461484 font_color : Tuple [int , int , int ] = (0 , 0 , 0 ),
462485 bar_color : Tuple [int , int , int ] = (0 , 0 , 0 ),
463486 background_color : Tuple [int , int , int ] = (255 , 255 , 255 ),
464- background_image : str = None ):
487+ background_image : str = None ,
488+ custom_bbox : Tuple [int , int , int , int ] = (0 , 0 , 0 , 0 ),
489+ text_offset : Tuple [int , int ] = (0 ,0 ),
490+ bar_background_color : Tuple [int , int , int ] = (0 , 0 , 0 ),
491+ draw_bar_background : bool = False ,
492+ bar_decoration : str = "" ):
465493 # Generate a radial progress bar and display it
466494 # Provide the background image path to display progress bar with transparent background
467495
@@ -474,6 +502,9 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
474502 if isinstance (font_color , str ):
475503 font_color = tuple (map (int , font_color .split (', ' )))
476504
505+ if isinstance (bar_background_color , str ):
506+ bar_background_color = tuple (map (int , bar_background_color .split (', ' )))
507+
477508 if angle_start % 361 == angle_end % 361 :
478509 if clockwise :
479510 angle_start += 0.1
@@ -525,6 +556,23 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
525556 ecart = 360 - angle_start + angle_end
526557 else :
527558 ecart = angle_end - angle_start
559+
560+ # draw bar background
561+ if draw_bar_background :
562+ if angle_end < angle_start :
563+ angleE = angle_start + ecart
564+ angleS = angle_start
565+ else :
566+ angleS = angle_start
567+ angleE = angle_start + ecart
568+ draw .arc ([0 , 0 , diameter - 1 , diameter - 1 ], angleS , angleE , fill = bar_background_color , width = bar_width )
569+
570+ # draw bar decoration
571+ if bar_decoration == "Ellipse" :
572+ self .DrawRadialDecoration (draw = draw , angle = angle_end , radius = radius , width = bar_width , color = bar_background_color )
573+ self .DrawRadialDecoration (draw = draw , angle = angle_start , radius = radius , width = bar_width , color = bar_color )
574+ self .DrawRadialDecoration (draw = draw , angle = angle_start + pct * ecart , radius = radius , width = bar_width , color = bar_color )
575+
528576 #
529577 # solid bar case
530578 if angle_sep == 0 :
@@ -558,6 +606,25 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
558606 ecart = angle_start - angle_end
559607 else :
560608 ecart = 360 - angle_end + angle_start
609+
610+ # draw bar background
611+ if draw_bar_background :
612+ if angle_end < angle_start :
613+ angleE = angle_start
614+ angleS = angle_start - ecart
615+ else :
616+ angleS = angle_start - ecart
617+ angleE = angle_start
618+ draw .arc ([0 , 0 , diameter - 1 , diameter - 1 ], angleS , angleE , fill = bar_background_color , width = bar_width )
619+
620+
621+ # draw bar decoration
622+ if bar_decoration == "Ellipse" :
623+ self .DrawRadialDecoration (draw = draw , angle = angle_end , radius = radius , width = bar_width , color = bar_background_color )
624+ self .DrawRadialDecoration (draw = draw , angle = angle_start , radius = radius , width = bar_width , color = bar_color )
625+ self .DrawRadialDecoration (draw = draw , angle = angle_start - pct * ecart , radius = radius , width = bar_width , color = bar_color )
626+
627+ #
561628 # solid bar case
562629 if angle_sep == 0 :
563630 if angle_end < angle_start :
@@ -593,10 +660,14 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
593660 font = ImageFont .truetype ("./res/fonts/" + font , font_size )
594661 left , top , right , bottom = font .getbbox (text )
595662 w , h = right - left , bottom - top
596- draw .text ((radius - w / 2 , radius - top - h / 2 ), text ,
663+ draw .text ((radius - w / 2 + text_offset [ 0 ] , radius - top - h / 2 + text_offset [ 1 ] ), text ,
597664 font = font , fill = font_color )
598665
599- self .DisplayPILImage (bar_image , xc - radius , yc - radius )
666+ if custom_bbox [0 ] != 0 or custom_bbox [1 ] != 0 or custom_bbox [2 ] != 0 or custom_bbox [3 ] != 0 :
667+ bar_image = bar_image .crop (box = custom_bbox )
668+
669+ self .DisplayPILImage (bar_image , xc - radius + custom_bbox [0 ], yc - radius + custom_bbox [1 ])
670+ # self.DisplayPILImage(bar_image, xc - radius, yc - radius)
600671
601672 # Load image from the filesystem, or get from the cache if it has already been loaded previously
602673 def open_image (self , bitmap_path : str ) -> Image :
0 commit comments