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 Union , Optional , Tuple
31
+ from fontio import BuiltinFont
32
+ from adafruit_bitmap_font .bdf import BDF
33
+ from adafruit_bitmap_font .pcf import PCF
34
+ except ImportError :
35
+ pass
36
+
29
37
import time
30
38
from adafruit_display_text import bitmap_label
31
39
32
40
33
41
class ScrollingLabel (bitmap_label .Label ):
34
-
35
- """
36
- ScrollingLabel - A fixed-width label that will scroll to the left
42
+ """ScrollingLabel - A fixed-width label that will scroll to the left
37
43
in order to show the full text if it's larger than the fixed-width.
38
44
39
45
: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
46
+ :type font: ~BuiltinFont, ~BDF, or ~PCF
47
+ :param int max_characters: The number of characters that sets the fixed-width. Default is 10.
48
+ :param str text: The full text to show in the label. If this is longer than
49
+ ``max_characters`` then the label will scroll to show everything.
50
+ :param float animate_time: The number of seconds in between scrolling animation
44
51
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
- """
52
+ :param int current_index: The index of the first visible character in the label.
53
+ Default is 0, the first character. Will increase while scrolling."""
48
54
49
55
# pylint: disable=too-many-arguments
50
56
def __init__ (
51
57
self ,
52
- font ,
53
- max_characters = 10 ,
54
- text = "" ,
55
- animate_time = 0.3 ,
56
- current_index = 0 ,
58
+ font : Union [ BuiltinFont , BDF , PCF ] ,
59
+ max_characters : Optional [ int ] = 10 ,
60
+ text : Optional [ str ] = "" ,
61
+ animate_time : Optional [ float ] = 0.3 ,
62
+ current_index : Optional [ int ] = 0 ,
57
63
** kwargs
58
- ):
64
+ ) -> None :
59
65
60
66
super ().__init__ (font , ** kwargs )
61
67
self .animate_time = animate_time
@@ -69,13 +75,12 @@ def __init__(
69
75
70
76
self .update ()
71
77
72
- def update (self , force = False ):
73
- """
74
- Attempt to update the display. If `animate_time` has elapsed since
78
+ def update (self , force : Optional [bool ] = False ) -> None :
79
+ """Attempt to update the display. If ``animate_time`` has elapsed since
75
80
previews animation frame then move the characters over by 1 index.
76
81
Must be called in the main loop of user code.
77
82
78
- :param force: whether to ignore `animation_time` and force the update. Default is False.
83
+ :param bool force: whether to ignore `` animation_time` ` and force the update. Default is False.
79
84
:return: None
80
85
"""
81
86
_now = time .monotonic ()
@@ -110,33 +115,31 @@ def update(self, force=False):
110
115
return
111
116
112
117
@property
113
- def current_index (self ):
114
- """
115
- Index of the first visible character.
118
+ def current_index (self ) -> int :
119
+ """Index of the first visible character.
116
120
117
- :return int: the current index
121
+ :return int: The current index
118
122
"""
119
123
return self ._current_index
120
124
121
125
@current_index .setter
122
- def current_index (self , new_index ):
126
+ def current_index (self , new_index : int ):
123
127
if new_index < len (self .full_text ):
124
128
self ._current_index = new_index
125
129
else :
126
130
self ._current_index = new_index % len (self .full_text )
127
131
128
132
@property
129
- def full_text (self ):
130
- """
131
- The full text to be shown. If it's longer than `max_characters` then
133
+ def full_text (self ) -> str :
134
+ """The full text to be shown. If it's longer than ``max_characters`` then
132
135
scrolling will occur as needed.
133
136
134
137
:return string: The full text of this label.
135
138
"""
136
139
return self ._full_text
137
140
138
141
@full_text .setter
139
- def full_text (self , new_text ):
142
+ def full_text (self , new_text : str ):
140
143
if new_text [- 1 ] != " " :
141
144
new_text = "{} " .format (new_text )
142
145
self ._full_text = new_text
0 commit comments