Skip to content

Commit a3362c9

Browse files
committed
Move library file into directory for packaging
Start refactor to base class
1 parent 1e13c49 commit a3362c9

File tree

2 files changed

+104
-8
lines changed

2 files changed

+104
-8
lines changed

adafruit_progressbar.py renamed to Adafruit_ProgressBar/adafruit_progressbar.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
"""
2323

2424
# imports
25-
import displayio
25+
from adafruit_progressbar_base import ProgressBarBase
2626

2727
__version__ = "0.0.0-auto.0"
2828
__repo__ = "https://github.com/brentru/Adafruit_CircuitPython_ProgressBar.git"
2929

3030
# pylint: disable=too-many-arguments, too-few-public-methods
31-
class ProgressBar(displayio.TileGrid):
31+
class ProgressBar(ProgressBarBase):
3232
"""A dynamic progress bar widget.
3333
3434
:param int x: The x-position of the top left corner.
@@ -57,11 +57,6 @@ def __init__(
5757
stroke=1,
5858
):
5959
assert isinstance(progress, float), "Progress must be a floating point value."
60-
self._bitmap = displayio.Bitmap(width, height, 3)
61-
self._palette = displayio.Palette(3)
62-
self._palette[0] = 0x0
63-
self._palette[1] = outline_color
64-
self._palette[2] = bar_color
6560

6661
# _width and _height are already in use for blinka TileGrid
6762
self._bar_width = width
@@ -80,7 +75,15 @@ def __init__(
8075
for line in range(stroke):
8176
self._bitmap[line, _h] = 1
8277
self._bitmap[width - 1 - line, _h] = 1
83-
super().__init__(self._bitmap, pixel_shader=self._palette, x=x, y=y)
78+
79+
super(ProgressBarBase, self).__init__(
80+
(x, y),
81+
(width, height),
82+
self.progress,
83+
self._palette[0],
84+
self._palette[1],
85+
self._palette[2],
86+
)
8487

8588
@property
8689
def progress(self):
@@ -147,3 +150,6 @@ def fill(self, color):
147150
else:
148151
self._palette[2] = color
149152
self._palette.make_opaque(0)
153+
154+
def render(self):
155+
super().render()
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# SPDX-FileCopyrightText: 2020 Brent Rubell for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`adafruit_progressbar`
7+
================================================================================
8+
9+
Dynamic progress bar widget for CircuitPython displays
10+
11+
12+
* Author(s): Brent Rubell and Hugo Dahl
13+
14+
Implementation Notes
15+
--------------------
16+
17+
**Software and Dependencies:**
18+
19+
* Adafruit CircuitPython firmware for the supported boards:
20+
https://github.com/adafruit/circuitpython/releases
21+
22+
"""
23+
24+
# imports
25+
import displayio
26+
27+
__version__ = "0.0.0-auto.0"
28+
__repo__ = "https://github.com/brentru/Adafruit_CircuitPython_ProgressBar.git"
29+
30+
31+
class ProgressBarBase(displayio.TileGrid):
32+
def __init__(
33+
self,
34+
position: (int, int),
35+
size: (int, int),
36+
start_value: float = 0.0,
37+
bar_color=0x00FF00,
38+
outline_color=0xFFFFFF,
39+
fill_color=0x000000,
40+
):
41+
42+
self._size = size
43+
self._position = position
44+
self._progress = start_value
45+
self._bitmap = displayio.Bitmap(self.width, self.height, 3)
46+
self._palette = displayio.Palette(3)
47+
self._palette[0] = fill_color
48+
self._palette[1] = outline_color
49+
self._palette[2] = bar_color
50+
51+
super(ProgressBarBase, self).__init__(
52+
self._bitmap,
53+
pixel_shader=self._palette,
54+
x=self._position[0],
55+
y=self._position[1],
56+
)
57+
58+
_bitmap: displayio.Bitmap # The bitmap used for the bar/value
59+
_position: (int, int) # The (x,y) coordinates of the top-left corner
60+
_size: (int, int) # The dimensions of the progress bar
61+
_palette: displayio.Palette(3) # The palette to be used
62+
_progress: float # The value to represent, between 0.0 and 100.0
63+
64+
@property.getter
65+
def width(self):
66+
return self._size[0]
67+
68+
@property.getter
69+
def height(self):
70+
return self._size[1]
71+
72+
@property.getter
73+
def x(self):
74+
return self._position[0]
75+
76+
@property.getter
77+
def y(self):
78+
return self._position[1]
79+
80+
@property
81+
def progress(self):
82+
return self._progress
83+
84+
@property.setter
85+
def progress(self, value):
86+
self._progress = value
87+
self.render()
88+
89+
def render(self):
90+
pass

0 commit comments

Comments
 (0)