28
28
import gc
29
29
from time import sleep
30
30
import terminalio
31
+ from displayio import Group
31
32
from adafruit_bitmap_font import bitmap_font
32
33
from adafruit_display_text .label import Label
33
34
from adafruit_matrixportal .network import Network
@@ -124,6 +125,7 @@ def __init__(
124
125
self ._text_maxlen = []
125
126
self ._text_transform = []
126
127
self ._text_scrolling = []
128
+ self ._text_scale = []
127
129
self ._scrolling_index = None
128
130
self ._text_font = terminalio .FONT
129
131
@@ -138,6 +140,7 @@ def add_text(
138
140
text_wrap = False ,
139
141
text_maxlen = 0 ,
140
142
text_transform = None ,
143
+ text_scale = 1 ,
141
144
scrolling = False ,
142
145
):
143
146
"""
@@ -153,6 +156,7 @@ def add_text(
153
156
``False``, no wrapping.
154
157
:param text_maxlen: The max length of the text for text wrapping. Defaults to 0.
155
158
:param text_transform: A function that will be called on the text before display
159
+ :param int text_scale: The factor to scale the default size of the text by
156
160
:param bool scrolling: If true, text is placed offscreen and the scroll() function is used
157
161
to scroll text on a pixel-by-pixel basis. Multiple text labels with
158
162
the scrolling set to True will be cycled through.
@@ -169,6 +173,9 @@ def add_text(
169
173
text_maxlen = 0
170
174
if not text_transform :
171
175
text_transform = None
176
+ if not isinstance (text_scale , (int , float )) or text_scale < 1 :
177
+ text_scale = 1
178
+ text_scale = round (text_scale )
172
179
if scrolling :
173
180
text_position = (self .display .width , text_position [1 ])
174
181
@@ -182,6 +189,7 @@ def add_text(
182
189
self ._text_wrap .append (text_wrap )
183
190
self ._text_maxlen .append (text_maxlen )
184
191
self ._text_transform .append (text_transform )
192
+ self ._text_scale .append (text_scale )
185
193
self ._text_scrolling .append (scrolling )
186
194
187
195
if scrolling and self ._scrolling_index is None : # Not initialized yet
@@ -242,7 +250,10 @@ def set_text_color(self, color, index=0):
242
250
if self ._text [index ]:
243
251
color = self .html_color_convert (color )
244
252
self ._text_color [index ] = color
245
- self ._text [index ].color = color
253
+ if isinstance (self ._text [index ], Group ):
254
+ self ._text [index ][0 ].color = color
255
+ else :
256
+ self ._text [index ].color = color
246
257
247
258
def set_text (self , val , index = 0 ):
248
259
"""Display text, with indexing into our list of text boxes.
@@ -261,12 +272,18 @@ def set_text(self, val, index=0):
261
272
index_in_splash = None
262
273
if self ._text [index ] is not None :
263
274
print ("Replacing text area with :" , string )
264
- index_in_splash = self .splash .index (self ._text [index ])
265
275
if len (string ) > 0 :
266
- self ._text [index ] = Label (self ._text_font , text = string )
267
- self ._text [index ].color = self ._text_color [index ]
268
- self ._text [index ].x = self ._text_position [index ][0 ]
269
- self ._text [index ].y = self ._text_position [index ][1 ]
276
+ label = Label (self ._text_font , text = string )
277
+ label .color = self ._text_color [index ]
278
+ if self ._text_scale [index ] > 1 :
279
+ self ._text [index ] = Group (max_size = 1 , scale = self ._text_scale [index ])
280
+ self ._text [index ].x = self ._text_position [index ][0 ]
281
+ self ._text [index ].y = self ._text_position [index ][1 ]
282
+ self ._text [index ].append (label )
283
+ else :
284
+ label .x = self ._text_position [index ][0 ]
285
+ label .y = self ._text_position [index ][1 ]
286
+ self ._text [index ] = label
270
287
elif index_in_splash is not None :
271
288
self ._text [index ] = None
272
289
@@ -315,6 +332,14 @@ def get_io_data(self, feed_key):
315
332
316
333
return self .network .get_io_data (feed_key )
317
334
335
+ def get_io_last_data (self , feed_key ):
336
+ """Return last value from Adafruit IO Feed Data that matches the feed key
337
+
338
+ :param str feed_key: Name of feed key to receive data from.
339
+
340
+ """
341
+ return self .network .get_io_last_data (feed_key )
342
+
318
343
def get_io_feed (self , feed_key , detailed = False ):
319
344
"""Return the Adafruit IO Feed that matches the feed key
320
345
0 commit comments