Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions library/lcd/lcd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
bar_color: Color = (0, 0, 0),
bar_outline: bool = True,
background_color: Color = (255, 255, 255),
background_image: Optional[str] = None):
background_image: Optional[str] = None,
inverse_direction: Optional[bool] = False):
# Generate a progress bar and display it
# Provide the background image path to display progress bar with transparent background

Expand Down Expand Up @@ -356,11 +357,33 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
bar_image = bar_image.crop(box=(x, y, x + width, y + height))

# Draw progress bar
bar_filled_width = (value / (max_value - min_value) * width) - 1
if bar_filled_width < 0:
bar_filled_width = 0
if width > height:
bar_filled_width = (value / (max_value - min_value) * width) - 1
if bar_filled_width < 0:
bar_filled_width = 0
else:
bar_filled_height = (value / (max_value - min_value) * height) - 1
if bar_filled_height < 0:
bar_filled_height = 0
draw = ImageDraw.Draw(bar_image)
draw.rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color, outline=bar_color)

# most common setting
x1 = 0
y1 = 0
x2 = width - 1
y2 = height - 1

if width > height:
if inverse_direction is True:
x1 = width - bar_filled_width
else:
x1 = bar_filled_width
else:
if inverse_direction is True:
y2 = height - bar_filled_height
else:
y1 = bar_filled_height
draw.rectangle([x1, y1, x2, y2], fill=bar_color, outline=bar_color)

if bar_outline:
# Draw outline
Expand Down
3 changes: 2 additions & 1 deletion library/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def display_themed_progress_bar(theme_data, value):
bar_color=theme_data.get("BAR_COLOR", (0, 0, 0)),
bar_outline=theme_data.get("BAR_OUTLINE", False),
background_color=theme_data.get("BACKGROUND_COLOR", (255, 255, 255)),
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None))
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None)),
inverse_direction=theme_data.get("INVERSE_DIRECTION", False)
)


Expand Down