]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
Merge branch 'adafruit:main' into dev/add-font-protocol
authorAlec Delaney <89490472+tekktrik@users.noreply.github.com>
Wed, 18 May 2022 00:32:31 +0000 (20:32 -0400)
committerGitHub <noreply@github.com>
Wed, 18 May 2022 00:32:31 +0000 (20:32 -0400)
12 files changed:
.pre-commit-config.yaml
_typing.py [deleted file]
displayio/_display.py
displayio/_displaycore.py
displayio/_epaperdisplay.py
displayio/_fourwire.py
displayio/_i2cdisplay.py
displayio/_palette.py
displayio/_tilegrid.py
paralleldisplay.py
requirements.txt
setup.py

index 68b37c856c946521c83c52955856351782c749bc..a37eb9436327f883b49d1813bfc260c04f570e61 100644 (file)
@@ -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 (file)
index 85cb393..0000000
+++ /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,
-]
index 80387224811e04f4ba15edfa0282055506a2ad63..41d53d152971bbf149d57bd1c4caff5667a019ec 100644 (file)
@@ -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)))
index a68f6663c5a93a5e41ebd25197eedd6f9115e7ab..afb92c8eccedf3a5d5190ea05fd6c7c95419d622 100644 (file)
@@ -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
index 29f8a54d840e9f1d7d08dfb991abe82be3616905..7e17fa96ae523ea09b85574fb4d41c8c2ab7851f 100644 (file)
@@ -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
index 0aae5dad212a0239c5f26ae68414a05f13463b33..7c8f7c5edaeb45d725f2d75aee04c7ea2af5893c 100644 (file)
@@ -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:
index 421fd105c7d3024df692cd688b6d4deddc05e886..958ce1d97433d12391806aef701d56892f536acb 100644 (file)
@@ -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)
index 8579bcb14cc182c8feabf061d75b1601da047b53..c008c8755e50f8794252ebb7a625fa3e0ae8b862 100644 (file)
@@ -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.
index 25b0c73ce83e0434ab5b8b46a9f91a83663eacb9..7fc9189a4dcdca4b98dc0ddc0862e2554b1c809d 100644 (file)
@@ -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
index b666121126aa977e57ae0e35b0c188077c48c668..0627418233bc2b21527175aed809d93958b3e09c 100644 (file)
@@ -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.
index 10356cbe0bec80eada7351248dbe2a5f1907224c..0324ea8bcfa01a8058a09e5d42b70e383926eb3f 100644 (file)
@@ -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
index 64f2711459dca0bc4df98389a93962aded6eba64..2e48252ed3cddfd794272be564ba3d1d8224c3e7 100644 (file)
--- 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"],
 )