diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index b8aa8d6..9acec60 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -16,3 +16,4 @@ jobs: uses: adafruit/workflows-circuitpython-libs/release-gh@main with: github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} diff --git a/.gitignore b/.gitignore index 544ec4a..db3d538 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ _build # Virtual environment-specific files .env +.venv # MacOS-specific files *.DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e5fccc..70ade69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,21 +4,21 @@ repos: - repo: https://github.com/python/black - rev: 22.3.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: v0.14.0 + rev: v1.1.2 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.4.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.15.5 + rev: v2.17.4 hooks: - id: pylint name: pylint (library code) diff --git a/.pylintrc b/.pylintrc index 40208c3..f945e92 100644 --- a/.pylintrc +++ b/.pylintrc @@ -396,4 +396,4 @@ min-public-methods=1 # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=Exception +overgeneral-exceptions=builtins.Exception diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: diff --git a/adafruit_sharpmemorydisplay.py b/adafruit_sharpmemorydisplay.py index 526095c..2875f71 100644 --- a/adafruit_sharpmemorydisplay.py +++ b/adafruit_sharpmemorydisplay.py @@ -27,6 +27,17 @@ """ # pylint: enable=line-too-long +from __future__ import annotations + + +try: + # pylint: disable=unused-import + import typing + from busio import SPI + from digitalio import DigitalInOut + from circuitpython_typing.pil import Image +except ImportError: + pass import adafruit_framebuf from adafruit_bus_device.spi_device import SPIDevice @@ -45,7 +56,7 @@ _SHARPMEM_BIT_CLEAR = const(0x20) # in lsb -def reverse_bit(num): +def reverse_bit(num: int) -> int: """Turn an LSB byte to an MSB byte, and vice versa. Used for SPI as it is LSB for the SHARP, but 99% of SPI implementations are MSB only!""" result = 0 @@ -62,7 +73,15 @@ class SharpMemoryDisplay(adafruit_framebuf.FrameBuffer): # pylint: disable=too-many-instance-attributes,abstract-method - def __init__(self, spi, scs_pin, width, height, *, baudrate=2000000): + def __init__( + self, + spi: SPI, + scs_pin: DigitalInOut, + width: int, + height: int, + *, + baudrate=2000000, + ): scs_pin.switch_to_output(value=True) self.spi_device = SPIDevice( spi, scs_pin, cs_active_value=True, baudrate=baudrate @@ -78,13 +97,12 @@ def __init__(self, spi, scs_pin, width, height, *, baudrate=2000000): # Set the vcom bit to a defined state self._vcom = True - def show(self): + def show(self) -> None: """write out the frame buffer via SPI, we use MSB SPI only so some bit-swapping is required. """ with self.spi_device as spi: - image_buffer = bytearray() # toggle the VCOM bit self._buf[0] = _SHARPMEM_BIT_WRITECMD @@ -105,7 +123,7 @@ def show(self): image_buffer.extend(self._buf) spi.write(image_buffer) - def image(self, img): + def image(self, img: Image) -> None: """Set buffer to value of Python Imaging Library image. The image should be in 1 bit mode and a size equal to the display size.""" # determine our effective width/height, taking rotation into account diff --git a/docs/conf.py b/docs/conf.py index 8093484..bc1ce7e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,6 +17,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinxcontrib.jquery", "sphinx.ext.intersphinx", "sphinx.ext.napoleon", "sphinx.ext.todo", @@ -100,19 +101,9 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get("READTHEDOCS", None) == "True" - -if not on_rtd: # only import and set the theme if we're building docs locally - try: - import sphinx_rtd_theme - - html_theme = "sphinx_rtd_theme" - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] - except: - html_theme = "default" - html_theme_path = ["."] -else: - html_theme_path = ["."] +import sphinx_rtd_theme + +html_theme = "sphinx_rtd_theme" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, diff --git a/docs/requirements.txt b/docs/requirements.txt index 88e6733..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,4 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx +sphinxcontrib-jquery +sphinx-rtd-theme diff --git a/examples/sharpmemorydisplay_pillow_demo.py b/examples/sharpmemorydisplay_pillow_demo.py index edc007e..4201580 100644 --- a/examples/sharpmemorydisplay_pillow_demo.py +++ b/examples/sharpmemorydisplay_pillow_demo.py @@ -28,6 +28,7 @@ scs = digitalio.DigitalInOut(board.D6) # inverted chip select # display = adafruit_sharpmemorydisplay.SharpMemoryDisplay(spi, scs, 96, 96) +# display = adafruit_sharpmemorydisplay.SharpMemoryDisplay(spi, scs, 400, 240) display = adafruit_sharpmemorydisplay.SharpMemoryDisplay(spi, scs, 144, 168) # Clear display. @@ -56,7 +57,8 @@ # Draw Some Text text = "Hello World!" -(font_width, font_height) = font.getsize(text) +bbox = font.getbbox(text) +(font_width, font_height) = bbox[2] - bbox[0], bbox[3] - bbox[1] draw.text( (display.width // 2 - font_width // 2, display.height // 2 - font_height // 2), text,