Skip to content

Commit 76a0bf8

Browse files
committed
Adding type annotations
1 parent dc1cd60 commit 76a0bf8

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

adafruit_pixel_framebuf.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,24 @@
3838
"""
3939

4040
# imports
41+
try:
42+
from typing import Union
43+
44+
from adafruit_dotstar import DotStar
45+
from neopixel import NeoPixel
46+
except ImportError:
47+
pass
4148

42-
from micropython import const
4349
import adafruit_framebuf
4450
from adafruit_led_animation.grid import PixelGrid
51+
from micropython import const
4552

4653
__version__ = "0.0.0+auto.0"
4754
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Pixel_Framebuf.git"
4855

49-
HORIZONTAL = const(1)
50-
VERTICAL = const(2)
56+
HORIZONTAL: int = const(1)
57+
VERTICAL: int = const(2)
58+
5159

5260
# pylint: disable=too-many-function-args
5361
class PixelFramebuffer(adafruit_framebuf.FrameBuffer):
@@ -59,6 +67,7 @@ class PixelFramebuffer(adafruit_framebuf.FrameBuffer):
5967
:param width: Framebuffer width.
6068
:param height: Framebuffer height.
6169
:param orientation: Orientation of the strip pixels - HORIZONTAL (default) or VERTICAL.
70+
HORIZONTAL and VERTICAL are primitive integers created by micropython.const(x).
6271
:param alternating: Whether the strip alternates direction from row to row (default True).
6372
:param reverse_x: Whether the strip X origin is on the right side (default False).
6473
:param reverse_y: Whether the strip Y origin is on the bottom (default False).
@@ -70,17 +79,17 @@ class PixelFramebuffer(adafruit_framebuf.FrameBuffer):
7079

7180
def __init__(
7281
self,
73-
pixels,
74-
width,
75-
height,
76-
orientation=HORIZONTAL,
77-
alternating=True,
78-
reverse_x=False,
79-
reverse_y=False,
80-
top=0,
81-
bottom=0,
82-
rotation=0,
83-
): # pylint: disable=too-many-arguments
82+
pixels: Union[NeoPixel, DotStar],
83+
width: int,
84+
height: int,
85+
orientation: int = HORIZONTAL,
86+
alternating: bool = True,
87+
reverse_x: bool = False,
88+
reverse_y: bool = False,
89+
top: int = 0,
90+
bottom: int = 0,
91+
rotation: int = 0,
92+
) -> None: # pylint: disable=too-many-arguments
8493
self._width = width
8594
self._height = height
8695

@@ -98,26 +107,19 @@ def __init__(
98107

99108
self._buffer = bytearray(width * height * 3)
100109
self._double_buffer = bytearray(width * height * 3)
101-
super().__init__(
102-
self._buffer, width, height, buf_format=adafruit_framebuf.RGB888
103-
)
110+
super().__init__(self._buffer, width, height, buf_format=adafruit_framebuf.RGB888)
104111
self.rotation = rotation
105112

106-
def blit(self):
113+
def blit(self) -> None:
107114
"""blit is not yet implemented"""
108115
raise NotImplementedError()
109116

110-
def display(self):
117+
def display(self) -> None:
111118
"""Copy the raw buffer changes to the grid and show"""
112119
for _y in range(self._height):
113120
for _x in range(self._width):
114121
index = (_y * self.stride + _x) * 3
115-
if (
116-
self._buffer[index : index + 3]
117-
!= self._double_buffer[index : index + 3]
118-
):
122+
if self._buffer[index : index + 3] != self._double_buffer[index : index + 3]:
119123
self._grid[(_x, _y)] = tuple(self._buffer[index : index + 3])
120-
self._double_buffer[index : index + 3] = self._buffer[
121-
index : index + 3
122-
]
124+
self._double_buffer[index : index + 3] = self._buffer[index : index + 3]
123125
self._grid.show()

0 commit comments

Comments
 (0)