@@ -130,19 +130,37 @@ def __init__(
130
130
self ._x = anchor_position [0 ]
131
131
self ._y = anchor_position [1 ]
132
132
133
+ self ._stroke = stroke
134
+
135
+ super ().__init__ (
136
+ anchor_position ,
137
+ size ,
138
+ progress ,
139
+ bar_color ,
140
+ outline_color ,
141
+ 0x444444 ,
142
+ border_thickness = stroke ,
143
+ show_margin = True ,
144
+ value_range = (0.0 , 1.0 ),
145
+ )
146
+
147
+ self ._draw_outline ()
148
+
149
+ def _draw_outline (self ):
150
+ """
151
+ Draws the outline (border) of the widget.
152
+ """
153
+
133
154
# draw outline rectangle
134
155
for _w in range (self ._width ):
135
- for line in range (stroke ):
156
+ for line in range (self . _stroke ):
136
157
self ._bitmap [_w , line ] = 1
137
158
self ._bitmap [_w , self ._height - 1 - line ] = 1
138
159
for _h in range (self ._height ):
139
- for line in range (stroke ):
160
+ for line in range (self . _stroke ):
140
161
self ._bitmap [line , _h ] = 1
141
162
self ._bitmap [self ._width - 1 - line , _h ] = 1
142
163
143
- # pylint: disable=unexpected-keyword-arg, no-value-for-parameter
144
- super ().__init__ (self ._bitmap , pixel_shader = self ._palette , x = self ._x , y = self ._y )
145
-
146
164
@property
147
165
def progress (self ):
148
166
"""The percentage of the progress bar expressed as a
@@ -162,9 +180,30 @@ def progress(self, value):
162
180
assert value <= self ._max , "Progress value may not be > maximum value"
163
181
assert value >= self ._min , "Progress value may not be < minimum value"
164
182
183
+ _old_value = self ._progress_val
165
184
_new_value = round (value / self ._max , 2 )
185
+ self ._progress_val = _new_value
186
+ self .render (_old_value , _new_value , value )
187
+
188
+ def render (self , old_value , new_value , progress ):
189
+ """
190
+ Does the work of actually creating the graphical representation of
191
+ the value (percentage, aka "progress") to be displayed.
192
+
193
+ :param old_value: The previously displayed value
194
+ :type old_value: float
195
+ :param new_value: The new value to display
196
+ :type new_value: float
197
+ :param progress: The value to display, as a percentage, represented
198
+ by a float from 0.0 to 1.0 (0% to 100%)
199
+ :type progress: float
200
+ :return: None
201
+ :rtype: None
202
+ """
166
203
_padding = 1
167
204
205
+ print (f"Drawing a visual of progress value { progress } " )
206
+
168
207
if self ._margin :
169
208
_padding = 1
170
209
@@ -181,18 +220,18 @@ def progress(self, value):
181
220
self .height - (2 * _padding ) - _border_size
182
221
) # Count padding on the top and bottom
183
222
184
- _prev_value_size = int (self . _progress_val * _fill_width )
185
- _new_value_size = int (_new_value * _fill_width )
223
+ _prev_value_size = int (old_value * _fill_width )
224
+ _new_value_size = int (new_value * _fill_width )
186
225
187
226
# If we have *ANY* value other than "zero" (minimum), we should
188
227
# have at least one element showing
189
- if _new_value_size == 0 and value > self ._min :
228
+ if _new_value_size == 0 and new_value > self ._min :
190
229
_new_value_size = 1
191
230
192
231
# Conversely, if we have *ANY* value other than 100% (maximum),
193
232
# we should NOT show a full bar.
194
233
195
- if _new_value_size == _fill_width and value < self ._max :
234
+ if _new_value_size == _fill_width and new_value < self ._max :
196
235
_new_value_size -= 1
197
236
198
237
# Default values for increasing value
@@ -214,22 +253,14 @@ def progress(self, value):
214
253
else :
215
254
pass
216
255
217
- # DEBUG
218
- print (
219
- f"Start: { _start } End: { _end } Incr: { _incr } Size: { _new_value_size } Color: { _color } "
220
- )
221
-
222
256
# Because range() is ( from-include, to-exclude )...
223
-
224
257
_vert_start = _border_thickness + _padding
225
258
_vert_end = _vert_start + _fill_height
226
259
227
260
for h in range (_vert_start , _vert_end ):
228
261
for w in range (_start , _end , _incr ):
229
262
self ._bitmap [w , h ] = _color
230
263
231
- self ._progress_val = _new_value
232
-
233
264
@property
234
265
def fill (self ):
235
266
"""The fill of the progress bar. Can be a hex value for a color or ``None`` for
0 commit comments