26
26
CircuitPython driver for Adafruit PyPortal.
27
27
28
28
29
- * Author(s): Limor Fried, Kevin J. Walters
29
+ * Author(s): Limor Fried, Kevin J. Walters, Melissa LeBlanc-Williams
30
30
31
31
Implementation Notes
32
32
--------------------
59
59
import storage
60
60
import displayio
61
61
from adafruit_display_text .label import Label
62
+ import terminalio
62
63
import audioio
63
64
import audiocore
64
65
import rtc
@@ -159,6 +160,7 @@ class PyPortal:
159
160
``False``, no wrapping.
160
161
:param text_maxlen: The max length of the text for text wrapping. Defaults to 0.
161
162
:param text_transform: A function that will be called on the text before display
163
+ :param int text_scale: The factor to scale the default size of the text by
162
164
:param json_transform: A function or a list of functions to call with the parsed JSON.
163
165
Changes and additions are permitted for the ``dict`` object.
164
166
:param image_json_path: The JSON traversal path for a background image to display. Defaults to
@@ -197,12 +199,13 @@ def __init__(
197
199
convert_image = True ,
198
200
default_bg = 0x000000 ,
199
201
status_neopixel = None ,
200
- text_font = None ,
202
+ text_font = terminalio . FONT ,
201
203
text_position = None ,
202
204
text_color = 0x808080 ,
203
205
text_wrap = False ,
204
206
text_maxlen = 0 ,
205
207
text_transform = None ,
208
+ text_scale = 1 ,
206
209
json_transform = None ,
207
210
image_json_path = None ,
208
211
image_resize = None ,
@@ -380,20 +383,27 @@ def __init__(
380
383
text_maxlen = [0 ] * num
381
384
if not text_transform :
382
385
text_transform = [None ] * num
386
+ if not isinstance (text_scale , (list , tuple )):
387
+ text_scale = [text_scale ] * num
383
388
else :
384
389
num = 1
385
390
text_position = (text_position ,)
386
391
text_color = (text_color ,)
387
392
text_wrap = (text_wrap ,)
388
393
text_maxlen = (text_maxlen ,)
389
394
text_transform = (text_transform ,)
395
+ text_scale = (text_scale ,)
390
396
self ._text = [None ] * num
391
397
self ._text_color = [None ] * num
392
398
self ._text_position = [None ] * num
393
399
self ._text_wrap = [None ] * num
394
400
self ._text_maxlen = [None ] * num
395
401
self ._text_transform = [None ] * num
396
- self ._text_font = bitmap_font .load_font (text_font )
402
+ self ._text_scale = [None ] * num
403
+ if text_font is not terminalio .FONT :
404
+ self ._text_font = bitmap_font .load_font (text_font )
405
+ else :
406
+ self ._text_font = terminalio .FONT
397
407
if self ._debug :
398
408
print ("Loading font glyphs" )
399
409
# self._text_font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
@@ -409,6 +419,9 @@ def __init__(
409
419
self ._text_wrap [i ] = text_wrap [i ]
410
420
self ._text_maxlen [i ] = text_maxlen [i ]
411
421
self ._text_transform [i ] = text_transform [i ]
422
+ if not isinstance (text_scale [i ], (int , float )) or text_scale [i ] < 1 :
423
+ text_scale [i ] = 1
424
+ self ._text_scale [i ] = text_scale [i ]
412
425
else :
413
426
self ._text_font = None
414
427
self ._text = None
@@ -561,7 +574,7 @@ def preload_font(self, glyphs=None):
561
574
if not glyphs :
562
575
glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,. \" '?!"
563
576
print ("Preloading font glyphs:" , glyphs )
564
- if self ._text_font :
577
+ if self ._text_font and self . _text_font is not terminalio . FONT :
565
578
self ._text_font .load_glyphs (glyphs )
566
579
567
580
def set_caption (self , caption_text , caption_position , caption_color ):
@@ -621,7 +634,9 @@ def set_text(self, val, index=0):
621
634
text_index = i
622
635
break
623
636
624
- self ._text [index ] = Label (self ._text_font , text = string )
637
+ self ._text [index ] = Label (
638
+ self ._text_font , text = string , scale = self ._text_scale [index ]
639
+ )
625
640
self ._text [index ].color = self ._text_color [index ]
626
641
self ._text [index ].x = self ._text_position [index ][0 ]
627
642
self ._text [index ].y = self ._text_position [index ][1 ]
@@ -630,7 +645,9 @@ def set_text(self, val, index=0):
630
645
631
646
if self ._text_position [index ]: # if we want it placed somewhere...
632
647
print ("Making text area with string:" , string )
633
- self ._text [index ] = Label (self ._text_font , text = string )
648
+ self ._text [index ] = Label (
649
+ self ._text_font , text = string , scale = self ._text_scale [index ]
650
+ )
634
651
self ._text [index ].color = self ._text_color [index ]
635
652
self ._text [index ].x = self ._text_position [index ][0 ]
636
653
self ._text [index ].y = self ._text_position [index ][1 ]
0 commit comments