Skip to content

Commit b8120f8

Browse files
committed
All widgets working
Both horizontal and vertical widgets working. PyGameDisplay example updated for all directions Pylint checks all pass, including duplicate code
1 parent 8a72116 commit b8120f8

File tree

3 files changed

+20
-37
lines changed

3 files changed

+20
-37
lines changed

adafruit_progressbar/horizontalprogressbar.py

+8
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ def _get_horizontal_fill(
154154

155155
return base_offset - _start, base_offset - _end, _incr * -1
156156

157+
# pylint: disable=protected-access
158+
def _get_vertical_fill(
159+
self, _start: int, _end: int, _incr: int
160+
) -> Tuple[int, int, int]:
161+
return ProgressBarBase._get_vertical_fill(self, _start, _end, _incr)
162+
163+
# pylint: enable=protected-access
164+
157165
def _invert_fill_direction(self) -> bool:
158166
return self._direction == HorizontalFillDirection.RIGHT_TO_LEFT
159167

adafruit_progressbar/verticalprogressbar.py

+11-36
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
"""
2323

2424
try:
25-
from typing import Tuple, Union
25+
from typing import Tuple
2626
except ImportError:
2727
pass # Not needed for execution
2828
from . import ProgressBarBase
29+
from .horizontalprogressbar import HorizontalProgressBar
2930

3031

3132
# pylint: disable=too-few-public-methods
@@ -45,7 +46,7 @@ class VerticalFillDirection:
4546

4647

4748
# pylint: disable=too-many-arguments, too-few-public-methods, too-many-instance-attributes
48-
class VerticalProgressBar(ProgressBarBase):
49+
class VerticalProgressBar(HorizontalProgressBar):
4950
"""A dynamic progress bar widget.
5051
5152
The anchor position is the position where the control would start if it
@@ -104,40 +105,6 @@ class VerticalProgressBar(ProgressBarBase):
104105
105106
"""
106107

107-
# pylint: disable=too-many-arguments
108-
def __init__(
109-
self,
110-
position: Tuple[int, int],
111-
size: Tuple[int, int],
112-
min_value: Union[int, float] = 0,
113-
max_value: Union[int, float] = 100,
114-
value: Union[int, float] = 0,
115-
bar_color: Union[int, Tuple[int, int, int]] = 0x00FF00,
116-
outline_color: Union[int, Tuple[int, int, int]] = 0xFFFFFF,
117-
fill_color: Union[int, Tuple[int, int, int]] = 0x444444,
118-
border_thickness: int = 1,
119-
margin_size: int = 1,
120-
direction: VerticalFillDirection = VerticalFillDirection.DEFAULT,
121-
) -> None:
122-
123-
# Store the "direction" value locally. While they may appear to
124-
# "relate" with the values of the horizontal bar, their handling
125-
# is too different to be stored in the same underlying property,
126-
# which could lead to confusion
127-
self._direction = direction
128-
129-
super().__init__(
130-
position,
131-
size,
132-
value,
133-
bar_color,
134-
outline_color,
135-
fill_color,
136-
border_thickness,
137-
margin_size,
138-
(min_value, max_value),
139-
)
140-
141108
def _get_sizes_min_max(self) -> Tuple[int, int]:
142109
return 0, self.fill_height()
143110

@@ -146,6 +113,14 @@ def _get_value_sizes(self, _old_ratio: float, _new_ratio: float) -> Tuple[int, i
146113
_new_ratio * self.fill_height()
147114
)
148115

116+
# pylint: disable=protected-access
117+
def _get_horizontal_fill(
118+
self, _start: int, _end: int, _incr: int
119+
) -> Tuple[int, int, int]:
120+
return ProgressBarBase._get_horizontal_fill(self, _start, _end, _incr)
121+
122+
# pylint: enable=protected-access
123+
149124
def _get_vertical_fill(
150125
self, _start: int, _end: int, _incr: int
151126
) -> Tuple[int, int, int]:

examples/progressbar_displayio_blinka.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
vertical_bar = VerticalProgressBar(
7070
(200, 30),
7171
(32, 180),
72-
direction=VerticalFillDirection.BOTTOM_TO_TOP,
72+
direction=VerticalFillDirection.TOP_TO_BOTTOM,
7373
)
7474
splash.append(vertical_bar)
7575

0 commit comments

Comments
 (0)