Skip to content

Commit 9a2abce

Browse files
committed
Bug fixes related to text
1 parent 1d53404 commit 9a2abce

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

adafruit_matrixportal/matrixportal.py

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def add_text(
149149
"""
150150
if text_font:
151151
if text_font is terminalio.FONT:
152-
self._text_font = text_font
152+
self._text_font = terminalio.FONT
153153
else:
154154
self._text_font = bitmap_font.load_font(text_font)
155155
if not text_wrap:
@@ -218,7 +218,7 @@ def preload_font(self, glyphs=None):
218218
if not glyphs:
219219
glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,. \"'?!"
220220
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:
222222
self._text_font.load_glyphs(glyphs)
223223

224224
def set_text_color(self, color, index=0):
@@ -243,36 +243,43 @@ def set_text(self, val, index=0):
243243
# Make sure at least a single label exists
244244
if not self._text:
245245
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])
276283

277284
def get_local_time(self, location=None):
278285
"""Accessor function for get_local_time()"""

0 commit comments

Comments
 (0)