From e79ce9d1ca4c10a89486d770e5e2873abaa22bb3 Mon Sep 17 00:00:00 2001 From: cinderblockgames <79210192+cinderblockgames@users.noreply.github.com> Date: Sun, 25 May 2025 22:14:27 -0400 Subject: [PATCH 1/7] Managing addition of space at end of text Wrapping max_characters in properties and checking for length of text before adding a space to full_text. --- adafruit_display_text/scrolling_label.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 67159c0..490a744 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -65,7 +65,7 @@ def __init__( self.animate_time = animate_time self._current_index = current_index self._last_animate_time = -1 - self.max_characters = max_characters + self._max_characters = max_characters if text and text[-1] != " ": text = f"{text} " @@ -137,7 +137,7 @@ def full_text(self) -> str: @full_text.setter def full_text(self, new_text: str) -> None: - if new_text and new_text[-1] != " ": + if new_text and new_text[-1] != " " and len(new_text) > self.max_characters: new_text = f"{new_text} " if new_text != self._full_text: self._full_text = new_text @@ -156,3 +156,21 @@ def text(self): @text.setter def text(self, new_text): self.full_text = new_text + + @property + def max_characters(self): + """The maximum number of characters to display on screen. + + :return int: The maximum character length of this label. + """ + return self._max_characters + + @max_characters.setter + def max_characters(self, new_max_characters): + """Recalculate the full text based on the new max characters. + This is necessary to correctly handle the potential space at the end of + the text. + """ + if new_max_characters != self._max_characters: + self._max_characters = new_max_characters + self.full_text = self.full_text From 7ab6c88cdd552b5dfdf87354316bb15a101f55bb Mon Sep 17 00:00:00 2001 From: cinderblockgames <79210192+cinderblockgames@users.noreply.github.com> Date: Sun, 25 May 2025 22:31:53 -0400 Subject: [PATCH 2/7] Fixing in constructor as well Checking for max_characters in constructor before adding space. --- adafruit_display_text/scrolling_label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 490a744..68b9da9 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -67,7 +67,7 @@ def __init__( self._last_animate_time = -1 self._max_characters = max_characters - if text and text[-1] != " ": + if text and text[-1] != " " and len(text) > max_characters:: text = f"{text} " self._full_text = text From a0df56c4ffbedcd8fa269987cbdedcd968c27930 Mon Sep 17 00:00:00 2001 From: cinderblockgames <79210192+cinderblockgames@users.noreply.github.com> Date: Sun, 25 May 2025 22:35:03 -0400 Subject: [PATCH 3/7] Fixed typo :: -> : --- adafruit_display_text/scrolling_label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 68b9da9..5963272 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -67,7 +67,7 @@ def __init__( self._last_animate_time = -1 self._max_characters = max_characters - if text and text[-1] != " " and len(text) > max_characters:: + if text and text[-1] != " " and len(text) > max_characters: text = f"{text} " self._full_text = text From 9efd1f86de4187c9bf8c2f6d3d1c6041736663dc Mon Sep 17 00:00:00 2001 From: cinderblockgames <79210192+cinderblockgames@users.noreply.github.com> Date: Sun, 25 May 2025 23:24:21 -0400 Subject: [PATCH 4/7] Setting __init__ call to self.update to force If this isn't set to force the update, self._last_animate_time sometimes gets stuck as -1 for a while, thus keeping the label from appearing. --- adafruit_display_text/scrolling_label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 5963272..468c874 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -71,7 +71,7 @@ def __init__( text = f"{text} " self._full_text = text - self.update() + self.update(True) def update(self, force: bool = False) -> None: """Attempt to update the display. If ``animate_time`` has elapsed since From b0417dbe3e26db22788d1cb5d1b019396849daa8 Mon Sep 17 00:00:00 2001 From: cinderblockgames <79210192+cinderblockgames@users.noreply.github.com> Date: Mon, 26 May 2025 10:14:45 -0400 Subject: [PATCH 5/7] Update whitespace. Trying to get the ruff-format to succeed. --- adafruit_display_text/scrolling_label.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 468c874..07b4395 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -168,8 +168,9 @@ def max_characters(self): @max_characters.setter def max_characters(self, new_max_characters): """Recalculate the full text based on the new max characters. - This is necessary to correctly handle the potential space at the end of - the text. + + This is necessary to correctly handle the potential space at the end of + the text. """ if new_max_characters != self._max_characters: self._max_characters = new_max_characters From 8a95594a29bc1624a689ad08bed4685354340799 Mon Sep 17 00:00:00 2001 From: cinderblockgames <79210192+cinderblockgames@users.noreply.github.com> Date: Mon, 26 May 2025 10:15:14 -0400 Subject: [PATCH 6/7] Removed additional whitespace. Matching style. --- adafruit_display_text/scrolling_label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 07b4395..18787d7 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -168,7 +168,7 @@ def max_characters(self): @max_characters.setter def max_characters(self, new_max_characters): """Recalculate the full text based on the new max characters. - + This is necessary to correctly handle the potential space at the end of the text. """ From 51ba2d1f220f48a4d49af8f0e3ea2270ec687f43 Mon Sep 17 00:00:00 2001 From: cinderblockgames <79210192+cinderblockgames@users.noreply.github.com> Date: Mon, 26 May 2025 10:21:35 -0400 Subject: [PATCH 7/7] Removed extra whitespace. Matching style. --- adafruit_display_text/scrolling_label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 18787d7..372dc7d 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -156,7 +156,7 @@ def text(self): @text.setter def text(self, new_text): self.full_text = new_text - + @property def max_characters(self): """The maximum number of characters to display on screen.