26
26
__version__ = "0.0.0-auto.0"
27
27
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"
28
28
29
+ try :
30
+ from typing import Optional
31
+ from fontio import FontProtocol
32
+ except ImportError :
33
+ pass
34
+
29
35
import time
30
36
from adafruit_display_text import bitmap_label
31
37
32
38
33
39
class 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
37
41
in order to show the full text if it's larger than the fixed-width.
38
42
39
43
: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
44
49
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."""
48
52
49
53
# pylint: disable=too-many-arguments
50
54
def __init__ (
51
55
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 ,
57
61
** kwargs
58
- ):
62
+ ) -> None :
59
63
60
64
super ().__init__ (font , ** kwargs )
61
65
self .animate_time = animate_time
@@ -69,13 +73,13 @@ def __init__(
69
73
70
74
self .update ()
71
75
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
75
78
previews animation frame then move the characters over by 1 index.
76
79
Must be called in the main loop of user code.
77
80
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.
79
83
:return: None
80
84
"""
81
85
_now = time .monotonic ()
@@ -110,33 +114,31 @@ def update(self, force=False):
110
114
return
111
115
112
116
@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.
116
119
117
- :return int: the current index
120
+ :return int: The current index
118
121
"""
119
122
return self ._current_index
120
123
121
124
@current_index .setter
122
- def current_index (self , new_index ) :
125
+ def current_index (self , new_index : int ) -> None :
123
126
if new_index < len (self .full_text ):
124
127
self ._current_index = new_index
125
128
else :
126
129
self ._current_index = new_index % len (self .full_text )
127
130
128
131
@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
132
134
scrolling will occur as needed.
133
135
134
- :return string : The full text of this label.
136
+ :return str : The full text of this label.
135
137
"""
136
138
return self ._full_text
137
139
138
140
@full_text .setter
139
- def full_text (self , new_text ) :
141
+ def full_text (self , new_text : str ) -> None :
140
142
if new_text [- 1 ] != " " :
141
143
new_text = "{} " .format (new_text )
142
144
self ._full_text = new_text
0 commit comments