24
24
25
25
# imports
26
26
import displayio
27
- from . import ProgressBarBase
28
-
29
-
30
- # pylint: disable=too-few-public-methods
31
- class FillDirection (enumerate ):
32
- """Enums to define the direction in which the progressbar
33
- should fill"""
34
-
35
- LEFT_TO_RIGHT = 0
36
- DEFAULT = LEFT_TO_RIGHT
37
- BOTTOM_UP = 1
38
- TOP_DOWN = 2
39
- RIGHT_TO_LEFT = 3
27
+ from . import ProgressBarBase , FillDirection
40
28
41
29
42
30
# pylint: disable=too-many-arguments, too-few-public-methods, too-many-instance-attributes
@@ -100,6 +88,7 @@ def __init__(
100
88
progress = 0.0 ,
101
89
bar_color = 0x00FF00 ,
102
90
outline_color = 0xFFFFFF ,
91
+ fill_color = None ,
103
92
stroke = 1 ,
104
93
margin = False ,
105
94
direction = FillDirection .DEFAULT ,
@@ -132,10 +121,6 @@ def __init__(
132
121
self ._bar_width = self ._width
133
122
self ._bar_height = self ._height
134
123
135
- self ._progress_val = 0.0
136
- self .progress = self ._progress_val
137
- self .progress = progress
138
-
139
124
self ._x = anchor_position [0 ]
140
125
self ._y = anchor_position [1 ]
141
126
@@ -147,70 +132,31 @@ def __init__(
147
132
progress ,
148
133
bar_color ,
149
134
outline_color ,
150
- 0x444444 ,
135
+ fill_color ,
151
136
border_thickness = stroke ,
152
137
show_margin = True ,
153
138
value_range = (0.0 , 1.0 ),
154
139
)
155
140
156
- self ._draw_outline ()
157
-
158
- def _draw_outline (self ):
159
- """
160
- Draws the outline (border) of the widget.
161
- """
162
-
163
- # draw outline rectangle
164
- for _w in range (self ._width ):
165
- for line in range (self ._stroke ):
166
- self ._bitmap [_w , line ] = 1
167
- self ._bitmap [_w , self ._height - 1 - line ] = 1
168
- for _h in range (self ._height ):
169
- for line in range (self ._stroke ):
170
- self ._bitmap [line , _h ] = 1
171
- self ._bitmap [self ._width - 1 - line , _h ] = 1
172
-
173
- @property
174
- def progress (self ):
175
- """The percentage of the progress bar expressed as a
176
- floating point number.
177
- """
178
- return self ._progress_val
179
-
180
141
# pylint: disable=too-many-locals
181
- @progress .setter
182
- def progress (self , value ):
183
- """Draws the progress bar
184
-
185
- :param value: Progress bar value.
186
- :type value: float
187
- """
188
- assert value <= self ._max , "Progress value may not be > maximum value"
189
- assert value >= self ._min , "Progress value may not be < minimum value"
190
-
191
- _old_value = self ._progress_val
192
- _new_value = round (value / self ._max , 2 )
193
- self ._progress_val = _new_value
194
- self .render (_old_value , _new_value , value )
195
-
196
- def render (self , old_value , new_value , progress ):
142
+ def render (self , _old_value , _new_value , _progress_value ):
197
143
"""
198
144
Does the work of actually creating the graphical representation of
199
145
the value (percentage, aka "progress") to be displayed.
200
146
201
- :param old_value : The previously displayed value
202
- :type old_value : float
203
- :param new_value : The new value to display
204
- :type new_value : float
205
- :param progress : The value to display, as a percentage, represented
147
+ :param _old_value : The previously displayed value
148
+ :type _old_value : float
149
+ :param _new_value : The new value to display
150
+ :type _new_value : float
151
+ :param _progress_value : The value to display, as a percentage, represented
206
152
by a float from 0.0 to 1.0 (0% to 100%)
207
- :type progress : float
153
+ :type _progress_value : float
208
154
:return: None
209
155
:rtype: None
210
156
"""
211
157
_padding = 0
212
158
213
- print (f"Drawing a visual of progress value { progress } " )
159
+ print (f"Drawing a visual of progress value { _progress_value } " )
214
160
215
161
if self ._margin :
216
162
_padding = 1
@@ -222,24 +168,24 @@ def render(self, old_value, new_value, progress):
222
168
# in both directions (left-to-right and top-to-bottom)
223
169
224
170
_fill_width = (
225
- self .width - (2 * _padding ) - _border_size
171
+ self .widget_width - (2 * _padding ) - _border_size
226
172
) # Count padding on left and right
227
173
_fill_height = (
228
- self .height - (2 * _padding ) - _border_size
174
+ self .widget_height - (2 * _padding ) - _border_size
229
175
) # Count padding on the top and bottom
230
176
231
- _prev_value_size = int (old_value * _fill_height )
232
- _new_value_size = int (new_value * _fill_height )
177
+ _prev_value_size = int (_old_value * _fill_height )
178
+ _new_value_size = int (_new_value * _fill_height )
233
179
234
180
# If we have *ANY* value other than "zero" (minimum), we should
235
181
# have at least one element showing
236
- if _new_value_size == 0 and new_value > self ._min :
182
+ if _new_value_size == 0 and _new_value > self ._min :
237
183
_new_value_size = 1
238
184
239
185
# Conversely, if we have *ANY* value other than 100% (maximum),
240
186
# we should NOT show a full bar.
241
187
242
- if _new_value_size == _fill_height and new_value < self ._max :
188
+ if _new_value_size == _fill_height and _new_value < self ._max :
243
189
_new_value_size -= 1
244
190
245
191
# Default values for increasing value
@@ -269,32 +215,3 @@ def render(self, old_value, new_value, progress):
269
215
for h in range (_start , _end , _incr ):
270
216
for w in range (_start_offset , _fill_width ):
271
217
self ._bitmap [w , h ] = _color
272
-
273
- @property
274
- def fill (self ):
275
- """The fill of the progress bar. Can be a hex value for a color or
276
- ``None`` for transparent.
277
- """
278
- return self ._palette [0 ]
279
-
280
- @property
281
- def width (self ):
282
- """The width of the progress bar. In pixels, includes the border."""
283
- return self ._bar_width
284
-
285
- @property
286
- def height (self ):
287
- """The height of the progress bar. In pixels, includes the border."""
288
- return self ._bar_height
289
-
290
- @fill .setter
291
- def fill (self , color ):
292
- """Sets the fill of the progress bar. Can be a hex value for a color or
293
- ``None`` for transparent.
294
- """
295
- if color is None :
296
- self ._palette [2 ] = 0
297
- self ._palette .make_transparent (0 )
298
- else :
299
- self ._palette [2 ] = color
300
- self ._palette .make_opaque (0 )
0 commit comments