Skip to content

Commit 275466f

Browse files
committed
Reannotate matrix.py
1 parent 2c12658 commit 275466f

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

adafruit_ht16k33/matrix.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
"""
1111
from adafruit_ht16k33.ht16k33 import HT16K33
1212

13+
try:
14+
from typing import Optional, Tuple, Union, List
15+
from circuitpython_typing.pil import Image
16+
from busio import I2C
17+
except ImportError:
18+
pass
19+
1320

1421
__version__ = "0.0.0+auto.0"
1522
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"
@@ -21,7 +28,7 @@ class Matrix8x8(HT16K33):
2128
_columns = 8
2229
_rows = 8
2330

24-
def pixel(self, x, y, color = None):
31+
def pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]:
2532
"""Get or set the color of a given pixel.
2633
2734
:param int x: The x coordinate of the pixel
@@ -37,16 +44,16 @@ def pixel(self, x, y, color = None):
3744
x = (x - 1) % 8
3845
return super()._pixel(x, y, color)
3946

40-
def __getitem__(self, key):
47+
def __getitem__(self, key: Tuple[int, int]) -> Optional[bool]:
4148
x, y = key
4249
return self.pixel(x, y)
4350

44-
def __setitem__(self, key, value):
51+
def __setitem__(self, key: Tuple[int, int], value: Optional[bool]) -> None:
4552
x, y = key
4653
self.pixel(x, y, value)
4754

4855
# pylint: disable=too-many-branches
49-
def shift(self, x, y, rotate = False):
56+
def shift(self, x: int, y: int, rotate: bool = False) -> None:
5057
"""
5158
Shift pixels by x and y
5259
@@ -90,39 +97,39 @@ def shift(self, x, y, rotate = False):
9097

9198
# pylint: enable=too-many-branches
9299

93-
def shift_right(self, rotate = False):
100+
def shift_right(self, rotate: bool = False) -> None:
94101
"""
95102
Shift all pixels right
96103
97104
:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
98105
"""
99106
self.shift(1, 0, rotate)
100107

101-
def shift_left(self, rotate = False):
108+
def shift_left(self, rotate: bool = False) -> None:
102109
"""
103110
Shift all pixels left
104111
105112
:param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
106113
"""
107114
self.shift(-1, 0, rotate)
108115

109-
def shift_up(self, rotate = False):
116+
def shift_up(self, rotate: bool = False) -> None:
110117
"""
111118
Shift all pixels up
112119
113120
:param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
114121
"""
115122
self.shift(0, 1, rotate)
116123

117-
def shift_down(self, rotate = False):
124+
def shift_down(self, rotate: bool = False) -> None:
118125
"""
119126
Shift all pixels down
120127
121128
:param rotate: (Optional) Rotate the shifted pixels to top (default=False)
122129
"""
123130
self.shift(0, -1, rotate)
124131

125-
def image(self, img):
132+
def image(self, img: Image):
126133
"""Set buffer to value of Python Imaging Library image. The image should
127134
be in 1 bit mode and a size equal to the display size.
128135
@@ -149,12 +156,12 @@ def image(self, img):
149156
self.show()
150157

151158
@property
152-
def columns(self):
159+
def columns(self) -> int:
153160
"""Read-only property for number of columns"""
154161
return self._columns
155162

156163
@property
157-
def rows(self):
164+
def rows(self) -> int:
158165
"""Read-only property for number of rows"""
159166
return self._rows
160167

@@ -166,15 +173,15 @@ class Matrix16x8(Matrix8x8):
166173

167174
def __init__(
168175
self,
169-
i2c,
170-
address = 0x70,
171-
auto_write = True,
172-
brightness = 1.0,
173-
):
176+
i2c: I2C,
177+
address: Union[int, List[int], Tuple[int, ...]] = 0x70,
178+
auto_write: bool = True,
179+
brightness: float = 1.0,
180+
) -> None:
174181
super().__init__(i2c, address, auto_write, brightness)
175182
self._columns *= len(self.i2c_device)
176183

177-
def pixel(self, x, y, color = None):
184+
def pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]:
178185
"""Get or set the color of a given pixel.
179186
180187
:param int x: The x coordinate of the pixel
@@ -198,7 +205,7 @@ def pixel(self, x, y, color = None):
198205
class MatrixBackpack16x8(Matrix16x8):
199206
"""A double matrix backpack."""
200207

201-
def pixel(self, x, y, color = None):
208+
def pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]:
202209
"""Get or set the color of a given pixel.
203210
204211
:param int x: The x coordinate of the pixel
@@ -223,7 +230,7 @@ class Matrix8x8x2(Matrix8x8):
223230
LED_GREEN = 2
224231
LED_YELLOW = 3
225232

226-
def pixel(self, x, y, color = None):
233+
def pixel(self, x: int, y: int, color: Optional[int] = None) -> Optional[int]:
227234
"""Get or set the color of a given pixel.
228235
229236
:param int x: The x coordinate of the pixel
@@ -243,7 +250,7 @@ def pixel(self, x, y, color = None):
243250
return super()._pixel(y, x) | super()._pixel(y + 8, x) << 1
244251
return None
245252

246-
def fill(self, color):
253+
def fill(self, color: int) -> None:
247254
"""Fill the whole display with the given color.
248255
249256
:param bool color: Whether to fill the display
@@ -257,7 +264,7 @@ def fill(self, color):
257264
if self._auto_write:
258265
self.show()
259266

260-
def image(self, img):
267+
def image(self, img: Image) -> None:
261268
"""Set buffer to value of Python Imaging Library image. The image should
262269
be a size equal to the display size.
263270

0 commit comments

Comments
 (0)