Skip to content

Commit 7a29bc0

Browse files
committed
Fix CP syntax issues
Currently broken: progress display value Tested on: Matrix Portal
1 parent a0836c9 commit 7a29bc0

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

adafruit_progressbar/__init__.py

+31-24
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class ProgressBarBase(displayio.TileGrid):
6565
# pylint: disable=too-many-arguments
6666
def __init__(
6767
self,
68-
position: (int, int),
69-
size: (int, int),
70-
start_value: float = 0.0,
68+
position,
69+
size,
70+
start_value=0.0,
7171
bar_color=0x00FF00,
7272
outline_color=0xFFFFFF,
7373
fill_color=0x000000,
@@ -76,10 +76,11 @@ def __init__(
7676
value_range=(0.0, 1.0),
7777
):
7878

79-
self._size = size
79+
self._widget_size = size
8080
self._position = position
8181
self._progress = start_value
82-
self._bitmap = displayio.Bitmap(self.width, self.height, 3)
82+
print(f"Size: {size} - WS: {self.widget_size}")
83+
self._bitmap = displayio.Bitmap(size[0], size[1], 3)
8384
self._palette = displayio.Palette(3)
8485
self._palette[0] = fill_color
8586
self._palette[1] = outline_color
@@ -97,30 +98,36 @@ def __init__(
9798

9899
self._draw_outline()
99100

100-
_bitmap: displayio.Bitmap # The bitmap used for the bar/value
101-
_position: (int, int) # The (x,y) coordinates of the top-left corner
102-
_size: (int, int) # The dimensions of the progress bar
103-
_palette: displayio.Palette(3) # The palette to be used
104-
_progress: float # The value to represent, between 0.0 and 100.0
105-
_border_thickness: int # The thickness of the border around the control, in pixels
106-
_show_margin: bool # Whether we should display a margin between the border and the value/bar
107-
# The minimum and maximum values we can represent
108-
_range: (int, int) or (float, float)
101+
# _bitmap: displayio.Bitmap # The bitmap used for the bar/value
102+
# _position: (int, int) # The (x,y) coordinates of the top-left corner
103+
# _widget_size: (int, int) # The dimensions of the progress bar
104+
# _palette: displayio.Palette(3) # The palette to be used
105+
# _progress: float # The value to represent, between 0.0 and 100.0
106+
# _border_thickness: int # The thickness of the border around the control, in pixels
107+
# _show_margin: bool # Whether we should display a margin between
108+
# the border and the value/bar
109+
# # The minimum and maximum values we can represent
110+
# _range: (int, int) or (float, float)
109111

110112
@property
111-
def size(self):
113+
def widget_size(self):
112114
"""The size at the outer edge of the control, returned as a tuple (width, height)"""
113-
return self._size
115+
return self._widget_size
114116

115117
@property
116-
def width(self):
118+
def widget_width(self):
117119
"""The total width of the widget, in pixels. Includes the border and margin."""
118-
return self.size[0]
120+
return self.widget_size[0]
119121

120122
@property
121-
def height(self):
123+
def widget_height(self):
122124
"""The total height of the widget, in pixels. Includes the border and margin."""
123-
return self.size[1]
125+
return self.widget_size[1]
126+
127+
@property
128+
def _outline_color(self):
129+
"""The colour of the border/outline of the widget"""
130+
return self._palette[1]
124131

125132
@property
126133
def x(self):
@@ -176,14 +183,14 @@ def _draw_outline(self):
176183
stroke = self.border_thickness
177184

178185
# draw outline rectangle
179-
for _w in range(self.width):
186+
for _w in range(self.widget_width):
180187
for line in range(stroke):
181188
self._bitmap[_w, line] = 1
182-
self._bitmap[_w, self.height - 1 - line] = 1
183-
for _h in range(self.height):
189+
self._bitmap[_w, self.widget_height - 1 - line] = 1
190+
for _h in range(self.widget_height):
184191
for line in range(stroke):
185192
self._bitmap[line, _h] = 1
186-
self._bitmap[self.width - 1 - line, _h] = 1
193+
self._bitmap[self.widget_width - 1 - line, _h] = 1
187194

188195
def render(self, _old_value, _new_value, _progress_value) -> None:
189196
"""The method called when the display needs to be updated. This method

adafruit_progressbar/progressbar.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(
7777
value_range=(0.0, 1.0),
7878
)
7979

80-
_outline_color: int # The colour used for the border of the widget
80+
# _outline_color: int # The colour used for the border of the widget
8181

8282
@property
8383
def progress(self):
@@ -97,7 +97,7 @@ def progress(self, value):
9797
), "Progress value must be a floating point value."
9898

9999
# pylint: disable=no-member
100-
ProgressBarBase.progress.fset(self, value)
100+
self._progress = value
101101

102102
@property
103103
def outline_color(self):
@@ -144,17 +144,18 @@ def render(self, _previous_value, _new_value, _progress_value) -> None:
144144
if _previous_value > _new_value:
145145
# uncolorize range from width*value+margin to width-margin
146146
# from right to left
147-
_prev_pixel = max(2, int(self.width * self.progress - 2))
148-
_new_pixel = max(int(self.width * _new_value - 2), 2)
147+
_prev_pixel = max(2, int(self.widget_width * self.progress - 2))
148+
_new_pixel = max(int(self.widget_width * _new_value - 2), 2)
149149
for _w in range(_prev_pixel, _new_pixel - 1, -1):
150-
for _h in range(2, self.height - 2):
150+
for _h in range(2, self.widget_height - 2):
151151
self._bitmap[_w, _h] = 0
152152
else:
153153
# fill from the previous x pixel to the new x pixel
154-
_prev_pixel = max(2, int(self.width * self.progress - 3))
154+
_prev_pixel = max(2, int(self.widget_width * self.progress - 3))
155155
_new_pixel = min(
156-
int(self.width * _new_value - 2), int(self.width * 1.0 - 3)
156+
int(self.widget_width * _new_value - 2),
157+
int(self.widget_width * 1.0 - 3),
157158
)
158159
for _w in range(_prev_pixel, _new_pixel + 1):
159-
for _h in range(2, self.height - 2):
160+
for _h in range(2, self.widget_height - 2):
160161
self._bitmap[_w, _h] = 2

0 commit comments

Comments
 (0)