Skip to content

Commit 88635f3

Browse files
authored
Merge pull request #170 from rgrizzell/main
Add typing and documentation for ScrollingLabel
2 parents f60a409 + 0cc84af commit 88635f3

File tree

5 files changed

+55
-41
lines changed

5 files changed

+55
-41
lines changed

adafruit_display_text/scrolling_label.py

+32-30
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,40 @@
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+
2935
import time
3036
from adafruit_display_text import bitmap_label
3137

3238

3339
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
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

docs/api.rst

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313

1414
.. automodule:: adafruit_display_text.bitmap_label
1515
:members:
16+
17+
.. automodule:: adafruit_display_text.scrolling_label
18+
:members:

docs/examples.rst

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Simple test
1+
Simple Test
22
------------
33

44
Ensure your device works with this simple test.
@@ -7,7 +7,7 @@ Ensure your device works with this simple test.
77
:caption: examples/display_text_simpletest.py
88
:linenos:
99

10-
Bitmap_label Simple test
10+
Bitmap_label Simple Test
1111
------------------------
1212

1313
Simple test using bitmap_label to display text
@@ -16,6 +16,15 @@ Simple test using bitmap_label to display text
1616
:caption: examples/display_text_bitmap_label_simpletest.py
1717
:linenos:
1818

19+
ScrollingLabel Simple Test
20+
---------------------------
21+
22+
Simple test using scrolling_label to display text
23+
24+
.. literalinclude:: ../examples/display_text_scrolling_label.py
25+
:caption: examples/display_text_scrolling_label.py
26+
:linenos:
27+
1928
Label vs Bitmap_label Comparison
2029
--------------------------------
2130

@@ -25,7 +34,7 @@ Example to compare Label and Bitmap_Label characteristics
2534
:caption: examples/display_text_label_vs_bitmap_label_comparison.py
2635
:linenos:
2736

28-
Background color example
37+
Background Color Example
2938
------------------------
3039

3140
Show the text backgrounds features
@@ -34,7 +43,7 @@ Show the text backgrounds features
3443
:caption: examples/display_text_background_color.py
3544
:linenos:
3645

37-
Text padding example
46+
Text Padding Example
3847
--------------------
3948

4049
Show the text padding features in all directions
@@ -61,7 +70,7 @@ Boundingbox demonstration
6170
:caption: examples/display_text_textarea_boundingbox.py
6271
:linenos:
6372

64-
Align Baseline example
73+
Align Baseline Example
6574
----------------------
6675

6776
Demonstrate how to align different labels to a common horizontal line
@@ -70,7 +79,7 @@ Demonstrate how to align different labels to a common horizontal line
7079
:caption: examples/display_text_label_align_baseline_comparison.py
7180
:linenos:
7281

73-
Magtag example
82+
Magtag Example
7483
--------------
7584

7685
Uses the MAGTAG to display some text
@@ -79,7 +88,7 @@ Uses the MAGTAG to display some text
7988
:caption: examples/display_text_magtag.py
8089
:linenos:
8190

82-
MatrixPortal example
91+
MatrixPortal Example
8392
--------------------
8493

8594
Uses the MatrixPortal to display some text
@@ -88,7 +97,7 @@ Uses the MatrixPortal to display some text
8897
:caption: examples/display_text_matrixportal.py
8998
:linenos:
9099

91-
PyPortal example
100+
PyPortal Example
92101
----------------
93102

94103
Uses the Pyportal to display some text
@@ -97,7 +106,7 @@ Uses the Pyportal to display some text
97106
:caption: examples/display_text_pyportal.py
98107
:linenos:
99108

100-
Wraptest example
109+
Wraptest Example
101110
----------------
102111

103112
Illustrates the wraptest feature

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# SPDX-License-Identifier: Unlicense
44

55
Adafruit-Blinka
6-
adafruit-blinka-displayio
6+
adafruit-blinka-displayio>=0.10.2
77
adafruit-circuitpython-bitmap-font

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
author_email="[email protected]",
3535
install_requires=[
3636
"Adafruit-Blinka",
37-
"adafruit-blinka-displayio",
37+
"adafruit-blinka-displayio>=0.10.2",
3838
"adafruit-circuitpython-bitmap-font",
3939
],
4040
# Choose your license

0 commit comments

Comments
 (0)