3030__version__ = "0.0.0-auto.0"
3131__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"
3232
33+
3334class Matrix8x8 (HT16K33 ):
3435 """A single matrix."""
36+
3537 _columns = 8
3638 _rows = 8
3739
@@ -52,7 +54,7 @@ def __setitem__(self, key, value):
5254 x , y = key
5355 self .pixel (x , y , value )
5456
55- #pylint: disable=too-many-branches
57+ # pylint: disable=too-many-branches
5658 def shift (self , x , y , rotate = False ):
5759 """
5860 Shift pixels by x and y
@@ -61,28 +63,28 @@ def shift(self, x, y, rotate=False):
6163 """
6264 auto_write = self .auto_write
6365 self ._auto_write = False
64- if x > 0 : # Shift Right
66+ if x > 0 : # Shift Right
6567 for _ in range (x ):
6668 for row in range (0 , self .rows ):
6769 last_pixel = self [self .columns - 1 , row ] if rotate else 0
6870 for col in range (self .columns - 1 , 0 , - 1 ):
6971 self [col , row ] = self [col - 1 , row ]
7072 self [0 , row ] = last_pixel
71- elif x < 0 : # Shift Left
73+ elif x < 0 : # Shift Left
7274 for _ in range (- x ):
7375 for row in range (0 , self .rows ):
7476 last_pixel = self [0 , row ] if rotate else 0
7577 for col in range (0 , self .columns - 1 ):
7678 self [col , row ] = self [col + 1 , row ]
7779 self [self .columns - 1 , row ] = last_pixel
78- if y > 0 : # Shift Up
80+ if y > 0 : # Shift Up
7981 for _ in range (y ):
8082 for col in range (0 , self .columns ):
8183 last_pixel = self [col , self .rows - 1 ] if rotate else 0
8284 for row in range (self .rows - 1 , 0 , - 1 ):
8385 self [col , row ] = self [col , row - 1 ]
8486 self [col , 0 ] = last_pixel
85- elif y < 0 : # Shift Down
87+ elif y < 0 : # Shift Down
8688 for _ in range (- y ):
8789 for col in range (0 , self .columns ):
8890 last_pixel = self [col , 0 ] if rotate else 0
@@ -92,7 +94,8 @@ def shift(self, x, y, rotate=False):
9294 self ._auto_write = auto_write
9395 if auto_write :
9496 self .show ()
95- #pylint: enable=too-many-branches
97+
98+ # pylint: enable=too-many-branches
9699
97100 def shift_right (self , rotate = False ):
98101 """
@@ -131,12 +134,15 @@ def image(self, img):
131134 be in 1 bit mode and a size equal to the display size."""
132135 imwidth , imheight = img .size
133136 if imwidth != self .columns or imheight != self .rows :
134- raise ValueError ('Image must be same dimensions as display ({0}x{1}).' \
135- .format (self .columns , self .rows ))
137+ raise ValueError (
138+ "Image must be same dimensions as display ({0}x{1})." .format (
139+ self .columns , self .rows
140+ )
141+ )
136142 # Grab all the pixels from the image, faster than getpixel.
137- pixels = img .convert ('1' ).load ()
143+ pixels = img .convert ("1" ).load ()
138144 # Iterate through the pixels
139- for x in range (self .columns ): # yes this double loop is slow,
145+ for x in range (self .columns ): # yes this double loop is slow,
140146 for y in range (self .rows ): # but these displays are small!
141147 self .pixel (x , y , pixels [(x , y )])
142148 if self ._auto_write :
@@ -152,8 +158,10 @@ def rows(self):
152158 """Read-only property for number of rows"""
153159 return self ._rows
154160
161+
155162class Matrix16x8 (Matrix8x8 ):
156163 """The matrix wing."""
164+
157165 _columns = 16
158166
159167 def pixel (self , x , y , color = None ):
@@ -165,10 +173,12 @@ def pixel(self, x, y, color=None):
165173 if x >= 8 :
166174 x -= 8
167175 y += 8
168- return super ()._pixel (y , x , color )
176+ return super ()._pixel (y , x , color ) # pylint: disable=arguments-out-of-order
177+
169178
170179class MatrixBackpack16x8 (Matrix16x8 ):
171180 """A double matrix backpack."""
181+
172182 def pixel (self , x , y , color = None ):
173183 """Get or set the color of a given pixel."""
174184 if not 0 <= x <= 15 :
@@ -177,6 +187,7 @@ def pixel(self, x, y, color=None):
177187 return None
178188 return super ()._pixel (x , y , color )
179189
190+
180191class Matrix8x8x2 (Matrix8x8 ):
181192 """A bi-color matrix."""
182193
@@ -200,8 +211,8 @@ def pixel(self, x, y, color=None):
200211
201212 def fill (self , color ):
202213 """Fill the whole display with the given color."""
203- fill1 = 0xff if color & 0x01 else 0x00
204- fill2 = 0xff if color & 0x02 else 0x00
214+ fill1 = 0xFF if color & 0x01 else 0x00
215+ fill2 = 0xFF if color & 0x02 else 0x00
205216 for i in range (8 ):
206217 self ._set_buffer (i * 2 , fill1 )
207218 self ._set_buffer (i * 2 + 1 , fill2 )
@@ -213,12 +224,15 @@ def image(self, img):
213224 be a size equal to the display size."""
214225 imwidth , imheight = img .size
215226 if imwidth != self .columns or imheight != self .rows :
216- raise ValueError ('Image must be same dimensions as display ({0}x{1}).' \
217- .format (self .columns , self .rows ))
227+ raise ValueError (
228+ "Image must be same dimensions as display ({0}x{1})." .format (
229+ self .columns , self .rows
230+ )
231+ )
218232 # Grab all the pixels from the image, faster than getpixel.
219- pixels = img .convert (' RGB' ).load ()
233+ pixels = img .convert (" RGB" ).load ()
220234 # Iterate through the pixels
221- for x in range (self .columns ): # yes this double loop is slow,
235+ for x in range (self .columns ): # yes this double loop is slow,
222236 for y in range (self .rows ): # but these displays are small!
223237 if pixels [(x , y )] == (255 , 0 , 0 ):
224238 self .pixel (x , y , self .LED_RED )
0 commit comments