@@ -44,10 +44,6 @@ class ProgressBarBase(displayio.TileGrid):
44
44
:type position: Tuple[int, int]
45
45
:param size: The size (width, height) of the progress bar
46
46
:type size: Tuple[int, int]
47
- :param start_value: The beginning value of the progress bar. This value
48
- is displayed when the progress bar is first visible,
49
- if it hasn't been updated.
50
- :type start_value: float
51
47
:param bar_color: The color of the bar representing the value. This can
52
48
be a hexadecimal value for color (0x224466).
53
49
Default: 0x00FF00 (Solid green)
@@ -74,12 +70,11 @@ class ProgressBarBase(displayio.TileGrid):
74
70
:type value_range: Tuple[int, int] or Tuple[float, float]
75
71
"""
76
72
77
- # pylint: disable=too-many-arguments
73
+ # pylint: disable=too-many-arguments, too-many-instance-attributes
78
74
def __init__ (
79
75
self ,
80
76
position ,
81
77
size ,
82
- start_value = 0.0 ,
83
78
value = 0 ,
84
79
bar_color = 0x00FF00 ,
85
80
outline_color = 0xFFFFFF ,
@@ -91,8 +86,7 @@ def __init__(
91
86
92
87
self ._widget_size = size
93
88
self ._position = position
94
- self ._progress = start_value
95
- print (f"Size: { size } - WS: { self .widget_size } " )
89
+
96
90
self ._bitmap = displayio .Bitmap (size [0 ], size [1 ], 3 )
97
91
self ._palette = displayio .Palette (3 )
98
92
self ._palette [0 ] = fill_color
@@ -101,7 +95,17 @@ def __init__(
101
95
self ._border_thickness = border_thickness
102
96
self ._show_margin = show_margin
103
97
self ._range = value_range
104
- self ._value = value
98
+ self ._progress = 0.0
99
+
100
+ # Setup value and old_value to handle the change to the new
101
+ # initial value later.
102
+ self ._value = self .minimum
103
+ self ._old_value = self .minimum
104
+
105
+ self ._margin = 0
106
+
107
+ if self ._show_margin :
108
+ self ._margin = 1
105
109
106
110
super ().__init__ (
107
111
self ._bitmap ,
@@ -111,6 +115,8 @@ def __init__(
111
115
)
112
116
113
117
self ._draw_outline ()
118
+ self .render (self .minimum , self .minimum + 1 , 0 )
119
+ self .value = value
114
120
115
121
# _bitmap: displayio.Bitmap # The bitmap used for the bar/value
116
122
# _position: (int, int) # The (x,y) coordinates of the top-left corner
@@ -138,11 +144,6 @@ def widget_height(self):
138
144
"""The total height of the widget, in pixels. Includes the border and margin."""
139
145
return self .widget_size [1 ]
140
146
141
- @property
142
- def _outline_color (self ):
143
- """The colour of the border/outline of the widget"""
144
- return self ._palette [1 ]
145
-
146
147
@property
147
148
def x (self ):
148
149
"""The horizontal (x) position of the top-left corner of the widget."""
@@ -188,6 +189,15 @@ def value(self):
188
189
189
190
@value .setter
190
191
def value (self , value ):
192
+ """Sets the current value of the progress within the min-max range
193
+
194
+ :param value: The new value for the progress status
195
+ :type value: int/float
196
+ """
197
+ # Save off the previous value, so we can pass it in the
198
+ # call to "Render"
199
+ print (f"Updating value from { self ._value } to { value } " )
200
+ self ._old_value = self ._value
191
201
self ._value = value
192
202
# Convert value to float since we may be dealing with
193
203
# integer types, and we can't work with integer division
@@ -210,15 +220,17 @@ def border_thickness(self):
210
220
def progress (self , value ):
211
221
"""The current displayed value of the widget.
212
222
213
- :param float value: The new value which should be displayed by the progress
223
+ :param value: The new value which should be displayed by the progress
214
224
bar. Must be between 0.0-1.0
225
+ :type value: float
215
226
"""
216
- _old_value = self .progress
217
227
# If we're using floats, from 0.0 to 1.0, using 4 decimal places allows us to handle values
218
228
# as precise as 0.23456, which evaluates to a percentage value of 23.45% (with rounding)
219
229
self ._progress = round (value , 4 )
220
- print (f"Calling render() with ({ _old_value } , { self .progress } , { self .progress } )" )
221
- self .render (_old_value , self .progress , self .progress )
230
+ print (
231
+ f"Calling render() with ({ self ._old_value } , { self .value } , { self .progress } )"
232
+ )
233
+ self .render (self ._old_value , self .value , self .progress )
222
234
223
235
@property
224
236
def range (self ):
0 commit comments