2626__version__ = "0.0.0-auto.0"
2727__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"
2828
29+ try :
30+ from typing import Optional
31+ from fontio import FontProtocol
32+ except ImportError :
33+ pass
34+
2935import time
3036from adafruit_display_text import bitmap_label
3137
3238
3339class ScrollingLabel (bitmap_label .Label ):
34-
35- """
36- ScrollingLabel - A fixed-width label that will scroll to the left
40+ """ScrollingLabel - A fixed-width label that will scroll to the left
3741 in order to show the full text if it's larger than the fixed-width.
3842
3943 :param font: The font to use for the label.
40- :param max_characters: The number of characters that sets the fixed-width. Default is 10.
41- :param text: The full text to show in the label. If this is longer than
42- `max_characters` then the label will scroll to show everything.
43- :param animate_time: The number of seconds in between scrolling animation
44+ :type: ~FontProtocol
45+ :param int max_characters: The number of characters that sets the fixed-width. Default is 10.
46+ :param str text: The full text to show in the label. If this is longer than
47+ ``max_characters`` then the label will scroll to show everything.
48+ :param float animate_time: The number of seconds in between scrolling animation
4449 frames. Default is 0.3 seconds.
45- :param current_index: The index of the first visible character in the label.
46- Default is 0, the first character. Will increase while scrolling.
47- """
50+ :param int current_index: The index of the first visible character in the label.
51+ Default is 0, the first character. Will increase while scrolling."""
4852
4953 # pylint: disable=too-many-arguments
5054 def __init__ (
5155 self ,
52- font ,
53- max_characters = 10 ,
54- text = "" ,
55- animate_time = 0.3 ,
56- current_index = 0 ,
56+ font : FontProtocol ,
57+ max_characters : int = 10 ,
58+ text : Optional [ str ] = "" ,
59+ animate_time : Optional [ float ] = 0.3 ,
60+ current_index : Optional [ int ] = 0 ,
5761 ** kwargs
58- ):
62+ ) -> None :
5963
6064 super ().__init__ (font , ** kwargs )
6165 self .animate_time = animate_time
@@ -69,13 +73,13 @@ def __init__(
6973
7074 self .update ()
7175
72- def update (self , force = False ):
73- """
74- Attempt to update the display. If `animate_time` has elapsed since
76+ def update (self , force : bool = False ) -> None :
77+ """Attempt to update the display. If ``animate_time`` has elapsed since
7578 previews animation frame then move the characters over by 1 index.
7679 Must be called in the main loop of user code.
7780
78- :param force: whether to ignore `animation_time` and force the update. Default is False.
81+ :param bool force: whether to ignore ``animation_time`` and force the update.
82+ Default is False.
7983 :return: None
8084 """
8185 _now = time .monotonic ()
@@ -110,33 +114,31 @@ def update(self, force=False):
110114 return
111115
112116 @property
113- def current_index (self ):
114- """
115- Index of the first visible character.
117+ def current_index (self ) -> int :
118+ """Index of the first visible character.
116119
117- :return int: the current index
120+ :return int: The current index
118121 """
119122 return self ._current_index
120123
121124 @current_index .setter
122- def current_index (self , new_index ) :
125+ def current_index (self , new_index : int ) -> None :
123126 if new_index < len (self .full_text ):
124127 self ._current_index = new_index
125128 else :
126129 self ._current_index = new_index % len (self .full_text )
127130
128131 @property
129- def full_text (self ):
130- """
131- The full text to be shown. If it's longer than `max_characters` then
132+ def full_text (self ) -> str :
133+ """The full text to be shown. If it's longer than ``max_characters`` then
132134 scrolling will occur as needed.
133135
134- :return string : The full text of this label.
136+ :return str : The full text of this label.
135137 """
136138 return self ._full_text
137139
138140 @full_text .setter
139- def full_text (self , new_text ) :
141+ def full_text (self , new_text : str ) -> None :
140142 if new_text [- 1 ] != " " :
141143 new_text = "{} " .format (new_text )
142144 self ._full_text = new_text
0 commit comments