Skip to content

Commit db59686

Browse files
committed
refactor code, inverse now a graph setting
1 parent d5a2f27 commit db59686

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

library/lcd/lcd_comm.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,23 +325,14 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
325325
bar_color: Color = (0, 0, 0),
326326
bar_outline: bool = True,
327327
background_color: Color = (255, 255, 255),
328-
background_image: Optional[str] = None):
328+
background_image: Optional[str] = None,
329+
inverse_direction: Optional[bool] = False):
329330
# Generate a progress bar and display it
330331
# Provide the background image path to display progress bar with transparent background
331332

332333
bar_color = parse_color(bar_color)
333334
background_color = parse_color(background_color)
334335

335-
inverse = False
336-
# Assume we want to invert the direction is width or height are negative
337-
if width < 0:
338-
inverse = True
339-
width = width * -1
340-
341-
if height < 0:
342-
inverse = True
343-
height = height * -1
344-
345336
assert x <= self.get_width(), 'Progress bar X coordinate must be <= display width'
346337
assert y <= self.get_height(), 'Progress bar Y coordinate must be <= display height'
347338
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:
375366
if bar_filled_height < 0:
376367
bar_filled_height = 0
377368
draw = ImageDraw.Draw(bar_image)
369+
370+
# most common setting
371+
x1 = 0
372+
y1 = 0
373+
x2 = width - 1
374+
y2 = height - 1
375+
378376
if width > height:
379-
if inverse is True:
380-
draw.rectangle([width - bar_filled_width, 0, width -1, height - 1], fill=bar_color, outline=bar_color)
377+
if inverse_direction is True:
378+
x1 = width - bar_filled_width
381379
else:
382-
draw.rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color, outline=bar_color)
380+
x1 = bar_filled_width
383381
else:
384-
if inverse is True:
385-
draw.rectangle([0, 0, width - 1, height - bar_filled_height], fill=bar_color, outline=bar_color)
382+
if inverse_direction is True:
383+
y2 = height - bar_filled_height
386384
else:
387-
draw.rectangle([0, bar_filled_height, width - 1, height - 1], fill=bar_color, outline=bar_color)
385+
y1 = bar_filled_height
386+
draw.rectangle([x1, y1, x2, y2], fill=bar_color, outline=bar_color)
388387

389388
if bar_outline:
390389
# Draw outline

library/stats.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def display_themed_progress_bar(theme_data, value):
153153
bar_color=theme_data.get("BAR_COLOR", (0, 0, 0)),
154154
bar_outline=theme_data.get("BAR_OUTLINE", False),
155155
background_color=theme_data.get("BACKGROUND_COLOR", (255, 255, 255)),
156-
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None))
156+
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None)),
157+
inverse_direction=theme_data.get("INVERSE_DIRECTION", False)
157158
)
158159

159160

0 commit comments

Comments
 (0)