@@ -65,13 +65,13 @@ def __init__(
65
65
self .animate_time = animate_time
66
66
self ._current_index = current_index
67
67
self ._last_animate_time = - 1
68
- self .max_characters = max_characters
68
+ self ._max_characters = max_characters
69
69
70
- if text and text [- 1 ] != " " :
70
+ if text and text [- 1 ] != " " and len ( text ) > max_characters :
71
71
text = f"{ text } "
72
72
self ._full_text = text
73
73
74
- self .update ()
74
+ self .update (True )
75
75
76
76
def update (self , force : bool = False ) -> None :
77
77
"""Attempt to update the display. If ``animate_time`` has elapsed since
@@ -137,7 +137,7 @@ def full_text(self) -> str:
137
137
138
138
@full_text .setter
139
139
def full_text (self , new_text : str ) -> None :
140
- if new_text and new_text [- 1 ] != " " :
140
+ if new_text and new_text [- 1 ] != " " and len ( new_text ) > self . max_characters :
141
141
new_text = f"{ new_text } "
142
142
if new_text != self ._full_text :
143
143
self ._full_text = new_text
@@ -156,3 +156,22 @@ def text(self):
156
156
@text .setter
157
157
def text (self , new_text ):
158
158
self .full_text = new_text
159
+
160
+ @property
161
+ def max_characters (self ):
162
+ """The maximum number of characters to display on screen.
163
+
164
+ :return int: The maximum character length of this label.
165
+ """
166
+ return self ._max_characters
167
+
168
+ @max_characters .setter
169
+ def max_characters (self , new_max_characters ):
170
+ """Recalculate the full text based on the new max characters.
171
+
172
+ This is necessary to correctly handle the potential space at the end of
173
+ the text.
174
+ """
175
+ if new_max_characters != self ._max_characters :
176
+ self ._max_characters = new_max_characters
177
+ self .full_text = self .full_text
0 commit comments