@@ -126,7 +126,7 @@ def __init__(
126
126
self ._text_scrolling = []
127
127
self ._text_scale = []
128
128
self ._scrolling_index = None
129
- self ._text_font = terminalio . FONT
129
+ self ._text_font = []
130
130
self ._text_line_spacing = []
131
131
132
132
gc .collect ()
@@ -135,7 +135,7 @@ def __init__(
135
135
def add_text (
136
136
self ,
137
137
text_position = None ,
138
- text_font = None ,
138
+ text_font = terminalio . FONT ,
139
139
text_color = 0x808080 ,
140
140
text_wrap = False ,
141
141
text_maxlen = 0 ,
@@ -163,11 +163,10 @@ def add_text(
163
163
the scrolling set to True will be cycled through.
164
164
165
165
"""
166
- if text_font :
167
- if text_font is terminalio .FONT :
168
- self ._text_font = text_font
169
- else :
170
- self ._text_font = bitmap_font .load_font (text_font )
166
+ if text_font is terminalio .FONT :
167
+ self ._text_font .append (text_font )
168
+ else :
169
+ self ._text_font .append (bitmap_font .load_font (text_font ))
171
170
if not text_wrap :
172
171
text_wrap = 0
173
172
if not text_maxlen :
@@ -228,7 +227,7 @@ def set_background(self, file_or_color, position=None):
228
227
"""
229
228
self .graphics .set_background (file_or_color , position )
230
229
231
- def preload_font (self , glyphs = None ):
230
+ def preload_font (self , glyphs = None , index = 0 ):
232
231
# pylint: disable=line-too-long
233
232
"""Preload font.
234
233
@@ -239,8 +238,8 @@ def preload_font(self, glyphs=None):
239
238
if not glyphs :
240
239
glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,. \" '?!"
241
240
print ("Preloading font glyphs:" , glyphs )
242
- if self ._text_font is not terminalio .FONT :
243
- self ._text_font .load_glyphs (glyphs )
241
+ if self ._text_font [ index ] is not terminalio .FONT :
242
+ self ._text_font [ index ] .load_glyphs (glyphs )
244
243
245
244
def set_text_color (self , color , index = 0 ):
246
245
"""Update the text color, with indexing into our list of text boxes.
@@ -279,7 +278,7 @@ def set_text(self, val, index=0):
279
278
280
279
if len (string ) > 0 :
281
280
self ._text [index ] = Label (
282
- self ._text_font , text = string , scale = self ._text_scale [index ]
281
+ self ._text_font [ index ] , text = string , scale = self ._text_scale [index ]
283
282
)
284
283
self ._text [index ].color = self ._text_color [index ]
285
284
self ._text [index ].x = self ._text_position [index ][0 ]
@@ -373,12 +372,18 @@ def scroll_text(self, frame_delay=0.02):
373
372
"""
374
373
if self ._scrolling_index is None : # Not initialized yet
375
374
return
376
-
377
- self ._text [self ._scrolling_index ].x = self .graphics .display .width
378
- line_width = self ._text [self ._scrolling_index ].bounding_box [2 ]
379
- for _ in range (self .graphics .display .width + line_width + 1 ):
380
- self .scroll ()
381
- sleep (frame_delay )
375
+ if self ._text [self ._scrolling_index ] is not None :
376
+ self ._text [self ._scrolling_index ].x = self .graphics .display .width
377
+ line_width = self ._text [self ._scrolling_index ].bounding_box [2 ]
378
+ for _ in range (self .graphics .display .width + line_width + 1 ):
379
+ self .scroll ()
380
+ sleep (frame_delay )
381
+ else :
382
+ raise RuntimeError (
383
+ "Please assign text to the label with index {} before scrolling" .format (
384
+ self ._scrolling_index
385
+ )
386
+ )
382
387
383
388
def fetch (self , refresh_url = None , timeout = 10 ):
384
389
"""Fetch data from the url we initialized with, perfom any parsing,
0 commit comments