44# SPDX-License-Identifier: MIT
55
66"""
7- Matrix Displays
8- ================
7+ adafruit_ht16k33.matrix
8+ =======================
99
1010"""
1111from adafruit_ht16k33 .ht16k33 import HT16K33
@@ -27,7 +27,14 @@ class Matrix8x8(HT16K33):
2727 _rows = 8
2828
2929 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+ """
3138 if not 0 <= x <= 7 :
3239 return None
3340 if not 0 <= y <= 7 :
@@ -39,16 +46,18 @@ def __getitem__(self, key: int) -> Optional[bool]:
3946 x , y = key
4047 return self .pixel (x , y )
4148
42- def __setitem__ (self , key : int , value : bool ):
49+ def __setitem__ (self , key : int , value : bool ) -> None :
4350 x , y = key
4451 self .pixel (x , y , value )
4552
4653 # 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 :
4855 """
4956 Shift pixels by x and y
5057
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)
5261 """
5362 auto_write = self .auto_write
5463 self ._auto_write = False
@@ -86,41 +95,45 @@ def shift(self, x: int, y: int, rotate: bool = False):
8695
8796 # pylint: enable=too-many-branches
8897
89- def shift_right (self , rotate : bool = False ):
98+ def shift_right (self , rotate : bool = False ) -> None :
9099 """
91100 Shift all pixels right
92101
93102 :param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
94103 """
95104 self .shift (1 , 0 , rotate )
96105
97- def shift_left (self , rotate : bool = False ):
106+ def shift_left (self , rotate : bool = False ) -> None :
98107 """
99108 Shift all pixels left
100109
101110 :param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
102111 """
103112 self .shift (- 1 , 0 , rotate )
104113
105- def shift_up (self , rotate : bool = False ):
114+ def shift_up (self , rotate : bool = False ) -> None :
106115 """
107116 Shift all pixels up
108117
109118 :param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
110119 """
111120 self .shift (0 , 1 , rotate )
112121
113- def shift_down (self , rotate : bool = False ):
122+ def shift_down (self , rotate : bool = False ) -> None :
114123 """
115124 Shift all pixels down
116125
117126 :param rotate: (Optional) Rotate the shifted pixels to top (default=False)
118127 """
119128 self .shift (0 , - 1 , rotate )
120129
121- def image (self , img ) :
130+ def image (self , img : Image ) -> None :
122131 """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+
124137 imwidth , imheight = img .size
125138 if imwidth != self .columns or imheight != self .rows :
126139 raise ValueError (
@@ -141,12 +154,12 @@ def image(self, img):
141154 self .show ()
142155
143156 @property
144- def columns (self ):
157+ def columns (self ) -> int :
145158 """Read-only property for number of columns"""
146159 return self ._columns
147160
148161 @property
149- def rows (self ):
162+ def rows (self ) -> int :
150163 """Read-only property for number of rows"""
151164 return self ._rows
152165
@@ -156,8 +169,16 @@ class Matrix16x8(Matrix8x8):
156169
157170 _columns = 16
158171
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+
161182 if not 0 <= x <= 15 :
162183 return None
163184 if not 0 <= y <= 7 :
@@ -171,8 +192,16 @@ def pixel(self, x, y, color=None):
171192class MatrixBackpack16x8 (Matrix16x8 ):
172193 """A double matrix backpack."""
173194
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+
176205 if not 0 <= x <= 15 :
177206 return None
178207 if not 0 <= y <= 7 :
@@ -188,8 +217,15 @@ class Matrix8x8x2(Matrix8x8):
188217 LED_GREEN = 2
189218 LED_YELLOW = 3
190219
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+ """
193229 if not 0 <= x <= 7 :
194230 return None
195231 if not 0 <= y <= 7 :
@@ -201,8 +237,12 @@ def pixel(self, x, y, color=None):
201237 return super ()._pixel (y , x ) | super ()._pixel (y + 8 , x ) << 1
202238 return None
203239
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+
206246 fill1 = 0xFF if color & 0x01 else 0x00
207247 fill2 = 0xFF if color & 0x02 else 0x00
208248 for i in range (8 ):
@@ -211,9 +251,13 @@ def fill(self, color):
211251 if self ._auto_write :
212252 self .show ()
213253
214- def image (self , img : Image ):
254+ def image (self , img : Image ) -> None :
215255 """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+
217261 imwidth , imheight = img .size
218262 if imwidth != self .columns or imheight != self .rows :
219263 raise ValueError (
0 commit comments