4
4
# SPDX-License-Identifier: MIT
5
5
6
6
"""
7
- Matrix Displays
8
- ================
7
+ adafruit_ht16k33.matrix
8
+ =======================
9
9
10
10
"""
11
11
from adafruit_ht16k33 .ht16k33 import HT16K33
@@ -27,7 +27,14 @@ class Matrix8x8(HT16K33):
27
27
_rows = 8
28
28
29
29
def pixel (self , x : int , y : int , color : Optional [bool ] = None ) -> Optional [bool ]:
30
- """Get or set the color of a given pixel."""
30
+ """Get or set the color of a given pixel.
31
+
32
+ :param int x: The x coordinate of the pixel
33
+ :param int y: The y coordinate of the pixel
34
+ :param bool color: (Optional) The state to set the pixel
35
+ :return: If ``color`` was not set, this returns the state of the pixel
36
+ :rtype: bool
37
+ """
31
38
if not 0 <= x <= 7 :
32
39
return None
33
40
if not 0 <= y <= 7 :
@@ -39,16 +46,18 @@ def __getitem__(self, key: int) -> Optional[bool]:
39
46
x , y = key
40
47
return self .pixel (x , y )
41
48
42
- def __setitem__ (self , key : int , value : bool ):
49
+ def __setitem__ (self , key : int , value : bool ) -> None :
43
50
x , y = key
44
51
self .pixel (x , y , value )
45
52
46
53
# pylint: disable=too-many-branches
47
- def shift (self , x : int , y : int , rotate : bool = False ):
54
+ def shift (self , x : int , y : int , rotate : bool = False ) -> None :
48
55
"""
49
56
Shift pixels by x and y
50
57
51
- :param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
58
+ :param int x: The x coordinate of the pixel
59
+ :param int y: The y coordinate of the pixel
60
+ :param bool rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
52
61
"""
53
62
auto_write = self .auto_write
54
63
self ._auto_write = False
@@ -86,41 +95,45 @@ def shift(self, x: int, y: int, rotate: bool = False):
86
95
87
96
# pylint: enable=too-many-branches
88
97
89
- def shift_right (self , rotate : bool = False ):
98
+ def shift_right (self , rotate : bool = False ) -> None :
90
99
"""
91
100
Shift all pixels right
92
101
93
102
:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
94
103
"""
95
104
self .shift (1 , 0 , rotate )
96
105
97
- def shift_left (self , rotate : bool = False ):
106
+ def shift_left (self , rotate : bool = False ) -> None :
98
107
"""
99
108
Shift all pixels left
100
109
101
110
:param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
102
111
"""
103
112
self .shift (- 1 , 0 , rotate )
104
113
105
- def shift_up (self , rotate : bool = False ):
114
+ def shift_up (self , rotate : bool = False ) -> None :
106
115
"""
107
116
Shift all pixels up
108
117
109
118
:param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
110
119
"""
111
120
self .shift (0 , 1 , rotate )
112
121
113
- def shift_down (self , rotate : bool = False ):
122
+ def shift_down (self , rotate : bool = False ) -> None :
114
123
"""
115
124
Shift all pixels down
116
125
117
126
:param rotate: (Optional) Rotate the shifted pixels to top (default=False)
118
127
"""
119
128
self .shift (0 , - 1 , rotate )
120
129
121
- def image (self , img ) :
130
+ def image (self , img : Image ) -> None :
122
131
"""Set buffer to value of Python Imaging Library image. The image should
123
- be in 1 bit mode and a size equal to the display size."""
132
+ be in 1 bit mode and a size equal to the display size.
133
+
134
+ :param Image img: The image to show
135
+ """
136
+
124
137
imwidth , imheight = img .size
125
138
if imwidth != self .columns or imheight != self .rows :
126
139
raise ValueError (
@@ -141,12 +154,12 @@ def image(self, img):
141
154
self .show ()
142
155
143
156
@property
144
- def columns (self ):
157
+ def columns (self ) -> int :
145
158
"""Read-only property for number of columns"""
146
159
return self ._columns
147
160
148
161
@property
149
- def rows (self ):
162
+ def rows (self ) -> int :
150
163
"""Read-only property for number of rows"""
151
164
return self ._rows
152
165
@@ -156,8 +169,16 @@ class Matrix16x8(Matrix8x8):
156
169
157
170
_columns = 16
158
171
159
- def pixel (self , x , y , color = None ):
160
- """Get or set the color of a given pixel."""
172
+ def pixel (self , x : int , y : int , color : Optional [bool ] = None ) -> Optional [bool ]:
173
+ """Get or set the color of a given pixel.
174
+
175
+ :param int x: The x coordinate of the pixel
176
+ :param int y: The y coordinate of the pixel
177
+ :param bool color: (Optional) The state to set the pixel
178
+ :return: If ``color`` was not set, this returns the state of the pixel
179
+ :rtype: bool
180
+ """
181
+
161
182
if not 0 <= x <= 15 :
162
183
return None
163
184
if not 0 <= y <= 7 :
@@ -171,8 +192,16 @@ def pixel(self, x, y, color=None):
171
192
class MatrixBackpack16x8 (Matrix16x8 ):
172
193
"""A double matrix backpack."""
173
194
174
- def pixel (self , x , y , color = None ):
175
- """Get or set the color of a given pixel."""
195
+ def pixel (self , x : int , y : int , color : Optional [bool ] = None ) -> Optional [bool ]:
196
+ """Get or set the color of a given pixel.
197
+
198
+ :param int x: The x coordinate of the pixel
199
+ :param int y: The y coordinate of the pixel
200
+ :param bool color: (Optional) The state to set the pixel
201
+ :return: If ``color`` was not set, this returns the state of the pixel
202
+ :rtype: bool
203
+ """
204
+
176
205
if not 0 <= x <= 15 :
177
206
return None
178
207
if not 0 <= y <= 7 :
@@ -188,8 +217,15 @@ class Matrix8x8x2(Matrix8x8):
188
217
LED_GREEN = 2
189
218
LED_YELLOW = 3
190
219
191
- def pixel (self , x , y , color = None ):
192
- """Get or set the color of a given pixel."""
220
+ def pixel (self , x : int , y : int , color : Optional [bool ] = None ) -> Optional [bool ]:
221
+ """Get or set the color of a given pixel.
222
+
223
+ :param int x: The x coordinate of the pixel
224
+ :param int y: The y coordinate of the pixel
225
+ :param bool color: (Optional) The state to set the pixel
226
+ :return: If ``color`` was not set, this returns the state of the pixel
227
+ :rtype: bool
228
+ """
193
229
if not 0 <= x <= 7 :
194
230
return None
195
231
if not 0 <= y <= 7 :
@@ -201,8 +237,12 @@ def pixel(self, x, y, color=None):
201
237
return super ()._pixel (y , x ) | super ()._pixel (y + 8 , x ) << 1
202
238
return None
203
239
204
- def fill (self , color ):
205
- """Fill the whole display with the given color."""
240
+ def fill (self , color : bool ) -> None :
241
+ """Fill the whole display with the given color.
242
+
243
+ :param bool color: Whether to fill the display
244
+ """
245
+
206
246
fill1 = 0xFF if color & 0x01 else 0x00
207
247
fill2 = 0xFF if color & 0x02 else 0x00
208
248
for i in range (8 ):
@@ -211,9 +251,13 @@ def fill(self, color):
211
251
if self ._auto_write :
212
252
self .show ()
213
253
214
- def image (self , img : Image ):
254
+ def image (self , img : Image ) -> None :
215
255
"""Set buffer to value of Python Imaging Library image. The image should
216
- be a size equal to the display size."""
256
+ be a size equal to the display size.
257
+
258
+ :param Image img: The image to show
259
+ """
260
+
217
261
imwidth , imheight = img .size
218
262
if imwidth != self .columns or imheight != self .rows :
219
263
raise ValueError (
0 commit comments