From 40f068bdc9628677634becb6ac4ebfe8cd477d55 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Mon, 16 Nov 2020 15:49:21 -0800 Subject: [PATCH] Moved text wrapping to set_text() --- adafruit_magtag/magtag.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/adafruit_magtag/magtag.py b/adafruit_magtag/magtag.py index dd1b6e0..e6c2bbd 100755 --- a/adafruit_magtag/magtag.py +++ b/adafruit_magtag/magtag.py @@ -249,6 +249,12 @@ def set_text(self, val, index=0, auto_refresh=True): string += "..." index_in_splash = None + if len(string) > 0 and self._text_wrap[index]: + if self._debug: + print("Wrapping text with length of", self._text_wrap[index]) + lines = self.wrap_nicely(string, self._text_wrap[index]) + string = "\n".join(lines) + if self._text[index] is not None: if self._debug: print("Replacing text area with :", string) @@ -356,13 +362,6 @@ def fetch(self, refresh_url=None, timeout=10): string = "{:,d}".format(int(values[i])) except (TypeError, ValueError): string = values[i] # ok its a string - if self._debug: - print("Drawing text", string) - if self._text_wrap[i]: - if self._debug: - print("Wrapping text with length of", self._text_wrap[i]) - lines = self.wrap_nicely(string, self._text_wrap[i]) - string = "\n".join(lines) self.set_text(string, index=i, auto_refresh=False) self.refresh() if len(values) == 1: