@@ -65,7 +65,7 @@ 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
70
if text and text [- 1 ] != " " :
71
71
text = f"{ text } "
@@ -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,21 @@ 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
+ This is necessary to correctly handle the potential space at the end of
172
+ the text.
173
+ """
174
+ if new_max_characters != self ._max_characters :
175
+ self ._max_characters = new_max_characters
176
+ self .full_text = self .full_text
0 commit comments