5
5
`adafruit_matrixportal.graphics`
6
6
================================================================================
7
7
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.
9
9
10
10
* Author(s): Melissa LeBlanc-Williams
11
11
14
14
15
15
**Hardware:**
16
16
17
+ * `Adafruit MatrixPortal M4 <https://www.adafruit.com/product/4745>`_
17
18
* `Adafruit Metro M4 Express AirLift <https://www.adafruit.com/product/4000>`_
18
19
* `Adafruit RGB Matrix Shield <https://www.adafruit.com/product/2601>`_
19
20
* `64x32 RGB LED Matrix <https://www.adafruit.com/product/2278>`_
25
26
26
27
"""
27
28
28
- import gc
29
- import displayio
29
+ from adafruit_portalbase .graphics import GraphicsBase
30
30
from adafruit_matrixportal .matrix import Matrix
31
31
32
32
__version__ = "0.0.0-auto.0"
33
33
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal.git"
34
34
35
35
36
- class Graphics :
36
+ class Graphics ( GraphicsBase ) :
37
37
"""Graphics Helper Class for the MatrixPortal Library
38
38
39
39
:param default_bg: The path to your default background image file or a hex color.
@@ -48,7 +48,7 @@ class Graphics:
48
48
49
49
"""
50
50
51
- # pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
51
+ # pylint: disable=too-few-public-methods
52
52
def __init__ (
53
53
self ,
54
54
* ,
@@ -61,69 +61,12 @@ def __init__(
61
61
debug = False
62
62
):
63
63
64
- self ._debug = debug
65
64
matrix = Matrix (
66
65
bit_depth = bit_depth ,
67
66
width = width ,
68
67
height = height ,
69
68
alt_addr_pins = alt_addr_pins ,
70
69
color_order = color_order ,
71
70
)
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 )
0 commit comments