Skip to content

Commit 885fb7e

Browse files
authored
Merge pull request #55 from makermelissa/master
Ported over to use PortalBase
2 parents 770a6cc + ebacf7e commit 885fb7e

File tree

8 files changed

+90
-890
lines changed

8 files changed

+90
-890
lines changed

adafruit_matrixportal/fakerequests.py

-49
This file was deleted.

adafruit_matrixportal/graphics.py

+7-64
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
`adafruit_matrixportal.graphics`
66
================================================================================
77
8-
Helper library for the Adafruit RGB Matrix Shield + Metro M4 Airlift Lite.
8+
Helper library for the MatrixPortal M4 or Adafruit RGB Matrix Shield + Metro M4 Airlift Lite.
99
1010
* Author(s): Melissa LeBlanc-Williams
1111
@@ -14,6 +14,7 @@
1414
1515
**Hardware:**
1616
17+
* `Adafruit MatrixPortal M4 <https://www.adafruit.com/product/4745>`_
1718
* `Adafruit Metro M4 Express AirLift <https://www.adafruit.com/product/4000>`_
1819
* `Adafruit RGB Matrix Shield <https://www.adafruit.com/product/2601>`_
1920
* `64x32 RGB LED Matrix <https://www.adafruit.com/product/2278>`_
@@ -25,15 +26,14 @@
2526
2627
"""
2728

28-
import gc
29-
import displayio
29+
from adafruit_portalbase.graphics import GraphicsBase
3030
from adafruit_matrixportal.matrix import Matrix
3131

3232
__version__ = "0.0.0-auto.0"
3333
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal.git"
3434

3535

36-
class Graphics:
36+
class Graphics(GraphicsBase):
3737
"""Graphics Helper Class for the MatrixPortal Library
3838
3939
:param default_bg: The path to your default background image file or a hex color.
@@ -48,7 +48,7 @@ class Graphics:
4848
4949
"""
5050

51-
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
51+
# pylint: disable=too-few-public-methods
5252
def __init__(
5353
self,
5454
*,
@@ -61,69 +61,12 @@ def __init__(
6161
debug=False
6262
):
6363

64-
self._debug = debug
6564
matrix = Matrix(
6665
bit_depth=bit_depth,
6766
width=width,
6867
height=height,
6968
alt_addr_pins=alt_addr_pins,
7069
color_order=color_order,
7170
)
72-
self.display = matrix.display
73-
74-
if self._debug:
75-
print("Init display")
76-
self.splash = displayio.Group(max_size=15)
77-
78-
if self._debug:
79-
print("Init background")
80-
self._bg_group = displayio.Group(max_size=1)
81-
self._bg_file = None
82-
self._default_bg = default_bg
83-
self.splash.append(self._bg_group)
84-
85-
# set the default background
86-
self.set_background(self._default_bg)
87-
self.display.show(self.splash)
88-
89-
gc.collect()
90-
91-
def set_background(self, file_or_color, position=None):
92-
"""The background image to a bitmap file.
93-
94-
:param file_or_color: The filename of the chosen background image, or a hex color.
95-
96-
"""
97-
print("Set background to ", file_or_color)
98-
while self._bg_group:
99-
self._bg_group.pop()
100-
101-
if not position:
102-
position = (0, 0) # default in top corner
103-
104-
if not file_or_color:
105-
return # we're done, no background desired
106-
if self._bg_file:
107-
self._bg_file.close()
108-
if isinstance(file_or_color, str): # its a filenme:
109-
self._bg_file = open(file_or_color, "rb")
110-
background = displayio.OnDiskBitmap(self._bg_file)
111-
self._bg_sprite = displayio.TileGrid(
112-
background,
113-
pixel_shader=displayio.ColorConverter(),
114-
x=position[0],
115-
y=position[1],
116-
)
117-
elif isinstance(file_or_color, int):
118-
# Make a background color fill
119-
color_bitmap = displayio.Bitmap(self.display.width, self.display.height, 1)
120-
color_palette = displayio.Palette(1)
121-
color_palette[0] = file_or_color
122-
self._bg_sprite = displayio.TileGrid(
123-
color_bitmap, pixel_shader=color_palette, x=position[0], y=position[1],
124-
)
125-
else:
126-
raise RuntimeError("Unknown type of background")
127-
self._bg_group.append(self._bg_sprite)
128-
self.display.refresh()
129-
gc.collect()
71+
72+
super().__init__(matrix.display, default_bg=default_bg, debug=debug)

adafruit_matrixportal/matrix.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
`adafruit_matrixportal.matrix`
66
================================================================================
77
8-
Helper library for the Adafruit RGB Matrix Shield + Metro M4 Airlift Lite.
8+
Helper library for the MatrixPortal M4 or Adafruit RGB Matrix Shield + Metro M4 Airlift Lite.
99
1010
* Author(s): Melissa LeBlanc-Williams
1111

0 commit comments

Comments
 (0)