From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Wed, 18 May 2022 00:32:31 +0000 (-0400) Subject: Merge branch 'adafruit:main' into dev/add-font-protocol X-Git-Tag: 0.10.2^2~3 X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka_Displayio.git/commitdiff_plain/5697c1261805044cd15a8e5343ca8872d341991f?hp=0517310e672707ee57c9cbc2ffab61252ca0fbff Merge branch 'adafruit:main' into dev/add-font-protocol --- diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 68b37c8..a37eb94 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/python/black - rev: 20.8b1 + rev: 22.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool diff --git a/_typing.py b/_typing.py deleted file mode 100644 index 85cb393..0000000 --- a/_typing.py +++ /dev/null @@ -1,37 +0,0 @@ -# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams -# -# SPDX-License-Identifier: MIT - -""" -`_typing` -================================================================================ - -Type aliases for Blinka - -**Software and Dependencies:** - -* Adafruit Blinka: - https://github.com/adafruit/Adafruit_Blinka/releases - -* Author(s): Melissa LeBlanc-Williams - -""" - -from typing import Union - -__version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_Blinka_Displayio.git" - - -WriteableBuffer = Union[ - bytearray, - memoryview, - # array.array, - # ulab.numpy.ndarray, - # rgbmatrix.RGBMatrix -] - -ReadableBuffer = Union[ - bytes, - WriteableBuffer, -] diff --git a/displayio/_display.py b/displayio/_display.py index 8038722..41d53d1 100644 --- a/displayio/_display.py +++ b/displayio/_display.py @@ -26,7 +26,7 @@ import digitalio from PIL import Image import numpy import microcontroller -import _typing +import circuitpython_typing from ._displaycore import _DisplayCore from ._displaybus import _DisplayBus from ._colorconverter import ColorConverter @@ -60,7 +60,7 @@ class Display: def __init__( self, display_bus: _DisplayBus, - init_sequence: _typing.ReadableBuffer, + init_sequence: circuitpython_typing.ReadableBuffer, *, width: int, height: int, @@ -289,7 +289,7 @@ class Display: def _refresh_display_area(self, rectangle): """Loop through dirty rectangles and redraw that area.""" img = self._buffer.convert("RGB").crop(astuple(rectangle)) - img = img.rotate(self._rotation, expand=True) + img = img.rotate(360 - self._rotation, expand=True) display_rectangle = self._apply_rotation(rectangle) img = img.crop(astuple(self._clip(display_rectangle))) @@ -367,8 +367,8 @@ class Display: return struct.pack(self._bounds_encoding, x, y) # pylint: disable=no-member def fill_row( - self, y: int, buffer: _typing.WriteableBuffer - ) -> _typing.WriteableBuffer: + self, y: int, buffer: circuitpython_typing.WriteableBuffer + ) -> circuitpython_typing.WriteableBuffer: """Extract the pixels from a single row""" for x in range(0, self._width): _rgb_565 = self._colorconverter.convert(self._buffer.getpixel((x, y))) diff --git a/displayio/_displaycore.py b/displayio/_displaycore.py index a68f666..afb92c8 100644 --- a/displayio/_displaycore.py +++ b/displayio/_displaycore.py @@ -23,7 +23,7 @@ __repo__ = "https://github.com/adafruit/Adafruit_Blinka_Displayio.git" from typing import Union -import _typing +import circuitpython_typing from paralleldisplay import ParallelBus from ._fourwire import FourWire from ._group import Group @@ -227,7 +227,10 @@ class _DisplayCore: self._current_group._in_group = False def fill_area( - self, area: Area, mask: _typing.WriteableBuffer, buffer: _typing.WriteableBuffer + self, + area: Area, + mask: circuitpython_typing.WriteableBuffer, + buffer: circuitpython_typing.WriteableBuffer, ) -> bool: # pylint: disable=protected-access """Call the current group's fill area function""" @@ -261,7 +264,10 @@ class _DisplayCore: return True def send( - self, data_type: int, chip_select: int, data: _typing.ReadableBuffer + self, + data_type: int, + chip_select: int, + data: circuitpython_typing.ReadableBuffer, ) -> None: """ Send the data to the current bus diff --git a/displayio/_epaperdisplay.py b/displayio/_epaperdisplay.py index 29f8a54..7e17fa9 100644 --- a/displayio/_epaperdisplay.py +++ b/displayio/_epaperdisplay.py @@ -19,7 +19,7 @@ displayio for Blinka from typing import Optional import microcontroller -import _typing +import circuitpython_typing from ._group import Group from ._displaybus import _DisplayBus @@ -42,8 +42,8 @@ class EPaperDisplay: def __init__( self, display_bus: _DisplayBus, - start_sequence: _typing.ReadableBuffer, - stop_sequence: _typing.ReadableBuffer, + start_sequence: circuitpython_typing.ReadableBuffer, + stop_sequence: circuitpython_typing.ReadableBuffer, *, width: int, height: int, @@ -84,8 +84,10 @@ class EPaperDisplay: :param display_bus: The bus that the display is connected to :type _DisplayBus: displayio.FourWire or displayio.ParallelBus - :param ~_typing.ReadableBuffer start_sequence: Byte-packed initialization sequence. - :param ~_typing.ReadableBuffer stop_sequence: Byte-packed initialization sequence. + :param ~circuitpython_typing.ReadableBuffer start_sequence: Byte-packed + initialization sequence. + :param ~circuitpython_typing.ReadableBuffer stop_sequence: Byte-packed + initialization sequence. :param int width: Width in pixels :param int height: Height in pixels :param int ram_width: RAM width in pixels diff --git a/displayio/_fourwire.py b/displayio/_fourwire.py index 0aae5da..7c8f7c5 100644 --- a/displayio/_fourwire.py +++ b/displayio/_fourwire.py @@ -22,7 +22,7 @@ from typing import Optional import digitalio import busio import microcontroller -import _typing +import circuitpython_typing from ._constants import ( CHIP_SELECT_TOGGLE_EVERY_BYTE, CHIP_SELECT_UNTOUCHED, @@ -93,7 +93,11 @@ class FourWire: time.sleep(0.001) def send( - self, command, data: _typing.ReadableBuffer, *, toggle_every_byte: bool = False + self, + command, + data: circuitpython_typing.ReadableBuffer, + *, + toggle_every_byte: bool = False, ) -> None: """ Sends the given command value followed by the full set of data. Display state, @@ -108,11 +112,16 @@ class FourWire: else CHIP_SELECT_UNTOUCHED ) self._begin_transaction() - self._send(DISPLAY_COMMAND, chip_select, command) + self._send(DISPLAY_COMMAND, chip_select, bytes([command])) self._send(DISPLAY_DATA, chip_select, data) self._end_transaction() - def _send(self, data_type: int, chip_select: int, data: _typing.ReadableBuffer): + def _send( + self, + data_type: int, + chip_select: int, + data: circuitpython_typing.ReadableBuffer, + ): self._dc.value = data_type == DISPLAY_DATA if chip_select == CHIP_SELECT_TOGGLE_EVERY_BYTE: for byte in data: diff --git a/displayio/_i2cdisplay.py b/displayio/_i2cdisplay.py index 421fd10..958ce1d 100644 --- a/displayio/_i2cdisplay.py +++ b/displayio/_i2cdisplay.py @@ -23,7 +23,7 @@ displayio for Blinka import time import busio import digitalio -import _typing +import circuitpython_typing from ._constants import CHIP_SELECT_UNTOUCHED, DISPLAY_COMMAND __version__ = "0.0.0-auto.0" @@ -76,7 +76,7 @@ class I2CDisplay: while not self._i2c.try_lock(): pass - def send(self, command: int, data: _typing.ReadableBuffer) -> None: + def send(self, command: int, data: circuitpython_typing.ReadableBuffer) -> None: """ Sends the given command value followed by the full set of data. Display state, such as vertical scroll, set via ``send`` may or may not be reset once the code is @@ -86,7 +86,12 @@ class I2CDisplay: self._send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, bytes([command] + data)) self._end_transaction() - def _send(self, data_type: int, chip_select: int, data: _typing.ReadableBuffer): + def _send( + self, + data_type: int, + chip_select: int, + data: circuitpython_typing.ReadableBuffer, + ): # pylint: disable=unused-argument if data_type == DISPLAY_COMMAND: n = len(data) diff --git a/displayio/_palette.py b/displayio/_palette.py index 8579bcb..c008c87 100644 --- a/displayio/_palette.py +++ b/displayio/_palette.py @@ -18,7 +18,7 @@ displayio for Blinka """ from typing import Optional, Union, Tuple -import _typing +import circuitpython_typing __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git" @@ -73,7 +73,7 @@ class Palette: def __setitem__( self, index: int, - value: Union[int, _typing.ReadableBuffer, Tuple[int, int, int]], + value: Union[int, circuitpython_typing.ReadableBuffer, Tuple[int, int, int]], ) -> None: """Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1. diff --git a/displayio/_tilegrid.py b/displayio/_tilegrid.py index 25b0c73..7fc9189 100644 --- a/displayio/_tilegrid.py +++ b/displayio/_tilegrid.py @@ -381,6 +381,42 @@ class TileGrid: """The pixel shader of the tilegrid.""" return self._pixel_shader + @pixel_shader.setter + def pixel_shader(self, new_pixel_shader: Union[ColorConverter, Palette]) -> None: + if not isinstance(new_pixel_shader, ColorConverter) and not isinstance( + new_pixel_shader, Palette + ): + raise TypeError( + "Unsupported Type: new_pixel_shader must be ColorConverter or Palette" + ) + + self._pixel_shader = new_pixel_shader + + @property + def bitmap(self) -> Union[Bitmap, OnDiskBitmap, Shape]: + """The Bitmap, OnDiskBitmap, or Shape that is assigned to this TileGrid""" + return self._bitmap + + @bitmap.setter + def bitmap(self, new_bitmap: Union[Bitmap, OnDiskBitmap, Shape]) -> None: + + if ( + not isinstance(new_bitmap, Bitmap) + and not isinstance(new_bitmap, OnDiskBitmap) + and not isinstance(new_bitmap, Shape) + ): + raise TypeError( + "Unsupported Type: new_bitmap must be Bitmap, OnDiskBitmap, or Shape" + ) + + if ( + new_bitmap.width != self.bitmap.width + or new_bitmap.height != self.bitmap.height + ): + raise ValueError("New bitmap must be same size as old bitmap") + + self._bitmap = new_bitmap + def _extract_and_check_index(self, index): if isinstance(index, (tuple, list)): x = index[0] @@ -408,3 +444,23 @@ class TileGrid: if not 0 <= value <= 255: raise ValueError("Tile value out of bounds") self._tiles[index] = value + + @property + def width(self) -> int: + """Width in tiles""" + return self._width + + @property + def height(self) -> int: + """Height in tiles""" + return self._height + + @property + def tile_width(self) -> int: + """Width of each tile in pixels""" + return self._tile_width + + @property + def tile_height(self) -> int: + """Height of each tile in pixels""" + return self._tile_height diff --git a/paralleldisplay.py b/paralleldisplay.py index b666121..0627418 100644 --- a/paralleldisplay.py +++ b/paralleldisplay.py @@ -18,7 +18,7 @@ paralleldisplay for Blinka """ import microcontroller -import _typing +import circuitpython_typing __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git" @@ -61,7 +61,7 @@ class ParallelBus: """ raise NotImplementedError("ParallelBus reset has not been implemented yet") - def send(self, command: int, data: _typing.ReadableBuffer) -> None: + def send(self, command: int, data: circuitpython_typing.ReadableBuffer) -> None: """Sends the given command value followed by the full set of data. Display state, such as vertical scroll, set via ``send`` may or may not be reset once the code is done. diff --git a/requirements.txt b/requirements.txt index 10356cb..0324ea8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,8 @@ # # SPDX-License-Identifier: Unlicense -Adafruit-Blinka +Adafruit-Blinka>=7.0.0 +adafruit-circuitpython-typing pillow +pillow>=6.0.0; python_version>'3.9' numpy diff --git a/setup.py b/setup.py index 64f2711..2e48252 100644 --- a/setup.py +++ b/setup.py @@ -14,9 +14,20 @@ from setuptools import setup, find_packages # To use a consistent encoding from codecs import open from os import path +import sys here = path.abspath(path.dirname(__file__)) +requirements = [ + "Adafruit-Blinka>=7.0.0", + "adafruit-circuitpython-typing", + "pillow", + "numpy", +] + +if sys.version_info > (3, 9): + requirements.append("pillow>=6.0.0") + # Get the long description from the README file with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() @@ -33,11 +44,7 @@ setup( # Author details author="Adafruit Industries", author_email="circuitpython@adafruit.com", - install_requires=[ - "Adafruit-Blinka", - "pillow", - "numpy", - ], + install_requires=requirements, # Choose your license license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers @@ -54,6 +61,6 @@ setup( keywords="adafruit blinka circuitpython micropython displayio lcd tft display pitft", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=["fontio", "terminalio", "paralleldisplay", "_typing"], + py_modules=["fontio", "terminalio", "paralleldisplay"], packages=["displayio"], )