Skip to content

Performance boost and simpletest update #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 20, 2020
Merged
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
11 changes: 8 additions & 3 deletions adafruit_progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,17 @@ def progress(self, value):
), "Progress value must be a floating point value."
if self._progress_val > value:
# uncolorize range from width*value+margin to width-margin
for _w in range(int(value * self._width + 2), self._width - 2):
# from right to left
_prev_pixel = max(2, int(self._width * self._progress_val - 2))
_new_pixel = max(int(self._width * value - 2), 2)
for _w in range(_prev_pixel, _new_pixel - 1, -1):
for _h in range(2, self._height - 2):
self._bitmap[_w, _h] = 0
else:
# fully fill progress bar color
for _w in range(2, self._width * value - 2):
# fill from the previous x pixel to the new x pixel
_prev_pixel = max(2, int(self._width * self._progress_val - 3))
_new_pixel = min(int(self._width * value - 2), int(self._width * 1.0 - 3))
for _w in range(_prev_pixel, _new_pixel + 1):
for _h in range(2, self._height - 2):
self._bitmap[_w, _h] = 2
self._progress_val = value
Expand Down
13 changes: 7 additions & 6 deletions examples/progressbar_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@

current_progress = 0.0
while True:
while current_progress <= 1.0:
print("Progress: {}%".format(current_progress * 100))
progress_bar.progress = current_progress
current_progress += 0.05
if current_progress >= 1.0:
current_progress = 0.0
# range end is exclusive so we need to use 1 bigger than max number that we want
for current_progress in range(0, 101, 1):
print("Progress: {}%".format(current_progress))
progress_bar.progress = current_progress / 100 # convert to decimal
time.sleep(0.01)
time.sleep(0.3)
progress_bar.progress = 0.0
time.sleep(0.3)