Skip to content

Commit f215ee3

Browse files
authored
Merge pull request #16 from makermelissa/bugfixes
Bug fixes related to text
2 parents 1d53404 + 8f9e16e commit f215ee3

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

adafruit_matrixportal/matrixportal.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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,28 @@ 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+
index_in_splash = None
255+
if self._text[index] is not None:
256+
print("Replacing text area with :", string)
257+
self._text[index].text = string
258+
index_in_splash = self.splash.index(self._text[index])
259+
self._text[index] = Label(self._text_font, text=string, max_glyphs=max_glyphs)
260+
self._text[index].color = self._text_color[index]
261+
self._text[index].x = self._text_position[index][0]
262+
self._text[index].y = self._text_position[index][1]
263+
264+
if index_in_splash is not None:
265+
self.splash[index_in_splash] = self._text[index]
266+
else:
267+
self.splash.append(self._text[index])
276268

277269
def get_local_time(self, location=None):
278270
"""Accessor function for get_local_time()"""

0 commit comments

Comments
 (0)