Skip to content

Ported over to use PortalBase #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions adafruit_matrixportal/fakerequests.py

This file was deleted.

71 changes: 7 additions & 64 deletions adafruit_matrixportal/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
`adafruit_matrixportal.graphics`
================================================================================

Helper library for the Adafruit RGB Matrix Shield + Metro M4 Airlift Lite.
Helper library for the MatrixPortal M4 or Adafruit RGB Matrix Shield + Metro M4 Airlift Lite.

* Author(s): Melissa LeBlanc-Williams

Expand All @@ -14,6 +14,7 @@

**Hardware:**

* `Adafruit MatrixPortal M4 <https://www.adafruit.com/product/4745>`_
* `Adafruit Metro M4 Express AirLift <https://www.adafruit.com/product/4000>`_
* `Adafruit RGB Matrix Shield <https://www.adafruit.com/product/2601>`_
* `64x32 RGB LED Matrix <https://www.adafruit.com/product/2278>`_
Expand All @@ -25,15 +26,14 @@

"""

import gc
import displayio
from adafruit_portalbase.graphics import GraphicsBase
from adafruit_matrixportal.matrix import Matrix

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


class Graphics:
class Graphics(GraphicsBase):
"""Graphics Helper Class for the MatrixPortal Library

:param default_bg: The path to your default background image file or a hex color.
Expand All @@ -48,7 +48,7 @@ class Graphics:

"""

# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
# pylint: disable=too-few-public-methods
def __init__(
self,
*,
Expand All @@ -61,69 +61,12 @@ def __init__(
debug=False
):

self._debug = debug
matrix = Matrix(
bit_depth=bit_depth,
width=width,
height=height,
alt_addr_pins=alt_addr_pins,
color_order=color_order,
)
self.display = matrix.display

if self._debug:
print("Init display")
self.splash = displayio.Group(max_size=15)

if self._debug:
print("Init background")
self._bg_group = displayio.Group(max_size=1)
self._bg_file = None
self._default_bg = default_bg
self.splash.append(self._bg_group)

# set the default background
self.set_background(self._default_bg)
self.display.show(self.splash)

gc.collect()

def set_background(self, file_or_color, position=None):
"""The background image to a bitmap file.

:param file_or_color: The filename of the chosen background image, or a hex color.

"""
print("Set background to ", file_or_color)
while self._bg_group:
self._bg_group.pop()

if not position:
position = (0, 0) # default in top corner

if not file_or_color:
return # we're done, no background desired
if self._bg_file:
self._bg_file.close()
if isinstance(file_or_color, str): # its a filenme:
self._bg_file = open(file_or_color, "rb")
background = displayio.OnDiskBitmap(self._bg_file)
self._bg_sprite = displayio.TileGrid(
background,
pixel_shader=displayio.ColorConverter(),
x=position[0],
y=position[1],
)
elif isinstance(file_or_color, int):
# Make a background color fill
color_bitmap = displayio.Bitmap(self.display.width, self.display.height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = file_or_color
self._bg_sprite = displayio.TileGrid(
color_bitmap, pixel_shader=color_palette, x=position[0], y=position[1],
)
else:
raise RuntimeError("Unknown type of background")
self._bg_group.append(self._bg_sprite)
self.display.refresh()
gc.collect()

super().__init__(matrix.display, default_bg=default_bg, debug=debug)
2 changes: 1 addition & 1 deletion adafruit_matrixportal/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
`adafruit_matrixportal.matrix`
================================================================================

Helper library for the Adafruit RGB Matrix Shield + Metro M4 Airlift Lite.
Helper library for the MatrixPortal M4 or Adafruit RGB Matrix Shield + Metro M4 Airlift Lite.

* Author(s): Melissa LeBlanc-Williams

Expand Down
Loading