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
--------------------
58
58
import storage
59
59
import displayio
60
60
from adafruit_display_text .label import Label
61
+ import terminalio
61
62
import audioio
62
63
import audiocore
63
64
import rtc
@@ -147,6 +148,7 @@ class PyPortal:
147
148
``False``, no wrapping.
148
149
:param text_maxlen: The max length of the text for text wrapping. Defaults to 0.
149
150
:param text_transform: A function that will be called on the text before display
151
+ :param int text_scale: The factor to scale the default size of the text by
150
152
:param json_transform: A function or a list of functions to call with the parsed JSON.
151
153
Changes and additions are permitted for the ``dict`` object.
152
154
:param image_json_path: The JSON traversal path for a background image to display. Defaults to
@@ -184,12 +186,13 @@ def __init__(
184
186
regexp_path = None ,
185
187
default_bg = 0x000000 ,
186
188
status_neopixel = None ,
187
- text_font = None ,
189
+ text_font = terminalio . FONT ,
188
190
text_position = None ,
189
191
text_color = 0x808080 ,
190
192
text_wrap = False ,
191
193
text_maxlen = 0 ,
192
194
text_transform = None ,
195
+ text_scale = 1 ,
193
196
json_transform = None ,
194
197
image_json_path = None ,
195
198
image_resize = None ,
@@ -373,13 +376,18 @@ def __init__(
373
376
text_wrap = (text_wrap ,)
374
377
text_maxlen = (text_maxlen ,)
375
378
text_transform = (text_transform ,)
379
+ text_scale = (text_scale ,)
376
380
self ._text = [None ] * num
377
381
self ._text_color = [None ] * num
378
382
self ._text_position = [None ] * num
379
383
self ._text_wrap = [None ] * num
380
384
self ._text_maxlen = [None ] * num
381
385
self ._text_transform = [None ] * num
382
- self ._text_font = bitmap_font .load_font (text_font )
386
+ self ._text_scale = [None ] * num
387
+ if text_font is not terminalio .FONT :
388
+ self ._text_font = bitmap_font .load_font (text_font )
389
+ else :
390
+ self ._text_font = terminalio .FONT
383
391
if self ._debug :
384
392
print ("Loading font glyphs" )
385
393
# self._text_font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
@@ -395,6 +403,9 @@ def __init__(
395
403
self ._text_wrap [i ] = text_wrap [i ]
396
404
self ._text_maxlen [i ] = text_maxlen [i ]
397
405
self ._text_transform [i ] = text_transform [i ]
406
+ if not isinstance (text_scale [i ], (int , float )) or text_scale [i ] < 1 :
407
+ text_scale [i ] = 1
408
+ self ._text_scale [i ] = text_scale [i ]
398
409
else :
399
410
self ._text_font = None
400
411
self ._text = None
@@ -547,7 +558,7 @@ def preload_font(self, glyphs=None):
547
558
if not glyphs :
548
559
glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,. \" '?!"
549
560
print ("Preloading font glyphs:" , glyphs )
550
- if self ._text_font :
561
+ if self ._text_font and self . _text_font is not terminalio . FONT :
551
562
self ._text_font .load_glyphs (glyphs )
552
563
553
564
def set_caption (self , caption_text , caption_position , caption_color ):
@@ -607,7 +618,9 @@ def set_text(self, val, index=0):
607
618
text_index = i
608
619
break
609
620
610
- self ._text [index ] = Label (self ._text_font , text = string )
621
+ self ._text [index ] = Label (
622
+ self ._text_font , text = string , scale = self ._text_scale [index ]
623
+ )
611
624
self ._text [index ].color = self ._text_color [index ]
612
625
self ._text [index ].x = self ._text_position [index ][0 ]
613
626
self ._text [index ].y = self ._text_position [index ][1 ]
@@ -616,7 +629,9 @@ def set_text(self, val, index=0):
616
629
617
630
if self ._text_position [index ]: # if we want it placed somewhere...
618
631
print ("Making text area with string:" , string )
619
- self ._text [index ] = Label (self ._text_font , text = string )
632
+ self ._text [index ] = Label (
633
+ self ._text_font , text = string , scale = self ._text_scale [index ]
634
+ )
620
635
self ._text [index ].color = self ._text_color [index ]
621
636
self ._text [index ].x = self ._text_position [index ][0 ]
622
637
self ._text [index ].y = self ._text_position [index ][1 ]
0 commit comments