From 9a2abce123751efbf897f0a7ec1be895d905a075 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 8 Sep 2020 10:33:27 -0700 Subject: [PATCH 1/3] Bug fixes related to text --- adafruit_matrixportal/matrixportal.py | 71 +++++++++++++++------------ 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/adafruit_matrixportal/matrixportal.py b/adafruit_matrixportal/matrixportal.py index 12a8584..ca92406 100755 --- a/adafruit_matrixportal/matrixportal.py +++ b/adafruit_matrixportal/matrixportal.py @@ -149,7 +149,7 @@ def add_text( """ if text_font: if text_font is terminalio.FONT: - self._text_font = text_font + self._text_font = terminalio.FONT else: self._text_font = bitmap_font.load_font(text_font) if not text_wrap: @@ -218,7 +218,7 @@ def preload_font(self, glyphs=None): if not glyphs: glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,. \"'?!" print("Preloading font glyphs:", glyphs) - if self._text_font and self._text_font is not terminalio.FONT: + if self._text_font is not terminalio.FONT: self._text_font.load_glyphs(glyphs) def set_text_color(self, color, index=0): @@ -243,36 +243,43 @@ def set_text(self, val, index=0): # Make sure at least a single label exists if not self._text: self.add_text() - if self._text_font: - string = str(val) - if self._text_maxlen[index]: - string = string[: self._text_maxlen[index]] - if self._text[index]: - # print("Replacing text area with :", string) - # self._text[index].text = string - # return - try: - text_index = self.splash.index(self._text[index]) - except AttributeError: - for i in range(len(self.splash)): - if self.splash[i] == self._text[index]: - text_index = i - break - - self._text[index] = Label(self._text_font, text=string) - self._text[index].color = self._text_color[index] - self._text[index].x = self._text_position[index][0] - self._text[index].y = self._text_position[index][1] - self.splash[text_index] = self._text[index] - return - - if self._text_position[index]: # if we want it placed somewhere... - print("Making text area with string:", string) - self._text[index] = Label(self._text_font, text=string) - self._text[index].color = self._text_color[index] - self._text[index].x = self._text_position[index][0] - self._text[index].y = self._text_position[index][1] - self.splash.append(self._text[index]) + string = str(val) + if not string: + max_glyphs = 50 + else: + max_glyphs = len(string) + if self._text_maxlen[index]: + string = string[: self._text_maxlen[index]] + print("text index", self._text[index]) + if self._text[index] is not None: + print("Replacing text area with :", string) + self._text[index].text = string + # return + # try: + text_index = self.splash.index(self._text[index]) + # except AttributeError: + # for i in range(len(self.splash)): + # if self.splash[i] == self._text[index]: + # text_index = i + # break + + self._text[index] = Label( + self._text_font, text=string, max_glyphs=max_glyphs + ) + self._text[index].color = self._text_color[index] + self._text[index].x = self._text_position[index][0] + self._text[index].y = self._text_position[index][1] + self.splash[text_index] = self._text[index] + + elif self._text_position[index]: # if we want it placed somewhere... + print("Making text area with string:", string) + self._text[index] = Label( + self._text_font, text=string, max_glyphs=max_glyphs + ) + self._text[index].color = self._text_color[index] + self._text[index].x = self._text_position[index][0] + self._text[index].y = self._text_position[index][1] + self.splash.append(self._text[index]) def get_local_time(self, location=None): """Accessor function for get_local_time()""" From af1c7d898a59e88c8c05523c27f9948dbb438b99 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 8 Sep 2020 12:27:47 -0700 Subject: [PATCH 2/3] Made some of Scott's suggestions --- adafruit_matrixportal/matrixportal.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/adafruit_matrixportal/matrixportal.py b/adafruit_matrixportal/matrixportal.py index ca92406..0c8881c 100755 --- a/adafruit_matrixportal/matrixportal.py +++ b/adafruit_matrixportal/matrixportal.py @@ -149,7 +149,7 @@ def add_text( """ if text_font: if text_font is terminalio.FONT: - self._text_font = terminalio.FONT + self._text_font = text_font else: self._text_font = bitmap_font.load_font(text_font) if not text_wrap: @@ -254,14 +254,7 @@ def set_text(self, val, index=0): if self._text[index] is not None: print("Replacing text area with :", string) self._text[index].text = string - # return - # try: text_index = self.splash.index(self._text[index]) - # except AttributeError: - # for i in range(len(self.splash)): - # if self.splash[i] == self._text[index]: - # text_index = i - # break self._text[index] = Label( self._text_font, text=string, max_glyphs=max_glyphs From 8f9e16e65bf58fd51c34930daa9f7b88713270a5 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 8 Sep 2020 14:04:10 -0700 Subject: [PATCH 3/3] Scott's update plus bugfix --- adafruit_matrixportal/matrixportal.py | 28 ++++++++++----------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/adafruit_matrixportal/matrixportal.py b/adafruit_matrixportal/matrixportal.py index 0c8881c..b91c57b 100755 --- a/adafruit_matrixportal/matrixportal.py +++ b/adafruit_matrixportal/matrixportal.py @@ -251,27 +251,19 @@ def set_text(self, val, index=0): if self._text_maxlen[index]: string = string[: self._text_maxlen[index]] print("text index", self._text[index]) + index_in_splash = None if self._text[index] is not None: print("Replacing text area with :", string) self._text[index].text = string - text_index = self.splash.index(self._text[index]) - - self._text[index] = Label( - self._text_font, text=string, max_glyphs=max_glyphs - ) - self._text[index].color = self._text_color[index] - self._text[index].x = self._text_position[index][0] - self._text[index].y = self._text_position[index][1] - self.splash[text_index] = self._text[index] - - elif self._text_position[index]: # if we want it placed somewhere... - print("Making text area with string:", string) - self._text[index] = Label( - self._text_font, text=string, max_glyphs=max_glyphs - ) - self._text[index].color = self._text_color[index] - self._text[index].x = self._text_position[index][0] - self._text[index].y = self._text_position[index][1] + index_in_splash = self.splash.index(self._text[index]) + self._text[index] = Label(self._text_font, text=string, max_glyphs=max_glyphs) + self._text[index].color = self._text_color[index] + self._text[index].x = self._text_position[index][0] + self._text[index].y = self._text_position[index][1] + + if index_in_splash is not None: + self.splash[index_in_splash] = self._text[index] + else: self.splash.append(self._text[index]) def get_local_time(self, location=None):