Skip to content

Commit f089ce1

Browse files
authored
Merge pull request #2 from brentru/add-fill-fix-repeating-bug
Fix bug with decrementing progress bar, add set-able progress bar color fill
2 parents dcfa9e0 + 32da348 commit f089ce1

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

adafruit_progressbar.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def progress(self, value):
105105
assert value <= 1.0, "Progress value may not be > 100%"
106106
assert isinstance(value, float), "Progress value must be a floating point value."
107107
if self._progress_val > value:
108-
# bar colorized up to this position, unfill difference
109-
for _w in range(int(value*self._width+2), self._width*self._progress_val-2):
108+
# uncolorize range from width*value+margin to width-margin
109+
for _w in range(int(value*self._width+2), self._width-2):
110110
for _h in range(2, self._height-2):
111111
self._bitmap[_w, _h] = 0
112112
else:
@@ -115,3 +115,24 @@ def progress(self, value):
115115
for _h in range(2, self._height-2):
116116
self._bitmap[_w, _h] = 2
117117
self._progress_val = value
118+
119+
@property
120+
def fill(self):
121+
"""The fill of the progress bar. Can be a hex value for a color or ``None`` for
122+
transparent.
123+
124+
"""
125+
return self._palette[0]
126+
127+
@fill.setter
128+
def fill(self, color):
129+
"""Sets the fill of the progress bar. Can be a hex value for a color or ``None`` for
130+
transparent.
131+
132+
"""
133+
if color is None:
134+
self._palette[2] = 0
135+
self._palette.make_transparent(0)
136+
else:
137+
self._palette[2] = color
138+
self._palette.make_opaque(0)

0 commit comments

Comments
 (0)