@@ -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 ,
@@ -165,9 +165,9 @@ def add_text(
165
165
"""
166
166
if text_font :
167
167
if text_font is terminalio .FONT :
168
- self ._text_font = text_font
168
+ self ._text_font . append ( text_font )
169
169
else :
170
- self ._text_font = bitmap_font .load_font (text_font )
170
+ self ._text_font . append ( bitmap_font .load_font (text_font ) )
171
171
if not text_wrap :
172
172
text_wrap = 0
173
173
if not text_maxlen :
@@ -228,7 +228,7 @@ def set_background(self, file_or_color, position=None):
228
228
"""
229
229
self .graphics .set_background (file_or_color , position )
230
230
231
- def preload_font (self , glyphs = None ):
231
+ def preload_font (self , glyphs = None , index = 0 ):
232
232
# pylint: disable=line-too-long
233
233
"""Preload font.
234
234
@@ -239,8 +239,8 @@ def preload_font(self, glyphs=None):
239
239
if not glyphs :
240
240
glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,. \" '?!"
241
241
print ("Preloading font glyphs:" , glyphs )
242
- if self ._text_font is not terminalio .FONT :
243
- self ._text_font .load_glyphs (glyphs )
242
+ if self ._text_font [ index ] is not terminalio .FONT :
243
+ self ._text_font [ index ] .load_glyphs (glyphs )
244
244
245
245
def set_text_color (self , color , index = 0 ):
246
246
"""Update the text color, with indexing into our list of text boxes.
@@ -279,7 +279,7 @@ def set_text(self, val, index=0):
279
279
280
280
if len (string ) > 0 :
281
281
self ._text [index ] = Label (
282
- self ._text_font , text = string , scale = self ._text_scale [index ]
282
+ self ._text_font [ index ] , text = string , scale = self ._text_scale [index ]
283
283
)
284
284
self ._text [index ].color = self ._text_color [index ]
285
285
self ._text [index ].x = self ._text_position [index ][0 ]
@@ -373,12 +373,18 @@ def scroll_text(self, frame_delay=0.02):
373
373
"""
374
374
if self ._scrolling_index is None : # Not initialized yet
375
375
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 )
376
+ if self ._text [self ._scrolling_index ] is not None :
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 )
382
+ else :
383
+ raise RuntimeError (
384
+ "Please assign text to the label with index {} before scrolling" .format (
385
+ self ._scrolling_index
386
+ )
387
+ )
382
388
383
389
def fetch (self , refresh_url = None , timeout = 10 ):
384
390
"""Fetch data from the url we initialized with, perfom any parsing,
0 commit comments