Skip to content

Commit 316d40c

Browse files
committed
Adding typing information to scrolling_label.py
1 parent 4025ea6 commit 316d40c

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

adafruit_display_text/scrolling_label.py

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,42 @@
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 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+
2937
import time
3038
from adafruit_display_text import bitmap_label
3139

3240

3341
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
3743
in order to show the full text if it's larger than the fixed-width.
3844
3945
: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
4451
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."""
4854

4955
# pylint: disable=too-many-arguments
5056
def __init__(
5157
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,
5763
**kwargs
58-
):
64+
) -> None:
5965

6066
super().__init__(font, **kwargs)
6167
self.animate_time = animate_time
@@ -69,13 +75,12 @@ def __init__(
6975

7076
self.update()
7177

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
7580
previews animation frame then move the characters over by 1 index.
7681
Must be called in the main loop of user code.
7782
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.
7984
:return: None
8085
"""
8186
_now = time.monotonic()
@@ -110,33 +115,31 @@ def update(self, force=False):
110115
return
111116

112117
@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.
116120
117-
:return int: the current index
121+
:return int: The current index
118122
"""
119123
return self._current_index
120124

121125
@current_index.setter
122-
def current_index(self, new_index):
126+
def current_index(self, new_index: int):
123127
if new_index < len(self.full_text):
124128
self._current_index = new_index
125129
else:
126130
self._current_index = new_index % len(self.full_text)
127131

128132
@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
132135
scrolling will occur as needed.
133136
134137
:return string: The full text of this label.
135138
"""
136139
return self._full_text
137140

138141
@full_text.setter
139-
def full_text(self, new_text):
142+
def full_text(self, new_text: str):
140143
if new_text[-1] != " ":
141144
new_text = "{} ".format(new_text)
142145
self._full_text = new_text

0 commit comments

Comments
 (0)