@@ -112,6 +112,7 @@ def __init__(
112
112
self ._text_font = []
113
113
self ._text_line_spacing = []
114
114
self ._text_anchor_point = []
115
+ self ._text_is_data = []
115
116
116
117
gc .collect ()
117
118
@@ -127,6 +128,7 @@ def add_text(
127
128
text_scale = 1 ,
128
129
line_spacing = 1.25 ,
129
130
text_anchor_point = (0 , 0.5 ),
131
+ is_data = True ,
130
132
):
131
133
"""
132
134
Add text labels with settings
@@ -143,6 +145,10 @@ def add_text(
143
145
length. Defaults to 0.
144
146
:param text_transform: A function that will be called on the text before display
145
147
:param int text_scale: The factor to scale the default size of the text by
148
+ :param float line_spacing: The factor to space the lines apart
149
+ :param (float, float) text_anchor_point: Values between 0 and 1 to indicate where the text
150
+ position is relative to the label
151
+ :param bool is_data: If True, fetch will attempt to update the label
146
152
"""
147
153
if text_font is terminalio .FONT :
148
154
self ._text_font .append (text_font )
@@ -174,6 +180,7 @@ def add_text(
174
180
self ._text_scale .append (text_scale )
175
181
self ._text_line_spacing .append (line_spacing )
176
182
self ._text_anchor_point .append (text_anchor_point )
183
+ self ._text_is_data .append (bool (is_data ))
177
184
178
185
# pylint: enable=too-many-arguments
179
186
@@ -358,17 +365,21 @@ def fetch(self, refresh_url=None, timeout=10):
358
365
359
366
# fill out all the text blocks
360
367
if self ._text :
368
+ value_index = 0 # In case values and text is not the same
361
369
for i in range (len (self ._text )):
370
+ if not self ._text_is_data [i ]:
371
+ continue
362
372
string = None
363
373
if self ._text_transform [i ]:
364
374
func = self ._text_transform [i ]
365
- string = func (values [i ])
375
+ string = func (values [value_index ])
366
376
else :
367
377
try :
368
- string = "{:,d}" .format (int (values [i ]))
378
+ string = "{:,d}" .format (int (values [value_index ]))
369
379
except (TypeError , ValueError ):
370
- string = values [i ] # ok its a string
380
+ string = values [value_index ] # ok its a string
371
381
self .set_text (string , index = i , auto_refresh = False )
382
+ value_index += 1
372
383
self .refresh ()
373
384
if len (values ) == 1 :
374
385
return values [0 ]
0 commit comments