Skip to content

Commit 73c0f74

Browse files
committed
pylint dupe fix: refactor pixlematrix and matrix_featherwing to use superclass
1 parent 10f56ed commit 73c0f74

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-FileCopyrightText: 2021 Tim Cocks for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`adafruit_featherwing.auto_writeable`
7+
====================================================
8+
9+
Superclass for the helpers pixelmatrix and matrix_featherwing
10+
11+
* Author(s): Tim Cocks
12+
"""
13+
14+
15+
class AutoWriteable:
16+
"""Superclass for matrix_featherwing and pixelmatrix."""
17+
18+
def __init__(self):
19+
self._auto_write = True
20+
21+
@property
22+
def auto_write(self):
23+
"""
24+
Whether or not we are automatically updating
25+
If set to false, be sure to call show() to update
26+
"""
27+
return self._auto_write
28+
29+
@auto_write.setter
30+
def auto_write(self, write):
31+
if isinstance(write, bool):
32+
self._auto_write = write

adafruit_featherwing/matrix_featherwing.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@
1818
import board
1919
import adafruit_ht16k33.matrix as matrix
2020

21+
from adafruit_featherwing.auto_writeable import AutoWriteable
2122

22-
class MatrixFeatherWing:
23+
24+
class MatrixFeatherWing(AutoWriteable):
2325
"""Class representing an `Adafruit 8x16 LED Matrix FeatherWing
2426
<https://www.adafruit.com/product/3155>`_.
2527
2628
Automatically uses the feather's I2C bus."""
2729

2830
def __init__(self, address=0x70, i2c=None):
31+
2932
if i2c is None:
3033
i2c = board.I2C()
3134
self._matrix = matrix.Matrix16x8(i2c, address)
3235
self._matrix.auto_write = False
3336
self.columns = 16
3437
self.rows = 8
35-
self._auto_write = True
38+
super().__init__()
3639

3740
def __getitem__(self, key):
3841
"""
@@ -125,19 +128,6 @@ def shift_down(self, rotate=False):
125128
self._matrix.shift_down(rotate)
126129
self._update()
127130

128-
@property
129-
def auto_write(self):
130-
"""
131-
Whether or not we are automatically updating
132-
If set to false, be sure to call show() to update
133-
"""
134-
return self._auto_write
135-
136-
@auto_write.setter
137-
def auto_write(self, write):
138-
if isinstance(write, bool):
139-
self._auto_write = write
140-
141131
@property
142132
def blink_rate(self):
143133
"""

adafruit_featherwing/pixelmatrix.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
1717

1818
# pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation
19+
from adafruit_featherwing.auto_writeable import AutoWriteable
1920

2021

21-
class PixelMatrix:
22+
class PixelMatrix(AutoWriteable):
2223
"""Base Class for DotStar and NeoPixel FeatherWings
2324
2425
The feather uses pins D13 and D11"""
@@ -27,7 +28,7 @@ def __init__(self):
2728
self.rows = 0
2829
self.columns = 0
2930
self._matrix = None
30-
self._auto_write = True
31+
super().__init__()
3132

3233
def __setitem__(self, indices, value):
3334
"""
@@ -158,19 +159,6 @@ def shift_down(self, rotate=False):
158159
self._matrix[(self.rows - 1) * self.columns + x] = last_pixel
159160
self._update()
160161

161-
@property
162-
def auto_write(self):
163-
"""
164-
Whether or not we are automatically updating
165-
If set to false, be sure to call show() to update
166-
"""
167-
return self._auto_write
168-
169-
@auto_write.setter
170-
def auto_write(self, write):
171-
if isinstance(write, bool):
172-
self._auto_write = write
173-
174162
@property
175163
def brightness(self):
176164
"""

0 commit comments

Comments
 (0)