Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty text and update text instantly #211

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions adafruit_display_text/scrolling_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(
self._last_animate_time = -1
self.max_characters = max_characters

if text[-1] != " ":
if text and text[-1] != " ":
text = "{} ".format(text)
self._full_text = text

Expand Down Expand Up @@ -123,10 +123,10 @@ def current_index(self) -> int:

@current_index.setter
def current_index(self, new_index: int) -> None:
if new_index < len(self.full_text):
self._current_index = new_index
else:
if self.full_text:
self._current_index = new_index % len(self.full_text)
else:
self._current_index = 0

@property
def full_text(self) -> str:
Expand All @@ -139,11 +139,12 @@ def full_text(self) -> str:

@full_text.setter
def full_text(self, new_text: str) -> None:
if new_text[-1] != " ":
if new_text and new_text[-1] != " ":
new_text = "{} ".format(new_text)
self._full_text = new_text
self.current_index = 0
self.update()
if new_text != self._full_text:
self._full_text = new_text
self.current_index = 0
self.update(True)

@property
def text(self):
Expand Down