@@ -326,7 +326,8 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
326326 bar_color : Color = (0 , 0 , 0 ),
327327 bar_outline : bool = True ,
328328 background_color : Color = (255 , 255 , 255 ),
329- background_image : Optional [str ] = None ):
329+ background_image : Optional [str ] = None ,
330+ inverse_direction : Optional [bool ] = False ):
330331 # Generate a progress bar and display it
331332 # Provide the background image path to display progress bar with transparent background
332333
@@ -357,11 +358,33 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
357358 bar_image = bar_image .crop (box = (x , y , x + width , y + height ))
358359
359360 # Draw progress bar
360- bar_filled_width = (value / (max_value - min_value ) * width ) - 1
361- if bar_filled_width < 0 :
362- bar_filled_width = 0
361+ if width > height :
362+ bar_filled_width = (value / (max_value - min_value ) * width ) - 1
363+ if bar_filled_width < 0 :
364+ bar_filled_width = 0
365+ else :
366+ bar_filled_height = (value / (max_value - min_value ) * height ) - 1
367+ if bar_filled_height < 0 :
368+ bar_filled_height = 0
363369 draw = ImageDraw .Draw (bar_image )
364- draw .rectangle ([0 , 0 , bar_filled_width , height - 1 ], fill = bar_color , outline = bar_color )
370+
371+ # most common setting
372+ x1 = 0
373+ y1 = 0
374+ x2 = width - 1
375+ y2 = height - 1
376+
377+ if width > height :
378+ if inverse_direction is True :
379+ x1 = width - bar_filled_width
380+ else :
381+ x1 = bar_filled_width
382+ else :
383+ if inverse_direction is True :
384+ y2 = height - bar_filled_height
385+ else :
386+ y1 = bar_filled_height
387+ draw .rectangle ([x1 , y1 , x2 , y2 ], fill = bar_color , outline = bar_color )
365388
366389 if bar_outline :
367390 # Draw outline
0 commit comments