23
23
https://github.com/adafruit/circuitpython/releases
24
24
"""
25
25
26
+ try :
27
+ from typing import Optional , Tuple
28
+ from fontio import FontProtocol
29
+ except ImportError :
30
+ pass
31
+
26
32
import board
27
33
import displayio
28
34
import terminalio
@@ -58,15 +64,15 @@ class SimpleTextDisplay:
58
64
59
65
def __init__ (
60
66
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 ),
63
69
title_scale : int = 1 ,
64
70
title_length : int = 0 , # Ignored - will be removed in a future version
65
71
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 :
70
76
# pylint: disable=too-many-arguments, unused-argument
71
77
"""Display lines of text on a display using displayio. Lines of text are created in order as
72
78
shown in the example below. If you skip a number, the line will be shown blank on the
@@ -75,23 +81,23 @@ def __init__(
75
81
line. Remember, Python begins counting at 0, so the first line on the display is 0 in the
76
82
code. Setup occurs before the loop. For data to be dynamically updated on the display, you
77
83
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 =
79
85
microcontroller.cpu.temperature`` must be inside the ``while True:`` loop for the
80
86
temperature data displayed to update as the values change. You must call `show()` at the
81
87
end of the list for anything to display. See example below for usage.
82
88
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
84
90
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
86
92
title is provided. Defaults to white (255, 255, 255).
87
93
:param int title_scale: Scale the size of the title. Not necessary if no title is provided.
88
94
Defaults to 1.
89
95
:param int title_length: DEPRECATED/IGNORED - This will be removed in a future version.
90
96
:param int text_scale: Scale the size of the data lines. Scales the title as well.
91
97
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
95
101
on the display. If you provide a single color, all lines will be that color. Otherwise
96
102
it will cycle through the list you provide if the list is less than the number of lines
97
103
displayed. Default colors are used if ``colors`` is not set. For example, if creating
@@ -101,7 +107,7 @@ def __init__(
101
107
library. For example, if you import the library as
102
108
``from adafruit_simple_text_display import SimpleTextDisplay``, you can indicate the
103
109
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
105
111
display. To use with an external display, instantiate the display object and provide it
106
112
here. Defaults to ``board.DISPLAY``.
107
113
@@ -168,7 +174,7 @@ def __init__(
168
174
# Add first line
169
175
self ._lines .append (self .add_text_line (color = colors [0 ]))
170
176
171
- def __getitem__ (self , item ) :
177
+ def __getitem__ (self , item : int ) -> label . Label :
172
178
"""Fetch the Nth text line Group"""
173
179
if len (self ._lines ) - 1 < item :
174
180
for i in range (len (self ._lines ), item + 1 ):
@@ -177,7 +183,9 @@ def __getitem__(self, item):
177
183
)
178
184
return self ._lines [item ]
179
185
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 :
181
189
"""Adds a line on the display of the specified color and returns the label object."""
182
190
183
191
text_label = label .Label (
@@ -194,10 +202,10 @@ def add_text_line(self, color=(255, 255, 255)):
194
202
195
203
return text_label
196
204
197
- def show (self ):
205
+ def show (self ) -> None :
198
206
"""Call show() to display the data list."""
199
207
self ._display .show (self .text_group )
200
208
201
- def show_terminal (self ):
209
+ def show_terminal (self ) -> None :
202
210
"""Revert to terminalio screen."""
203
211
self ._display .show (None )
0 commit comments