@@ -149,7 +149,7 @@ def add_text(
149
149
"""
150
150
if text_font :
151
151
if text_font is terminalio .FONT :
152
- self ._text_font = text_font
152
+ self ._text_font = terminalio . FONT
153
153
else :
154
154
self ._text_font = bitmap_font .load_font (text_font )
155
155
if not text_wrap :
@@ -218,7 +218,7 @@ def preload_font(self, glyphs=None):
218
218
if not glyphs :
219
219
glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,. \" '?!"
220
220
print ("Preloading font glyphs:" , glyphs )
221
- if self ._text_font and self . _text_font is not terminalio .FONT :
221
+ if self ._text_font is not terminalio .FONT :
222
222
self ._text_font .load_glyphs (glyphs )
223
223
224
224
def set_text_color (self , color , index = 0 ):
@@ -243,36 +243,43 @@ def set_text(self, val, index=0):
243
243
# Make sure at least a single label exists
244
244
if not self ._text :
245
245
self .add_text ()
246
- if self ._text_font :
247
- string = str (val )
248
- if self ._text_maxlen [index ]:
249
- string = string [: self ._text_maxlen [index ]]
250
- if self ._text [index ]:
251
- # print("Replacing text area with :", string)
252
- # self._text[index].text = string
253
- # return
254
- try :
255
- text_index = self .splash .index (self ._text [index ])
256
- except AttributeError :
257
- for i in range (len (self .splash )):
258
- if self .splash [i ] == self ._text [index ]:
259
- text_index = i
260
- break
261
-
262
- self ._text [index ] = Label (self ._text_font , text = string )
263
- self ._text [index ].color = self ._text_color [index ]
264
- self ._text [index ].x = self ._text_position [index ][0 ]
265
- self ._text [index ].y = self ._text_position [index ][1 ]
266
- self .splash [text_index ] = self ._text [index ]
267
- return
268
-
269
- if self ._text_position [index ]: # if we want it placed somewhere...
270
- print ("Making text area with string:" , string )
271
- self ._text [index ] = Label (self ._text_font , text = string )
272
- self ._text [index ].color = self ._text_color [index ]
273
- self ._text [index ].x = self ._text_position [index ][0 ]
274
- self ._text [index ].y = self ._text_position [index ][1 ]
275
- self .splash .append (self ._text [index ])
246
+ string = str (val )
247
+ if not string :
248
+ max_glyphs = 50
249
+ else :
250
+ max_glyphs = len (string )
251
+ if self ._text_maxlen [index ]:
252
+ string = string [: self ._text_maxlen [index ]]
253
+ print ("text index" , self ._text [index ])
254
+ if self ._text [index ] is not None :
255
+ print ("Replacing text area with :" , string )
256
+ self ._text [index ].text = string
257
+ # return
258
+ # try:
259
+ text_index = self .splash .index (self ._text [index ])
260
+ # except AttributeError:
261
+ # for i in range(len(self.splash)):
262
+ # if self.splash[i] == self._text[index]:
263
+ # text_index = i
264
+ # break
265
+
266
+ self ._text [index ] = Label (
267
+ self ._text_font , text = string , max_glyphs = max_glyphs
268
+ )
269
+ self ._text [index ].color = self ._text_color [index ]
270
+ self ._text [index ].x = self ._text_position [index ][0 ]
271
+ self ._text [index ].y = self ._text_position [index ][1 ]
272
+ self .splash [text_index ] = self ._text [index ]
273
+
274
+ elif self ._text_position [index ]: # if we want it placed somewhere...
275
+ print ("Making text area with string:" , string )
276
+ self ._text [index ] = Label (
277
+ self ._text_font , text = string , max_glyphs = max_glyphs
278
+ )
279
+ self ._text [index ].color = self ._text_color [index ]
280
+ self ._text [index ].x = self ._text_position [index ][0 ]
281
+ self ._text [index ].y = self ._text_position [index ][1 ]
282
+ self .splash .append (self ._text [index ])
276
283
277
284
def get_local_time (self , location = None ):
278
285
"""Accessor function for get_local_time()"""
0 commit comments