Skip to content

Commit b5bdb1e

Browse files
authored
Merge pull request #13 from isacben/add-type-annotations
Added type annotations
2 parents e3519ec + e6532ff commit b5bdb1e

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

adafruit_simple_text_display.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
https://github.com/adafruit/circuitpython/releases
2424
"""
2525

26+
try:
27+
from typing import Optional, Tuple
28+
from fontio import FontProtocol
29+
except ImportError:
30+
pass
31+
2632
import board
2733
import displayio
2834
import terminalio
@@ -58,15 +64,15 @@ class SimpleTextDisplay:
5864

5965
def __init__(
6066
self,
61-
title=None,
62-
title_color=(255, 255, 255),
67+
title: Optional[str] = None,
68+
title_color: Tuple[int, int, int] = (255, 255, 255),
6369
title_scale: int = 1,
6470
title_length: int = 0, # Ignored - will be removed in a future version
6571
text_scale: int = 1,
66-
font=None,
67-
colors=None,
68-
display=None,
69-
):
72+
font: Optional[FontProtocol] = None,
73+
colors: Optional[Tuple[Tuple[int, int, int], ...]] = None,
74+
display: Optional[displayio.Display] = None,
75+
) -> None:
7076
# pylint: disable=too-many-arguments, unused-argument
7177
"""Display lines of text on a display using displayio. Lines of text are created in order as
7278
shown in the example below. If you skip a number, the line will be shown blank on the
@@ -75,23 +81,23 @@ def __init__(
7581
line. Remember, Python begins counting at 0, so the first line on the display is 0 in the
7682
code. Setup occurs before the loop. For data to be dynamically updated on the display, you
7783
must include the data call in the loop by using ``.text =``. For example, if setup is saved
78-
as ``temperature_data = simple_text_display()`` then ``temperature_data[0].text =
84+
as ``temperature_data = SimpleTextDisplay()`` then ``temperature_data[0].text =
7985
microcontroller.cpu.temperature`` must be inside the ``while True:`` loop for the
8086
temperature data displayed to update as the values change. You must call `show()` at the
8187
end of the list for anything to display. See example below for usage.
8288
83-
:param None,str title: The title displayed above the data. Set ``title="Title text"`` to
89+
:param str|None title: The title displayed above the data. Set ``title="Title text"`` to
8490
provide a title. Defaults to `None`.
85-
:param None,Tuple(int,int,int) title_color: The color of the title. Not necessary if no
91+
:param Tuple(int, int, int)|None title_color: The color of the title. Not necessary if no
8692
title is provided. Defaults to white (255, 255, 255).
8793
:param int title_scale: Scale the size of the title. Not necessary if no title is provided.
8894
Defaults to 1.
8995
:param int title_length: DEPRECATED/IGNORED - This will be removed in a future version.
9096
:param int text_scale: Scale the size of the data lines. Scales the title as well.
9197
Defaults to 1.
92-
:param ~fontio.BuiltinFont,~adafruit_bitmap_font.bdf.BDF,~adafruit_bitmap_font.pcf.PCF font:
93-
The font to use to display the title and data. Defaults to `terminalio.FONT`.
94-
:param None,Tuple(Tuple(int,int,int),...) colors: A list of colors for the lines of data
98+
:param ~FontProtocol|None font: The font to use to display the title and data. Defaults to
99+
`terminalio.FONT`.
100+
:param Tuple(Tuple(int, int, int), ...)|None colors: A list of colors for the lines of data
95101
on the display. If you provide a single color, all lines will be that color. Otherwise
96102
it will cycle through the list you provide if the list is less than the number of lines
97103
displayed. Default colors are used if ``colors`` is not set. For example, if creating
@@ -101,7 +107,7 @@ def __init__(
101107
library. For example, if you import the library as
102108
``from adafruit_simple_text_display import SimpleTextDisplay``, you can indicate the
103109
colors as follows: ``colors=(SimpleTextDisplay.WHITE, SimpleTextDisplay.RED)``.
104-
:param None,~displayio.Display display: The display object. Defaults to assuming a built-in
110+
:param ~displayio.Display|None display: The display object. Defaults to assuming a built-in
105111
display. To use with an external display, instantiate the display object and provide it
106112
here. Defaults to ``board.DISPLAY``.
107113
@@ -168,7 +174,7 @@ def __init__(
168174
# Add first line
169175
self._lines.append(self.add_text_line(color=colors[0]))
170176

171-
def __getitem__(self, item):
177+
def __getitem__(self, item: int) -> label.Label:
172178
"""Fetch the Nth text line Group"""
173179
if len(self._lines) - 1 < item:
174180
for i in range(len(self._lines), item + 1):
@@ -177,7 +183,9 @@ def __getitem__(self, item):
177183
)
178184
return self._lines[item]
179185

180-
def add_text_line(self, color=(255, 255, 255)):
186+
def add_text_line(
187+
self, color: Tuple[int, int, int] = (255, 255, 255)
188+
) -> label.Label:
181189
"""Adds a line on the display of the specified color and returns the label object."""
182190

183191
text_label = label.Label(
@@ -194,10 +202,10 @@ def add_text_line(self, color=(255, 255, 255)):
194202

195203
return text_label
196204

197-
def show(self):
205+
def show(self) -> None:
198206
"""Call show() to display the data list."""
199207
self._display.show(self.text_group)
200208

201-
def show_terminal(self):
209+
def show_terminal(self) -> None:
202210
"""Revert to terminalio screen."""
203211
self._display.show(None)

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44

55
Adafruit-Blinka
66
adafruit-circuitpython-display-text
7-
adafruit-circuitpython-bitmap-font

0 commit comments

Comments
 (0)