From 9c436e19df7a3163ff416a412828a7dae97c7242 Mon Sep 17 00:00:00 2001 From: Colin Shorts Date: Wed, 26 Nov 2025 18:06:37 +0000 Subject: [PATCH 1/3] feat: Add vertical progress bar --- library/lcd/lcd_comm.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/library/lcd/lcd_comm.py b/library/lcd/lcd_comm.py index 4e2714fe..9de85b98 100644 --- a/library/lcd/lcd_comm.py +++ b/library/lcd/lcd_comm.py @@ -356,11 +356,19 @@ 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) + if width > height: + draw.rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color, outline=bar_color) + else: + draw.rectangle([0, height - bar_filled_height, width - 1, height - 1], fill=bar_color, outline=bar_color) if bar_outline: # Draw outline From d5a2f27d04e75126e16a3c7109201d2548b9d767 Mon Sep 17 00:00:00 2001 From: Colin Shorts Date: Fri, 28 Nov 2025 17:50:17 +0000 Subject: [PATCH 2/3] feat: Add inverse direction for progress bar --- library/lcd/lcd_comm.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/library/lcd/lcd_comm.py b/library/lcd/lcd_comm.py index 9de85b98..f53746d4 100644 --- a/library/lcd/lcd_comm.py +++ b/library/lcd/lcd_comm.py @@ -332,6 +332,16 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value: bar_color = parse_color(bar_color) background_color = parse_color(background_color) + inverse = False + # Assume we want to invert the direction is width or height are negative + if width < 0: + inverse = True + width = width * -1 + + if height < 0: + inverse = True + height = height * -1 + assert x <= self.get_width(), 'Progress bar X coordinate must be <= display width' assert y <= self.get_height(), 'Progress bar Y coordinate must be <= display height' assert x + width <= self.get_width(), 'Progress bar width exceeds display width' @@ -366,9 +376,15 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value: bar_filled_height = 0 draw = ImageDraw.Draw(bar_image) if width > height: - draw.rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color, outline=bar_color) + if inverse is True: + draw.rectangle([width - bar_filled_width, 0, width -1, height - 1], fill=bar_color, outline=bar_color) + else: + draw.rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color, outline=bar_color) else: - draw.rectangle([0, height - bar_filled_height, width - 1, height - 1], fill=bar_color, outline=bar_color) + if inverse is True: + draw.rectangle([0, 0, width - 1, height - bar_filled_height], fill=bar_color, outline=bar_color) + else: + draw.rectangle([0, bar_filled_height, width - 1, height - 1], fill=bar_color, outline=bar_color) if bar_outline: # Draw outline From db596864638dbb80deff571e62a95b5b86c74aeb Mon Sep 17 00:00:00 2001 From: Colin Shorts Date: Mon, 1 Dec 2025 11:38:52 +0000 Subject: [PATCH 3/3] refactor code, inverse now a graph setting --- library/lcd/lcd_comm.py | 33 ++++++++++++++++----------------- library/stats.py | 3 ++- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/library/lcd/lcd_comm.py b/library/lcd/lcd_comm.py index f53746d4..6b95a0df 100644 --- a/library/lcd/lcd_comm.py +++ b/library/lcd/lcd_comm.py @@ -325,23 +325,14 @@ 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 bar_color = parse_color(bar_color) background_color = parse_color(background_color) - inverse = False - # Assume we want to invert the direction is width or height are negative - if width < 0: - inverse = True - width = width * -1 - - if height < 0: - inverse = True - height = height * -1 - assert x <= self.get_width(), 'Progress bar X coordinate must be <= display width' assert y <= self.get_height(), 'Progress bar Y coordinate must be <= display height' assert x + width <= self.get_width(), 'Progress bar width exceeds display width' @@ -375,16 +366,24 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value: if bar_filled_height < 0: bar_filled_height = 0 draw = ImageDraw.Draw(bar_image) + + # most common setting + x1 = 0 + y1 = 0 + x2 = width - 1 + y2 = height - 1 + if width > height: - if inverse is True: - draw.rectangle([width - bar_filled_width, 0, width -1, height - 1], fill=bar_color, outline=bar_color) + if inverse_direction is True: + x1 = width - bar_filled_width else: - draw.rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color, outline=bar_color) + x1 = bar_filled_width else: - if inverse is True: - draw.rectangle([0, 0, width - 1, height - bar_filled_height], fill=bar_color, outline=bar_color) + if inverse_direction is True: + y2 = height - bar_filled_height else: - draw.rectangle([0, bar_filled_height, width - 1, height - 1], fill=bar_color, outline=bar_color) + y1 = bar_filled_height + draw.rectangle([x1, y1, x2, y2], fill=bar_color, outline=bar_color) if bar_outline: # Draw outline diff --git a/library/stats.py b/library/stats.py index 9af85060..57ba43ac 100644 --- a/library/stats.py +++ b/library/stats.py @@ -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) )