From 5c3cbde856414fda64a8a07b48327093ac577cb2 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 30 May 2019 21:13:08 -0700 Subject: [PATCH 001/137] Fixed example to work with CP 4 and fixed index out of range error --- adafruit_button.py | 2 +- examples/display_button_simpletest.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_button.py b/adafruit_button.py index 115fc66..50e5491 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -146,7 +146,7 @@ def label(self): @label.setter def label(self, newtext): - if self._label and (self.group[-1] == self._label): + if self._label and len(self.group) > 0 and (self.group[-1] == self._label): self.group.pop() self._label = None diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index 04fda4b..ace4679 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -37,8 +37,8 @@ color_palette[0] = 0x404040 bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, - position=(0, 0)) -print(bg_sprite.position) + x=0, y=0) +print(bg_sprite.x, bg_sprite.y) splash.append(bg_sprite) ########################################################################## From 00bd1cab0b7c047c06048837d1596c695e194ff1 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 30 May 2019 21:19:48 -0700 Subject: [PATCH 002/137] Removed len() from check --- adafruit_button.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_button.py b/adafruit_button.py index 50e5491..32cc0b9 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -146,7 +146,7 @@ def label(self): @label.setter def label(self, newtext): - if self._label and len(self.group) > 0 and (self.group[-1] == self._label): + if self._label and self.group and (self.group[-1] == self._label): self.group.pop() self._label = None From 3c8065b7bc921d83cfe5b2fffd3397c525b30ce3 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 12 Jul 2019 10:55:50 -0700 Subject: [PATCH 003/137] Improvements to Simple Test --- examples/display_button_simpletest.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index ace4679..2bb2999 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -19,7 +19,7 @@ for i, filename in enumerate(fonts): fonts[i] = cwd+"/fonts/"+filename print(fonts) -THE_FONT = "/fonts/Chicago-12.bdf" +THE_FONT = "/fonts/Arial-12.bdf" DISPLAY_STRING = "Button Text" # Make the display context @@ -74,29 +74,26 @@ buttons.append(button_3) # a roundrect -button_4 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, +button_4 = Button(x=BUTTON_MARGIN*2+BUTTON_WIDTH, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, width=BUTTON_WIDTH, height=BUTTON_HEIGHT, label="button4", label_font=font, style=Button.ROUNDRECT) buttons.append(button_4) # a shadowrect -button_5 = Button(x=BUTTON_MARGIN*2+BUTTON_WIDTH, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, +button_5 = Button(x=BUTTON_MARGIN*3+BUTTON_WIDTH*2, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, width=BUTTON_WIDTH, height=BUTTON_HEIGHT, label="button5", label_font=font, style=Button.SHADOWRECT) buttons.append(button_5) # a shadowroundrect -button_6 = Button(x=BUTTON_MARGIN*3+2*BUTTON_WIDTH, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, +button_6 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN*3+BUTTON_HEIGHT*2, width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button5", label_font=font, style=Button.SHADOWROUNDRECT) + label="button6", label_font=font, style=Button.SHADOWROUNDRECT) buttons.append(button_6) - - for b in buttons: splash.append(b.group) - while True: p = ts.touch_point if p: From dc7ef5d3a46c4a301fd9f802cb15c72dd8ad06d7 Mon Sep 17 00:00:00 2001 From: siddacious Date: Sun, 14 Jul 2019 18:04:56 -0700 Subject: [PATCH 004/137] Fixed typo in rtd path --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index a1c2b73..ccd2093 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ Introduction ============ -.. image:: https://readthedocs.org/projects/adafruit-circuitpython-display_button/badge/?version=latest - :target: https://circuitpython.readthedocs.io/projects/display_button/en/latest/ +.. image:: https://readthedocs.org/projects/adafruit-circuitpython-display-button/badge/?version=latest + :target: https://circuitpython.readthedocs.io/projects/display-button/en/latest/ :alt: Documentation Status .. image:: https://img.shields.io/discord/327254708534116352.svg From 5043a0956013b024a5e76c1f71e56043cbb55005 Mon Sep 17 00:00:00 2001 From: Jason Pecor <14111408+jpecor@users.noreply.github.com> Date: Mon, 12 Aug 2019 22:24:41 -0500 Subject: [PATCH 005/137] Update to fill/outline color check The current code doesn't draw the button if both fill and outline are 0x000000 (black). With the proposed change, if either the outline or the fill have been assigned any value, the check will pass. If fill and outline are both None, nothing will be drawn. --- adafruit_button.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_button.py b/adafruit_button.py index 32cc0b9..ba4f76e 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -111,8 +111,8 @@ def __init__(self, *, x, y, width, height, name=None, style=RECT, self.selected_fill = (~self.fill_color) & 0xFFFFFF if self.selected_outline is None and outline_color is not None: self.selected_outline = (~self.outline_color) & 0xFFFFFF - - if outline_color or fill_color: + + if (outline_color is not None) or (fill_color is not None): if style == Button.RECT: self.body = Rect(x, y, width, height, fill=self.fill_color, outline=self.outline_color) From d329cd4bdeb14467551f43a743eaeb21bb52e483 Mon Sep 17 00:00:00 2001 From: Jason Pecor <14111408+jpecor@users.noreply.github.com> Date: Tue, 13 Aug 2019 13:12:28 -0500 Subject: [PATCH 006/137] Update adafruit_button.py Removed extra spaces on line 114 --- adafruit_button.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_button.py b/adafruit_button.py index ba4f76e..f9d84ba 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -111,7 +111,7 @@ def __init__(self, *, x, y, width, height, name=None, style=RECT, self.selected_fill = (~self.fill_color) & 0xFFFFFF if self.selected_outline is None and outline_color is not None: self.selected_outline = (~self.outline_color) & 0xFFFFFF - + if (outline_color is not None) or (fill_color is not None): if style == Button.RECT: self.body = Rect(x, y, width, height, From a38e7cc057cc6f7763674eb6767478c728838bd2 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 3 Sep 2019 09:56:20 -0700 Subject: [PATCH 007/137] Changed button to subclass of Group --- adafruit_button.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/adafruit_button.py b/adafruit_button.py index f9d84ba..b325eaa 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -56,7 +56,7 @@ def _check_color(color): return color -class Button(): +class Button(displayio.Group): # pylint: disable=too-many-instance-attributes, too-many-locals """Helper class for creating UI buttons for ``displayio``. @@ -87,6 +87,7 @@ def __init__(self, *, x, y, width, height, name=None, style=RECT, label=None, label_font=None, label_color=0x0, selected_fill=None, selected_outline=None, selected_label=None): + super().__init__() self.x = x self.y = y self.width = width @@ -135,10 +136,6 @@ def __init__(self, *, x, y, width, height, name=None, style=RECT, self.label = label - # else: # ok just a bounding box - # self.bodyshape = displayio.Shape(width, height) - # self.group.append(self.bodyshape) - @property def label(self): """The text label of the button""" From 81e4da02e3da2d174c9ae1ebc5f31163802498ee Mon Sep 17 00:00:00 2001 From: dherrada Date: Sat, 4 Jan 2020 15:14:59 -0500 Subject: [PATCH 008/137] Moved repository from Travis to GitHub Actions --- .github/workflows/build.yml | 50 +++++++++++++++++++++ .github/workflows/release.yml | 81 +++++++++++++++++++++++++++++++++++ .gitignore | 1 - .travis.yml | 48 --------------------- README.rst | 4 +- 5 files changed, 133 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..66ce4db --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Translate Repo Name For Build Tools filename_prefix + id: repo-name + run: | + echo ::set-output name=repo-name::$( + echo ${{ github.repository }} | + awk -F '\/' '{ print tolower($2) }' | + tr '_' '-' + ) + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Versions + run: | + python3 --version + - name: Checkout Current Repo + uses: actions/checkout@v1 + with: + submodules: true + - name: Checkout tools repo + uses: actions/checkout@v2 + with: + repository: adafruit/actions-ci-circuitpython-libs + path: actions-ci + - name: Install deps + run: | + source actions-ci/install.sh + - name: Library version + run: git describe --dirty --always --tags + - name: PyLint + run: | + pylint $( find . -path './adafruit*.py' ) + ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) + - name: Build assets + run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Build docs + working-directory: docs + run: sphinx-build -E -W -b html . _build/html diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..18efb9c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Translate Repo Name For Build Tools filename_prefix + id: repo-name + run: | + echo ::set-output name=repo-name::$( + echo ${{ github.repository }} | + awk -F '\/' '{ print tolower($2) }' | + tr '_' '-' + ) + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Versions + run: | + python3 --version + - name: Checkout Current Repo + uses: actions/checkout@v1 + with: + submodules: true + - name: Checkout tools repo + uses: actions/checkout@v2 + with: + repository: adafruit/actions-ci-circuitpython-libs + path: actions-ci + - name: Install deps + run: | + source actions-ci/install.sh + - name: Build assets + run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Upload Release Assets + # the 'official' actions version does not yet support dynamically + # supplying asset names to upload. @csexton's version chosen based on + # discussion in the issue below, as its the simplest to implement and + # allows for selecting files with a pattern. + # https://github.com/actions/upload-release-asset/issues/4 + #uses: actions/upload-release-asset@v1.0.1 + uses: csexton/release-asset-action@master + with: + pattern: "bundles/*" + github-token: ${{ secrets.GITHUB_TOKEN }} + + upload-pypi: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Set up Python + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + env: + TWINE_USERNAME: ${{ secrets.pypi_username }} + TWINE_PASSWORD: ${{ secrets.pypi_password }} + run: | + python setup.py sdist + twine upload dist/* diff --git a/.gitignore b/.gitignore index 55f127b..c83f8b7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ __pycache__ _build *.pyc .env -build* bundles *.DS_Store .eggs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6a11ef3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,48 +0,0 @@ -# This is a common .travis.yml for generating library release zip files for -# CircuitPython library releases using circuitpython-build-tools. -# See https://github.com/adafruit/circuitpython-build-tools for detailed setup -# instructions. - -dist: xenial -language: python -python: - - "3.6" - -cache: - pip: true - -# TODO: if deployment to PyPi is desired, change 'DEPLOY_PYPI' to "true", -# or remove the env block entirely and remove the condition in the -# deploy block. -env: - - DEPLOY_PYPI="true" - -deploy: - - provider: releases - api_key: "$GITHUB_TOKEN" - file_glob: true - file: "$TRAVIS_BUILD_DIR/bundles/*" - skip_cleanup: true - overwrite: true - on: - tags: true - # TODO: Use 'travis encrypt --com -r adafruit/' to generate - # the encrypted password for adafruit-travis. Paste result below. - - provider: pypi - user: adafruit-travis - password: - secure: ZxsMZrdftjJBqxdW4fowdLWFR5ykdCawV6pQt1BwRO8Q+6PGRloGkpIBQ2tj9eX85YY8q5sBIhqNwODJ5od9/B7nbx3xTo8T79O5Nq//tv9zmZaQS/uqZo8fj9TaHpaq+MVH2aCRfepey9/OzVRRsIZW/nEpaHuDPow7UtaoGFij4VsZ66RoVm88J7Zer8/bVlOdYatmMpb8SOSRE8Hj6jx7F4ayVxF2hVdzd8wOxrKObDkEFZ9ym0xYKHMWdPehtbnCOo/rgm0jtutd8plrKnTm//qNFEp6CdRcLbCEL6cQoPOWzk47p7tGe42yHllquB//f2VqmGzep3+YverAAOrPG2XOxp2ypQFc0RL6KY6CpDqWAdfYh+/H5o74oxCvRVWyUyHZ2eTHrd6YKnwlhxDTk0+A7FwforEPODm/YGxoTrRXduiD+LR4xvPFaQISAyFjIOeCYA1Yyfz4ZTQgcpXwqAa4irLlfb3rdjWRZIRnhR6mQsd1nTqDaxXcqlbL/EIH8KKG0ZBIAXL7F73ajRblaVn2iHvYkrTDKQhR8yaIFBUgAoSXdCBY1TIg3/RWU/knRyQItEKiQHXgua+gVO95GT4a2Hf2yV4y3PoaXCSoAVF24hgnHN9WRIEpyVRHgcMJpH2bLnXmDnl8KPgEqZD586tQaCqZdIdKtNJhUbo= - on: - tags: true - condition: $DEPLOY_PYPI = "true" - -install: - - pip install -r requirements.txt - - pip install circuitpython-build-tools Sphinx sphinx-rtd-theme - - pip install --force-reinstall pylint==1.9.2 - -script: - - pylint adafruit_button.py - - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) - - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-display_button --library_location . - - cd docs && sphinx-build -E -W -b html . _build/html && cd .. diff --git a/README.rst b/README.rst index ccd2093..b57ab78 100644 --- a/README.rst +++ b/README.rst @@ -9,8 +9,8 @@ Introduction :target: https://discord.gg/nBQh6qu :alt: Discord -.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_Display_Button.svg?branch=master - :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_Display_Button +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Display_Button/workflows/Build%20CI/badge.svg + :target: https://github.com/adafruit/Adafruit_CircuitPython_Display_Button/actions :alt: Build Status UI Buttons for displayio From e28fefcd94d0bdb8b872780230fcd9b04b76aeae Mon Sep 17 00:00:00 2001 From: caternuson Date: Wed, 15 Jan 2020 17:24:21 -0800 Subject: [PATCH 009/137] update examples --- examples/display_button_customfont.py | 106 ++++++++++++++++++++++++ examples/display_button_simpletest.py | 115 ++++++-------------------- 2 files changed, 133 insertions(+), 88 deletions(-) create mode 100644 examples/display_button_customfont.py diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py new file mode 100644 index 0000000..2bb2999 --- /dev/null +++ b/examples/display_button_customfont.py @@ -0,0 +1,106 @@ +import os +import board +import displayio +from adafruit_bitmap_font import bitmap_font +from adafruit_button import Button +import adafruit_touchscreen + +# These pins are used as both analog and digital! XL, XR and YU must be analog +# and digital capable. YD just need to be digital +ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, + board.TOUCH_YD, board.TOUCH_YU, + calibration=((5200, 59000), (5800, 57000)), + size=(320, 240)) + +# the current working directory (where this file is) +cwd = ("/"+__file__).rsplit('/', 1)[0] +fonts = [file for file in os.listdir(cwd+"/fonts/") + if (file.endswith(".bdf") and not file.startswith("._"))] +for i, filename in enumerate(fonts): + fonts[i] = cwd+"/fonts/"+filename +print(fonts) +THE_FONT = "/fonts/Arial-12.bdf" +DISPLAY_STRING = "Button Text" + +# Make the display context +splash = displayio.Group(max_size=20) +board.DISPLAY.show(splash) +BUTTON_WIDTH = 80 +BUTTON_HEIGHT = 40 +BUTTON_MARGIN = 20 + +########################################################################## +# Make a background color fill + +color_bitmap = displayio.Bitmap(320, 240, 1) +color_palette = displayio.Palette(1) +color_palette[0] = 0x404040 +bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + x=0, y=0) +print(bg_sprite.x, bg_sprite.y) +splash.append(bg_sprite) + +########################################################################## + +# Load the font +font = bitmap_font.load_font(THE_FONT) + +buttons = [] +# Default button styling: +button_0 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN, + width=BUTTON_WIDTH, height=BUTTON_HEIGHT, + label="button0", label_font=font) +buttons.append(button_0) + +# a button with no indicators at all +button_1 = Button(x=BUTTON_MARGIN*2+BUTTON_WIDTH, y=BUTTON_MARGIN, + width=BUTTON_WIDTH, height=BUTTON_HEIGHT, + fill_color=None, outline_color=None) +buttons.append(button_1) + +# various colorings +button_2 = Button(x=BUTTON_MARGIN*3+2*BUTTON_WIDTH, y=BUTTON_MARGIN, + width=BUTTON_WIDTH, height=BUTTON_HEIGHT, + label="button2", label_font=font, label_color=0x0000FF, + fill_color=0x00FF00, outline_color=0xFF0000) +buttons.append(button_2) + +# Transparent button with text +button_3 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, + width=BUTTON_WIDTH, height=BUTTON_HEIGHT, + label="button3", label_font=font, label_color=0x0, + fill_color=None, outline_color=None) +buttons.append(button_3) + +# a roundrect +button_4 = Button(x=BUTTON_MARGIN*2+BUTTON_WIDTH, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, + width=BUTTON_WIDTH, height=BUTTON_HEIGHT, + label="button4", label_font=font, style=Button.ROUNDRECT) +buttons.append(button_4) + +# a shadowrect +button_5 = Button(x=BUTTON_MARGIN*3+BUTTON_WIDTH*2, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, + width=BUTTON_WIDTH, height=BUTTON_HEIGHT, + label="button5", label_font=font, style=Button.SHADOWRECT) +buttons.append(button_5) + +# a shadowroundrect +button_6 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN*3+BUTTON_HEIGHT*2, + width=BUTTON_WIDTH, height=BUTTON_HEIGHT, + label="button6", label_font=font, style=Button.SHADOWROUNDRECT) +buttons.append(button_6) + +for b in buttons: + splash.append(b.group) + +while True: + p = ts.touch_point + if p: + print(p) + for i, b in enumerate(buttons): + if b.contains(p): + print("Button %d pressed" % i) + b.selected = True + else: + b.selected = False diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index 2bb2999..4828188 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -1,106 +1,45 @@ -import os import board import displayio -from adafruit_bitmap_font import bitmap_font +import terminalio from adafruit_button import Button import adafruit_touchscreen -# These pins are used as both analog and digital! XL, XR and YU must be analog -# and digital capable. YD just need to be digital +#--| Button Config |------------------------------------------------- +BUTTON_X = 110 +BUTTON_Y = 95 +BUTTON_WIDTH = 100 +BUTTON_HEIGHT = 50 +BUTTON_STYLE = Button.ROUNDRECT +BUTTON_FILL_COLOR = 0x00FFFF +BUTTON_OUTLINE_COLOR = 0xFF00FF +BUTTON_LABEL = "HELLO WORLD" +BUTTON_LABEL_COLOR = 0x000000 +#--| Button Config |------------------------------------------------- + +# Setup touchscreen (PyPortal) ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), size=(320, 240)) -# the current working directory (where this file is) -cwd = ("/"+__file__).rsplit('/', 1)[0] -fonts = [file for file in os.listdir(cwd+"/fonts/") - if (file.endswith(".bdf") and not file.startswith("._"))] -for i, filename in enumerate(fonts): - fonts[i] = cwd+"/fonts/"+filename -print(fonts) -THE_FONT = "/fonts/Arial-12.bdf" -DISPLAY_STRING = "Button Text" - # Make the display context -splash = displayio.Group(max_size=20) +splash = displayio.Group() board.DISPLAY.show(splash) -BUTTON_WIDTH = 80 -BUTTON_HEIGHT = 40 -BUTTON_MARGIN = 20 - -########################################################################## -# Make a background color fill - -color_bitmap = displayio.Bitmap(320, 240, 1) -color_palette = displayio.Palette(1) -color_palette[0] = 0x404040 -bg_sprite = displayio.TileGrid(color_bitmap, - pixel_shader=color_palette, - x=0, y=0) -print(bg_sprite.x, bg_sprite.y) -splash.append(bg_sprite) - -########################################################################## - -# Load the font -font = bitmap_font.load_font(THE_FONT) - -buttons = [] -# Default button styling: -button_0 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button0", label_font=font) -buttons.append(button_0) - -# a button with no indicators at all -button_1 = Button(x=BUTTON_MARGIN*2+BUTTON_WIDTH, y=BUTTON_MARGIN, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - fill_color=None, outline_color=None) -buttons.append(button_1) - -# various colorings -button_2 = Button(x=BUTTON_MARGIN*3+2*BUTTON_WIDTH, y=BUTTON_MARGIN, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button2", label_font=font, label_color=0x0000FF, - fill_color=0x00FF00, outline_color=0xFF0000) -buttons.append(button_2) - -# Transparent button with text -button_3 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button3", label_font=font, label_color=0x0, - fill_color=None, outline_color=None) -buttons.append(button_3) - -# a roundrect -button_4 = Button(x=BUTTON_MARGIN*2+BUTTON_WIDTH, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button4", label_font=font, style=Button.ROUNDRECT) -buttons.append(button_4) - -# a shadowrect -button_5 = Button(x=BUTTON_MARGIN*3+BUTTON_WIDTH*2, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button5", label_font=font, style=Button.SHADOWRECT) -buttons.append(button_5) -# a shadowroundrect -button_6 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN*3+BUTTON_HEIGHT*2, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button6", label_font=font, style=Button.SHADOWROUNDRECT) -buttons.append(button_6) +# Make the button +button = Button(x=BUTTON_X, y=BUTTON_Y, + width=BUTTON_WIDTH, height=BUTTON_HEIGHT, style=BUTTON_STYLE, + fill_color=BUTTON_FILL_COLOR, outline_color=BUTTON_OUTLINE_COLOR, + label="HELLO WORLD", label_font=terminalio.FONT, label_color=BUTTON_LABEL_COLOR) -for b in buttons: - splash.append(b.group) +# Add button to the display context +splash.append(button.group) +# Loop and look for touches while True: p = ts.touch_point if p: - print(p) - for i, b in enumerate(buttons): - if b.contains(p): - print("Button %d pressed" % i) - b.selected = True - else: - b.selected = False + if button.contains(p): + button.selected = True + else: + button.selected = False From f1ac76f26f714557dab5478b7d410971c44ae69e Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 15 Mar 2020 09:12:03 -0500 Subject: [PATCH 010/137] update code of conduct --- CODE_OF_CONDUCT.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 8ee6e44..134d510 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -34,6 +34,8 @@ Examples of unacceptable behavior by participants include: * Excessive or unwelcome helping; answering outside the scope of the question asked * Trolling, insulting/derogatory comments, and personal or political attacks +* Promoting or spreading disinformation, lies, or conspiracy theories against + a person, group, organisation, project, or community * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission @@ -72,10 +74,10 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Helpers by tagging @community helpers. You may also send an -open message from any channel, or a direct message to @kattni#1507, -@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or -@Andon#8175. +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. From 2e3da9e7201be0601f591049aa54062e7fee5930 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Thu, 5 Mar 2020 22:06:59 -0600 Subject: [PATCH 011/137] update pylintrc for black Signed-off-by: sommersoft --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 039eaec..d8f0ee8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -52,7 +52,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From d0e0f18d16153753ce02926c3d8861ced74dd894 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 17 Mar 2020 17:11:05 -0500 Subject: [PATCH 012/137] update example file pylint Signed-off-by: sommersoft --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66ce4db..11ce574 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,7 @@ jobs: - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) + ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Build docs From 5a7fc279b5910b1ca1f6de7e6e387cb52d50a587 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Mon, 16 Mar 2020 21:12:48 -0500 Subject: [PATCH 013/137] update build.yml to pip install pylint black sphinx Signed-off-by: sommersoft --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11ce574..fff3aa9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,9 +34,13 @@ jobs: with: repository: adafruit/actions-ci-circuitpython-libs path: actions-ci - - name: Install deps + - name: Install dependencies + # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh + - name: Pip install pylint, black, & Sphinx + run: | + pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint From 41ed2ab594048221c440c22bf005fe5df3a4a7fb Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 20 Mar 2020 21:00:36 -0400 Subject: [PATCH 014/137] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_button.py | 87 +++++++++++++------ docs/conf.py | 112 ++++++++++++++----------- examples/display_button_customfont.py | 115 ++++++++++++++++++-------- examples/display_button_simpletest.py | 32 ++++--- examples/display_button_soundboard.py | 49 ++++++----- setup.py | 52 +++++------- 7 files changed, 281 insertions(+), 168 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_button.py b/adafruit_button.py index b325eaa..bfb119e 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -52,7 +52,7 @@ def _check_color(color): # if a tuple is supplied, convert it to a RGB number if isinstance(color, tuple): r, g, b = color - return int((r << 16) + (g << 8) + (b & 0xff)) + return int((r << 16) + (g << 8) + (b & 0xFF)) return color @@ -82,11 +82,24 @@ class Button(displayio.Group): SHADOWRECT = const(2) SHADOWROUNDRECT = const(3) - def __init__(self, *, x, y, width, height, name=None, style=RECT, - fill_color=0xFFFFFF, outline_color=0x0, - label=None, label_font=None, label_color=0x0, - selected_fill=None, selected_outline=None, - selected_label=None): + def __init__( + self, + *, + x, + y, + width, + height, + name=None, + style=RECT, + fill_color=0xFFFFFF, + outline_color=0x0, + label=None, + label_font=None, + label_color=0x0, + selected_fill=None, + selected_outline=None, + selected_label=None + ): super().__init__() self.x = x self.y = y @@ -115,21 +128,49 @@ def __init__(self, *, x, y, width, height, name=None, style=RECT, if (outline_color is not None) or (fill_color is not None): if style == Button.RECT: - self.body = Rect(x, y, width, height, - fill=self.fill_color, outline=self.outline_color) + self.body = Rect( + x, + y, + width, + height, + fill=self.fill_color, + outline=self.outline_color, + ) elif style == Button.ROUNDRECT: - self.body = RoundRect(x, y, width, height, r=10, - fill=self.fill_color, outline=self.outline_color) + self.body = RoundRect( + x, + y, + width, + height, + r=10, + fill=self.fill_color, + outline=self.outline_color, + ) elif style == Button.SHADOWRECT: - self.shadow = Rect(x + 2, y + 2, width - 2, height - 2, - fill=outline_color) - self.body = Rect(x, y, width - 2, height - 2, - fill=self.fill_color, outline=self.outline_color) + self.shadow = Rect( + x + 2, y + 2, width - 2, height - 2, fill=outline_color + ) + self.body = Rect( + x, + y, + width - 2, + height - 2, + fill=self.fill_color, + outline=self.outline_color, + ) elif style == Button.SHADOWROUNDRECT: - self.shadow = RoundRect(x + 2, y + 2, width - 2, height - 2, r=10, - fill=self.outline_color) - self.body = RoundRect(x, y, width - 2, height - 2, r=10, - fill=self.fill_color, outline=self.outline_color) + self.shadow = RoundRect( + x + 2, y + 2, width - 2, height - 2, r=10, fill=self.outline_color + ) + self.body = RoundRect( + x, + y, + width - 2, + height - 2, + r=10, + fill=self.fill_color, + outline=self.outline_color, + ) if self.shadow: self.group.append(self.shadow) self.group.append(self.body) @@ -148,7 +189,7 @@ def label(self, newtext): self._label = None if not newtext or (self._label_color is None): # no new text - return # nothing to do! + return # nothing to do! if not self._label_font: raise RuntimeError("Please provide label font") @@ -164,7 +205,6 @@ def label(self, newtext): if (self.selected_label is None) and (self._label_color is not None): self.selected_label = (~self._label_color) & 0xFFFFFF - @property def selected(self): """Selected inverts the colors.""" @@ -173,7 +213,7 @@ def selected(self): @selected.setter def selected(self, value): if value == self._selected: - return # bail now, nothing more to do + return # bail now, nothing more to do self._selected = value if self._selected: new_fill = self.selected_fill @@ -195,5 +235,6 @@ def contains(self, point): ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for determining that a button has been touched. """ - return (self.x <= point[0] <= self.x + self.width) and (self.y <= point[1] <= - self.y + self.height) + return (self.x <= point[0] <= self.x + self.width) and ( + self.y <= point[1] <= self.y + self.height + ) diff --git a/docs/conf.py b/docs/conf.py index 276f652..7741d74 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,10 +11,10 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.napoleon', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", ] # TODO: Please Read! @@ -23,29 +24,32 @@ autodoc_mock_imports = ["displayio", "adafruit_display_text", "adafruit_display_shapes"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit Display_Button Library' -copyright = u'2019 Limor Fried' -author = u'Limor Fried' +project = u"Adafruit Display_Button Library" +copyright = u"2019 Limor Fried" +author = u"Limor Fried" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -57,7 +61,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -69,7 +73,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -84,59 +88,62 @@ # 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' +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(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # 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, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitDisplay_buttonLibrarydoc' +htmlhelp_basename = "AdafruitDisplay_buttonLibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitDisplay_ButtonLibrary.tex', u'AdafruitDisplay_Button Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitDisplay_ButtonLibrary.tex", + u"AdafruitDisplay_Button Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -144,8 +151,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitDisplay_Buttonlibrary', u'Adafruit Display_Button Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitDisplay_Buttonlibrary", + u"Adafruit Display_Button Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -154,7 +166,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitDisplay_ButtonLibrary', u'Adafruit Display_Button Library Documentation', - author, 'AdafruitDisplay_ButtonLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitDisplay_ButtonLibrary", + u"Adafruit Display_Button Library Documentation", + author, + "AdafruitDisplay_ButtonLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index 2bb2999..1c6d5aa 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -7,17 +7,24 @@ # These pins are used as both analog and digital! XL, XR and YU must be analog # and digital capable. YD just need to be digital -ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, - board.TOUCH_YD, board.TOUCH_YU, - calibration=((5200, 59000), (5800, 57000)), - size=(320, 240)) +ts = adafruit_touchscreen.Touchscreen( + board.TOUCH_XL, + board.TOUCH_XR, + board.TOUCH_YD, + board.TOUCH_YU, + calibration=((5200, 59000), (5800, 57000)), + size=(320, 240), +) # the current working directory (where this file is) -cwd = ("/"+__file__).rsplit('/', 1)[0] -fonts = [file for file in os.listdir(cwd+"/fonts/") - if (file.endswith(".bdf") and not file.startswith("._"))] +cwd = ("/" + __file__).rsplit("/", 1)[0] +fonts = [ + file + for file in os.listdir(cwd + "/fonts/") + if (file.endswith(".bdf") and not file.startswith("._")) +] for i, filename in enumerate(fonts): - fonts[i] = cwd+"/fonts/"+filename + fonts[i] = cwd + "/fonts/" + filename print(fonts) THE_FONT = "/fonts/Arial-12.bdf" DISPLAY_STRING = "Button Text" @@ -35,9 +42,7 @@ color_bitmap = displayio.Bitmap(320, 240, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x404040 -bg_sprite = displayio.TileGrid(color_bitmap, - pixel_shader=color_palette, - x=0, y=0) +bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) print(bg_sprite.x, bg_sprite.y) splash.append(bg_sprite) @@ -48,47 +53,89 @@ buttons = [] # Default button styling: -button_0 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button0", label_font=font) +button_0 = Button( + x=BUTTON_MARGIN, + y=BUTTON_MARGIN, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="button0", + label_font=font, +) buttons.append(button_0) # a button with no indicators at all -button_1 = Button(x=BUTTON_MARGIN*2+BUTTON_WIDTH, y=BUTTON_MARGIN, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - fill_color=None, outline_color=None) +button_1 = Button( + x=BUTTON_MARGIN * 2 + BUTTON_WIDTH, + y=BUTTON_MARGIN, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + fill_color=None, + outline_color=None, +) buttons.append(button_1) # various colorings -button_2 = Button(x=BUTTON_MARGIN*3+2*BUTTON_WIDTH, y=BUTTON_MARGIN, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button2", label_font=font, label_color=0x0000FF, - fill_color=0x00FF00, outline_color=0xFF0000) +button_2 = Button( + x=BUTTON_MARGIN * 3 + 2 * BUTTON_WIDTH, + y=BUTTON_MARGIN, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="button2", + label_font=font, + label_color=0x0000FF, + fill_color=0x00FF00, + outline_color=0xFF0000, +) buttons.append(button_2) # Transparent button with text -button_3 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button3", label_font=font, label_color=0x0, - fill_color=None, outline_color=None) +button_3 = Button( + x=BUTTON_MARGIN, + y=BUTTON_MARGIN * 2 + BUTTON_HEIGHT, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="button3", + label_font=font, + label_color=0x0, + fill_color=None, + outline_color=None, +) buttons.append(button_3) # a roundrect -button_4 = Button(x=BUTTON_MARGIN*2+BUTTON_WIDTH, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button4", label_font=font, style=Button.ROUNDRECT) +button_4 = Button( + x=BUTTON_MARGIN * 2 + BUTTON_WIDTH, + y=BUTTON_MARGIN * 2 + BUTTON_HEIGHT, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="button4", + label_font=font, + style=Button.ROUNDRECT, +) buttons.append(button_4) # a shadowrect -button_5 = Button(x=BUTTON_MARGIN*3+BUTTON_WIDTH*2, y=BUTTON_MARGIN*2+BUTTON_HEIGHT, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button5", label_font=font, style=Button.SHADOWRECT) +button_5 = Button( + x=BUTTON_MARGIN * 3 + BUTTON_WIDTH * 2, + y=BUTTON_MARGIN * 2 + BUTTON_HEIGHT, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="button5", + label_font=font, + style=Button.SHADOWRECT, +) buttons.append(button_5) # a shadowroundrect -button_6 = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN*3+BUTTON_HEIGHT*2, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="button6", label_font=font, style=Button.SHADOWROUNDRECT) +button_6 = Button( + x=BUTTON_MARGIN, + y=BUTTON_MARGIN * 3 + BUTTON_HEIGHT * 2, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="button6", + label_font=font, + style=Button.SHADOWROUNDRECT, +) buttons.append(button_6) for b in buttons: diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index 4828188..4db6e28 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -4,7 +4,7 @@ from adafruit_button import Button import adafruit_touchscreen -#--| Button Config |------------------------------------------------- +# --| Button Config |------------------------------------------------- BUTTON_X = 110 BUTTON_Y = 95 BUTTON_WIDTH = 100 @@ -14,23 +14,35 @@ BUTTON_OUTLINE_COLOR = 0xFF00FF BUTTON_LABEL = "HELLO WORLD" BUTTON_LABEL_COLOR = 0x000000 -#--| Button Config |------------------------------------------------- +# --| Button Config |------------------------------------------------- # Setup touchscreen (PyPortal) -ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, - board.TOUCH_YD, board.TOUCH_YU, - calibration=((5200, 59000), (5800, 57000)), - size=(320, 240)) +ts = adafruit_touchscreen.Touchscreen( + board.TOUCH_XL, + board.TOUCH_XR, + board.TOUCH_YD, + board.TOUCH_YU, + calibration=((5200, 59000), (5800, 57000)), + size=(320, 240), +) # Make the display context splash = displayio.Group() board.DISPLAY.show(splash) # Make the button -button = Button(x=BUTTON_X, y=BUTTON_Y, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, style=BUTTON_STYLE, - fill_color=BUTTON_FILL_COLOR, outline_color=BUTTON_OUTLINE_COLOR, - label="HELLO WORLD", label_font=terminalio.FONT, label_color=BUTTON_LABEL_COLOR) +button = Button( + x=BUTTON_X, + y=BUTTON_Y, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + style=BUTTON_STYLE, + fill_color=BUTTON_FILL_COLOR, + outline_color=BUTTON_OUTLINE_COLOR, + label="HELLO WORLD", + label_font=terminalio.FONT, + label_color=BUTTON_LABEL_COLOR, +) # Add button to the display context splash.append(button.group) diff --git a/examples/display_button_soundboard.py b/examples/display_button_soundboard.py index 340b3ff..de2ec36 100644 --- a/examples/display_button_soundboard.py +++ b/examples/display_button_soundboard.py @@ -5,23 +5,23 @@ SHOW_BUTTONS = False # the current working directory (where this file is) -cwd = ("/"+__file__).rsplit('/', 1)[0] +cwd = ("/" + __file__).rsplit("/", 1)[0] # No internet use version of pyportal -pyportal = PyPortal(default_bg=cwd+"/button_background.bmp") +pyportal = PyPortal(default_bg=cwd + "/button_background.bmp") spots = [] -spots.append({'label': "1", 'pos': (10, 10), 'size': (60, 60), 'file': "01.wav"}) -spots.append({'label': "2", 'pos': (90, 10), 'size': (60, 60), 'file': "02.wav"}) -spots.append({'label': "3", 'pos': (170, 10), 'size': (60, 60), 'file': "03.wav"}) -spots.append({'label': "4", 'pos': (250, 10), 'size': (60, 60), 'file': "04.wav"}) -spots.append({'label': "5", 'pos': (10, 90), 'size': (60, 60), 'file': "05.wav"}) -spots.append({'label': "6", 'pos': (90, 90), 'size': (60, 60), 'file': "06.wav"}) -spots.append({'label': "7", 'pos': (170, 90), 'size': (60, 60), 'file': "07.wav"}) -spots.append({'label': "8", 'pos': (250, 90), 'size': (60, 60), 'file': "08.wav"}) -spots.append({'label': "9", 'pos': (10, 170), 'size': (60, 60), 'file': "09.wav"}) -spots.append({'label': "10", 'pos': (90, 170), 'size': (60, 60), 'file': "10.wav"}) -spots.append({'label': "11", 'pos': (170, 170), 'size': (60, 60), 'file': "11.wav"}) -spots.append({'label': "12", 'pos': (250, 170), 'size': (60, 60), 'file': "12.wav"}) +spots.append({"label": "1", "pos": (10, 10), "size": (60, 60), "file": "01.wav"}) +spots.append({"label": "2", "pos": (90, 10), "size": (60, 60), "file": "02.wav"}) +spots.append({"label": "3", "pos": (170, 10), "size": (60, 60), "file": "03.wav"}) +spots.append({"label": "4", "pos": (250, 10), "size": (60, 60), "file": "04.wav"}) +spots.append({"label": "5", "pos": (10, 90), "size": (60, 60), "file": "05.wav"}) +spots.append({"label": "6", "pos": (90, 90), "size": (60, 60), "file": "06.wav"}) +spots.append({"label": "7", "pos": (170, 90), "size": (60, 60), "file": "07.wav"}) +spots.append({"label": "8", "pos": (250, 90), "size": (60, 60), "file": "08.wav"}) +spots.append({"label": "9", "pos": (10, 170), "size": (60, 60), "file": "09.wav"}) +spots.append({"label": "10", "pos": (90, 170), "size": (60, 60), "file": "10.wav"}) +spots.append({"label": "11", "pos": (170, 170), "size": (60, 60), "file": "11.wav"}) +spots.append({"label": "12", "pos": (250, 170), "size": (60, 60), "file": "12.wav"}) buttons = [] for spot in spots: @@ -29,11 +29,17 @@ if SHOW_BUTTONS: fill = None outline = 0x00FF00 - button = Button(x=spot['pos'][0], y=spot['pos'][1], - width=spot['size'][0], height=spot['size'][1], - fill_color=fill, outline_color=outline, - label=spot['label'], label_color=None, - name=spot['file']) + button = Button( + x=spot["pos"][0], + y=spot["pos"][1], + width=spot["size"][0], + height=spot["size"][1], + fill_color=fill, + outline_color=outline, + label=spot["label"], + label_color=None, + name=spot["file"], + ) pyportal.splash.append(button.group) buttons.append(button) @@ -46,9 +52,8 @@ for b in buttons: if b.contains(p): print("Touched", b.name) - if currently_pressed != b: # don't restart if playing - pyportal.play_file(cwd + "/" + b.name, - wait_to_finish=False) + if currently_pressed != b: # don't restart if playing + pyportal.play_file(cwd + "/" + b.name, wait_to_finish=False) currently_pressed = b break else: diff --git a/setup.py b/setup.py index 0fab7fc..6d788de 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ """ from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -13,51 +14,40 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-display_button', - + name="adafruit-circuitpython-display_button", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='UI Buttons for displayio', + setup_requires=["setuptools_scm"], + description="UI Buttons for displayio", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_Display_Button', - + url="https://github.com/adafruit/Adafruit_CircuitPython_Display_Button", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=[ - 'Adafruit-Blinka' - ], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka"], # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit blinka circuitpython micropython display_button buttons UI', - + keywords="adafruit blinka circuitpython micropython display_button buttons UI", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=['adafruit_display_button'], + py_modules=["adafruit_display_button"], ) From 3c029d9b56283393bf04bdd41dd94b346df9a965 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 7 Apr 2020 15:02:31 -0500 Subject: [PATCH 015/137] build.yml: add black formatting check Signed-off-by: sommersoft --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1dad804..b6977a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,9 @@ jobs: pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags + - name: Check formatting + run: | + black --check --target-version=py35 . - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) From a40ffc502df55ffb91536a41bbe41faffc65e7c4 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 9 Apr 2020 17:32:19 -0400 Subject: [PATCH 016/137] Black reformatting with Python 3 target. --- docs/conf.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 7741d74..782fd9e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -38,18 +38,18 @@ master_doc = "index" # General information about the project. -project = u"Adafruit Display_Button Library" -copyright = u"2019 Limor Fried" -author = u"Limor Fried" +project = "Adafruit Display_Button Library" +copyright = "2019 Limor Fried" +author = "Limor Fried" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u"1.0" +version = "1.0" # The full version, including alpha/beta/rc tags. -release = u"1.0" +release = "1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -140,7 +140,7 @@ ( master_doc, "AdafruitDisplay_ButtonLibrary.tex", - u"AdafruitDisplay_Button Library Documentation", + "AdafruitDisplay_Button Library Documentation", author, "manual", ), @@ -154,7 +154,7 @@ ( master_doc, "AdafruitDisplay_Buttonlibrary", - u"Adafruit Display_Button Library Documentation", + "Adafruit Display_Button Library Documentation", [author], 1, ) @@ -169,7 +169,7 @@ ( master_doc, "AdafruitDisplay_ButtonLibrary", - u"Adafruit Display_Button Library Documentation", + "Adafruit Display_Button Library Documentation", author, "AdafruitDisplay_ButtonLibrary", "One line description of project.", From 54be3e55f36ce471296b82e8db9b225c9bfc129e Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 26 Jun 2020 15:54:03 -0700 Subject: [PATCH 017/137] Added displayio as dependency --- requirements.txt | 1 + setup.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index edf9394..f99129c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Adafruit-Blinka +adafruit-blinka-displayio diff --git a/setup.py b/setup.py index 6d788de..0963bf4 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ # Author details author="Adafruit Industries", author_email="circuitpython@adafruit.com", - install_requires=["Adafruit-Blinka"], + install_requires=["Adafruit-Blinka", "adafruit-blinka-displayio"], # Choose your license license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers @@ -49,5 +49,5 @@ # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=["adafruit_display_button"], + packages=["adafruit_display_button"], ) From 5ac649d6609df03f6d022e199eec71f39ad76feb Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Mon, 29 Jun 2020 08:12:31 -0700 Subject: [PATCH 018/137] Updated module name to correct one --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0963bf4..41b0ca4 100644 --- a/setup.py +++ b/setup.py @@ -49,5 +49,5 @@ # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - packages=["adafruit_display_button"], + py_modules=["adafruit_button"], ) From 4f49de16421c447c27b93dee7db8027e4cba4850 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 8 Jul 2020 16:49:04 -0400 Subject: [PATCH 019/137] Fixed discord invite link --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index b57ab78..6de19d7 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ Introduction :alt: Documentation Status .. image:: https://img.shields.io/discord/327254708534116352.svg - :target: https://discord.gg/nBQh6qu + :target: https://adafru.it/discord :alt: Discord .. image:: https://github.com/adafruit/Adafruit_CircuitPython_Display_Button/workflows/Build%20CI/badge.svg From 6842af4a48abdfd2c5e2d6e3bf76aa9ed444bb08 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Mon, 10 Aug 2020 14:45:28 -0500 Subject: [PATCH 020/137] use extended Group instead of property --- adafruit_button.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/adafruit_button.py b/adafruit_button.py index bfb119e..551e036 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -100,14 +100,13 @@ def __init__( selected_outline=None, selected_label=None ): - super().__init__() + super().__init__(x=x, y=y) self.x = x self.y = y self.width = width self.height = height self._font = label_font self._selected = False - self.group = displayio.Group() self.name = name self._label = label self.body = self.fill = self.shadow = None @@ -129,8 +128,8 @@ def __init__( if (outline_color is not None) or (fill_color is not None): if style == Button.RECT: self.body = Rect( - x, - y, + 0, + 0, width, height, fill=self.fill_color, @@ -138,8 +137,8 @@ def __init__( ) elif style == Button.ROUNDRECT: self.body = RoundRect( - x, - y, + 0, + 0, width, height, r=10, @@ -148,11 +147,11 @@ def __init__( ) elif style == Button.SHADOWRECT: self.shadow = Rect( - x + 2, y + 2, width - 2, height - 2, fill=outline_color + 0 + 2, 0 + 2, width - 2, height - 2, fill=outline_color ) self.body = Rect( - x, - y, + 0, + 0, width - 2, height - 2, fill=self.fill_color, @@ -160,11 +159,11 @@ def __init__( ) elif style == Button.SHADOWROUNDRECT: self.shadow = RoundRect( - x + 2, y + 2, width - 2, height - 2, r=10, fill=self.outline_color + 0 + 2, 0 + 2, width - 2, height - 2, r=10, fill=self.outline_color ) self.body = RoundRect( - x, - y, + 0, + 0, width - 2, height - 2, r=10, @@ -172,8 +171,8 @@ def __init__( outline=self.outline_color, ) if self.shadow: - self.group.append(self.shadow) - self.group.append(self.body) + self.append(self.shadow) + self.append(self.body) self.label = label @@ -184,8 +183,8 @@ def label(self): @label.setter def label(self, newtext): - if self._label and self.group and (self.group[-1] == self._label): - self.group.pop() + if self._label and self and (self[-1] == self._label): + self.pop() self._label = None if not newtext or (self._label_color is None): # no new text @@ -197,10 +196,10 @@ def label(self, newtext): dims = self._label.bounding_box if dims[2] >= self.width or dims[3] >= self.height: raise RuntimeError("Button not large enough for label") - self._label.x = self.x + (self.width - dims[2]) // 2 - self._label.y = self.y + self.height // 2 + self._label.x = 0 + (self.width - dims[2]) // 2 + self._label.y = 0 + self.height // 2 self._label.color = self._label_color - self.group.append(self._label) + self.append(self._label) if (self.selected_label is None) and (self._label_color is not None): self.selected_label = (~self._label_color) & 0xFFFFFF From 4ead3aaaaf69167a476eecad023dc2852ffff75d Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Tue, 11 Aug 2020 21:34:40 -0500 Subject: [PATCH 021/137] add group property for backward compatibility with warning --- adafruit_button.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/adafruit_button.py b/adafruit_button.py index 551e036..9af9866 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -229,6 +229,16 @@ def selected(self, value): if self._label is not None: self._label.color = new_label + @property + def group(self): + """Return self for compatibility with old API.""" + print( + "Warning: The group property is being deprecated. " + "User code should be updated to add the Button directly to the " + "Display or other Groups." + ) + return self + def contains(self, point): """Used to determine if a point is contained within a button. For example, ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for From dd266cbf2684f70ae5c8f60659e7df0e53cf3c23 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Tue, 11 Aug 2020 21:45:19 -0500 Subject: [PATCH 022/137] update example scripts to use new API for adding to other Groups --- examples/display_button_customfont.py | 2 +- examples/display_button_simpletest.py | 2 +- examples/display_button_soundboard.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index 1c6d5aa..bce7679 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -139,7 +139,7 @@ buttons.append(button_6) for b in buttons: - splash.append(b.group) + splash.append(b) while True: p = ts.touch_point diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index 4db6e28..0fe5a73 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -45,7 +45,7 @@ ) # Add button to the display context -splash.append(button.group) +splash.append(button) # Loop and look for touches while True: diff --git a/examples/display_button_soundboard.py b/examples/display_button_soundboard.py index de2ec36..06537d2 100644 --- a/examples/display_button_soundboard.py +++ b/examples/display_button_soundboard.py @@ -40,7 +40,7 @@ label_color=None, name=spot["file"], ) - pyportal.splash.append(button.group) + pyportal.splash.append(button) buttons.append(button) last_pressed = None From 4e495dffdf0b6b506931e5be22c8e5b26b637641 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Wed, 12 Aug 2020 23:00:54 -0500 Subject: [PATCH 023/137] remove unneeded zeros --- adafruit_button.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_button.py b/adafruit_button.py index 9af9866..de776ee 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -147,7 +147,7 @@ def __init__( ) elif style == Button.SHADOWRECT: self.shadow = Rect( - 0 + 2, 0 + 2, width - 2, height - 2, fill=outline_color + 2, 2, width - 2, height - 2, fill=outline_color ) self.body = Rect( 0, @@ -159,7 +159,7 @@ def __init__( ) elif style == Button.SHADOWROUNDRECT: self.shadow = RoundRect( - 0 + 2, 0 + 2, width - 2, height - 2, r=10, fill=self.outline_color + 2, 2, width - 2, height - 2, r=10, fill=self.outline_color ) self.body = RoundRect( 0, @@ -196,8 +196,8 @@ def label(self, newtext): dims = self._label.bounding_box if dims[2] >= self.width or dims[3] >= self.height: raise RuntimeError("Button not large enough for label") - self._label.x = 0 + (self.width - dims[2]) // 2 - self._label.y = 0 + self.height // 2 + self._label.x = (self.width - dims[2]) // 2 + self._label.y = self.height // 2 self._label.color = self._label_color self.append(self._label) From 8057dcf0de11c7207bc02f215233a3345be30622 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Wed, 12 Aug 2020 23:03:59 -0500 Subject: [PATCH 024/137] black format --- adafruit_button.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adafruit_button.py b/adafruit_button.py index de776ee..0a7bef4 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -146,9 +146,7 @@ def __init__( outline=self.outline_color, ) elif style == Button.SHADOWRECT: - self.shadow = Rect( - 2, 2, width - 2, height - 2, fill=outline_color - ) + self.shadow = Rect(2, 2, width - 2, height - 2, fill=outline_color) self.body = Rect( 0, 0, From 60813be5348f73bd739eba73128aabef1e3c2a14 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 15:06:44 -0500 Subject: [PATCH 025/137] Added pre-commit and SPDX copyright Signed-off-by: dherrada --- .github/workflows/build.yml | 28 ++++++++++++++++++++++++---- .github/workflows/release.yml | 4 ++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6977a9..59baa53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Build CI on: [pull_request, push] @@ -38,20 +42,36 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, black, & Sphinx + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - - name: Check formatting + - name: Pre-commit hooks run: | - black --check --target-version=py35 . + pre-commit run --all-files - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Archive bundles + uses: actions/upload-artifact@v2 + with: + name: bundles + path: ${{ github.workspace }}/bundles/ - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Build Python package + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + pip install --upgrade setuptools wheel twine readme_renderer testresources + python setup.py sdist + python setup.py bdist_wheel --universal + twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18efb9c..6d0015a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Release Actions on: From 363d63cc07a0b7a9ca274a975a2c0935ffb97a8e Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 16:06:47 -0500 Subject: [PATCH 026/137] Added pre-commit-config file Signed-off-by: dherrada --- .pre-commit-config.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..aab5f1c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +repos: +- repo: https://github.com/python/black + rev: stable + hooks: + - id: black +- repo: https://github.com/fsfe/reuse-tool + rev: latest + hooks: + - id: reuse +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace From bc9ff3cb0097144d236fd0695343d0ae73133aa7 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 13 Jan 2021 12:45:11 -0500 Subject: [PATCH 027/137] Ran pre-commit, added licenses --- .gitignore | 6 +- .pylintrc | 4 + .readthedocs.yml | 4 + CODE_OF_CONDUCT.md | 14 +- LICENSES/CC-BY-4.0.txt | 324 ++++++++++++++++++++++++++ LICENSES/MIT.txt | 19 ++ LICENSES/Unlicense.txt | 20 ++ README.rst.license | 3 + adafruit_button.py | 23 +- docs/_static/favicon.ico.license | 3 + docs/api.rst.license | 3 + docs/conf.py | 4 + docs/examples.rst.license | 3 + docs/index.rst.license | 3 + examples/display_button_customfont.py | 5 +- examples/display_button_simpletest.py | 5 +- examples/display_button_soundboard.py | 3 + requirements.txt | 4 + setup.py | 4 + 19 files changed, 427 insertions(+), 27 deletions(-) create mode 100644 LICENSES/CC-BY-4.0.txt create mode 100644 LICENSES/MIT.txt create mode 100644 LICENSES/Unlicense.txt create mode 100644 README.rst.license create mode 100644 docs/_static/favicon.ico.license create mode 100644 docs/api.rst.license create mode 100644 docs/examples.rst.license create mode 100644 docs/index.rst.license diff --git a/.gitignore b/.gitignore index c83f8b7..9647e71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + *.mpy .idea __pycache__ @@ -8,4 +12,4 @@ bundles *.DS_Store .eggs dist -**/*.egg-info \ No newline at end of file +**/*.egg-info diff --git a/.pylintrc b/.pylintrc index d8f0ee8..5c31f66 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + [MASTER] # A comma-separated list of package or module names from where C extensions may diff --git a/.readthedocs.yml b/.readthedocs.yml index f4243ad..ffa84c4 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + python: version: 3 requirements_file: requirements.txt diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 134d510..8a55c07 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,3 +1,9 @@ + + # Adafruit Community Code of Conduct ## Our Pledge @@ -43,7 +49,7 @@ Examples of unacceptable behavior by participants include: The goal of the standards and moderation guidelines outlined here is to build and maintain a respectful community. We ask that you don’t just aim to be -"technically unimpeachable", but rather try to be your best self. +"technically unimpeachable", but rather try to be your best self. We value many things beyond technical expertise, including collaboration and supporting others within our community. Providing a positive experience for @@ -74,9 +80,9 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Moderators by tagging @community moderators. You may -also send an open message from any channel, or a direct message to -@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. diff --git a/LICENSES/CC-BY-4.0.txt b/LICENSES/CC-BY-4.0.txt new file mode 100644 index 0000000..3f92dfc --- /dev/null +++ b/LICENSES/CC-BY-4.0.txt @@ -0,0 +1,324 @@ +Creative Commons Attribution 4.0 International Creative Commons Corporation +("Creative Commons") is not a law firm and does not provide legal services +or legal advice. Distribution of Creative Commons public licenses does not +create a lawyer-client or other relationship. Creative Commons makes its licenses +and related information available on an "as-is" basis. Creative Commons gives +no warranties regarding its licenses, any material licensed under their terms +and conditions, or any related information. Creative Commons disclaims all +liability for damages resulting from their use to the fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and conditions +that creators and other rights holders may use to share original works of +authorship and other material subject to copyright and certain other rights +specified in the public license below. The following considerations are for +informational purposes only, are not exhaustive, and do not form part of our +licenses. + +Considerations for licensors: Our public licenses are intended for use by +those authorized to give the public permission to use material in ways otherwise +restricted by copyright and certain other rights. Our licenses are irrevocable. +Licensors should read and understand the terms and conditions of the license +they choose before applying it. Licensors should also secure all rights necessary +before applying our licenses so that the public can reuse the material as +expected. Licensors should clearly mark any material not subject to the license. +This includes other CC-licensed material, or material used under an exception +or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors + +Considerations for the public: By using one of our public licenses, a licensor +grants the public permission to use the licensed material under specified +terms and conditions. If the licensor's permission is not necessary for any +reason–for example, because of any applicable exception or limitation to copyright–then +that use is not regulated by the license. Our licenses grant only permissions +under copyright and certain other rights that a licensor has authority to +grant. Use of the licensed material may still be restricted for other reasons, +including because others have copyright or other rights in the material. A +licensor may make special requests, such as asking that all changes be marked +or described. Although not required by our licenses, you are encouraged to +respect those requests where reasonable. More considerations for the public +: wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution +4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree to +be bound by the terms and conditions of this Creative Commons Attribution +4.0 International Public License ("Public License"). To the extent this Public +License may be interpreted as a contract, You are granted the Licensed Rights +in consideration of Your acceptance of these terms and conditions, and the +Licensor grants You such rights in consideration of benefits the Licensor +receives from making the Licensed Material available under these terms and +conditions. + +Section 1 – Definitions. + +a. Adapted Material means material subject to Copyright and Similar Rights +that is derived from or based upon the Licensed Material and in which the +Licensed Material is translated, altered, arranged, transformed, or otherwise +modified in a manner requiring permission under the Copyright and Similar +Rights held by the Licensor. For purposes of this Public License, where the +Licensed Material is a musical work, performance, or sound recording, Adapted +Material is always produced where the Licensed Material is synched in timed +relation with a moving image. + +b. Adapter's License means the license You apply to Your Copyright and Similar +Rights in Your contributions to Adapted Material in accordance with the terms +and conditions of this Public License. + +c. Copyright and Similar Rights means copyright and/or similar rights closely +related to copyright including, without limitation, performance, broadcast, +sound recording, and Sui Generis Database Rights, without regard to how the +rights are labeled or categorized. For purposes of this Public License, the +rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. + +d. Effective Technological Measures means those measures that, in the absence +of proper authority, may not be circumvented under laws fulfilling obligations +under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, +and/or similar international agreements. + +e. Exceptions and Limitations means fair use, fair dealing, and/or any other +exception or limitation to Copyright and Similar Rights that applies to Your +use of the Licensed Material. + +f. Licensed Material means the artistic or literary work, database, or other +material to which the Licensor applied this Public License. + +g. Licensed Rights means the rights granted to You subject to the terms and +conditions of this Public License, which are limited to all Copyright and +Similar Rights that apply to Your use of the Licensed Material and that the +Licensor has authority to license. + +h. Licensor means the individual(s) or entity(ies) granting rights under this +Public License. + +i. Share means to provide material to the public by any means or process that +requires permission under the Licensed Rights, such as reproduction, public +display, public performance, distribution, dissemination, communication, or +importation, and to make material available to the public including in ways +that members of the public may access the material from a place and at a time +individually chosen by them. + +j. Sui Generis Database Rights means rights other than copyright resulting +from Directive 96/9/EC of the European Parliament and of the Council of 11 +March 1996 on the legal protection of databases, as amended and/or succeeded, +as well as other essentially equivalent rights anywhere in the world. + +k. You means the individual or entity exercising the Licensed Rights under +this Public License. Your has a corresponding meaning. + +Section 2 – Scope. + + a. License grant. + +1. Subject to the terms and conditions of this Public License, the Licensor +hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, +irrevocable license to exercise the Licensed Rights in the Licensed Material +to: + + A. reproduce and Share the Licensed Material, in whole or in part; and + + B. produce, reproduce, and Share Adapted Material. + +2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions +and Limitations apply to Your use, this Public License does not apply, and +You do not need to comply with its terms and conditions. + + 3. Term. The term of this Public License is specified in Section 6(a). + +4. Media and formats; technical modifications allowed. The Licensor authorizes +You to exercise the Licensed Rights in all media and formats whether now known +or hereafter created, and to make technical modifications necessary to do +so. The Licensor waives and/or agrees not to assert any right or authority +to forbid You from making technical modifications necessary to exercise the +Licensed Rights, including technical modifications necessary to circumvent +Effective Technological Measures. For purposes of this Public License, simply +making modifications authorized by this Section 2(a)(4) never produces Adapted +Material. + + 5. Downstream recipients. + +A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed +Material automatically receives an offer from the Licensor to exercise the +Licensed Rights under the terms and conditions of this Public License. + +B. No downstream restrictions. You may not offer or impose any additional +or different terms or conditions on, or apply any Effective Technological +Measures to, the Licensed Material if doing so restricts exercise of the Licensed +Rights by any recipient of the Licensed Material. + +6. No endorsement. Nothing in this Public License constitutes or may be construed +as permission to assert or imply that You are, or that Your use of the Licensed +Material is, connected with, or sponsored, endorsed, or granted official status +by, the Licensor or others designated to receive attribution as provided in +Section 3(a)(1)(A)(i). + + b. Other rights. + +1. Moral rights, such as the right of integrity, are not licensed under this +Public License, nor are publicity, privacy, and/or other similar personality +rights; however, to the extent possible, the Licensor waives and/or agrees +not to assert any such rights held by the Licensor to the limited extent necessary +to allow You to exercise the Licensed Rights, but not otherwise. + +2. Patent and trademark rights are not licensed under this Public License. + +3. To the extent possible, the Licensor waives any right to collect royalties +from You for the exercise of the Licensed Rights, whether directly or through +a collecting society under any voluntary or waivable statutory or compulsory +licensing scheme. In all other cases the Licensor expressly reserves any right +to collect such royalties. + +Section 3 – License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the following +conditions. + + a. Attribution. + +1. If You Share the Licensed Material (including in modified form), You must: + +A. retain the following if it is supplied by the Licensor with the Licensed +Material: + +i. identification of the creator(s) of the Licensed Material and any others +designated to receive attribution, in any reasonable manner requested by the +Licensor (including by pseudonym if designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of warranties; + +v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; + +B. indicate if You modified the Licensed Material and retain an indication +of any previous modifications; and + +C. indicate the Licensed Material is licensed under this Public License, and +include the text of, or the URI or hyperlink to, this Public License. + +2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner +based on the medium, means, and context in which You Share the Licensed Material. +For example, it may be reasonable to satisfy the conditions by providing a +URI or hyperlink to a resource that includes the required information. + +3. If requested by the Licensor, You must remove any of the information required +by Section 3(a)(1)(A) to the extent reasonably practicable. + +4. If You Share Adapted Material You produce, the Adapter's License You apply +must not prevent recipients of the Adapted Material from complying with this +Public License. + +Section 4 – Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that apply to +Your use of the Licensed Material: + +a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, +reuse, reproduce, and Share all or a substantial portion of the contents of +the database; + +b. if You include all or a substantial portion of the database contents in +a database in which You have Sui Generis Database Rights, then the database +in which You have Sui Generis Database Rights (but not its individual contents) +is Adapted Material; and + +c. You must comply with the conditions in Section 3(a) if You Share all or +a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not replace +Your obligations under this Public License where the Licensed Rights include +other Copyright and Similar Rights. + +Section 5 – Disclaimer of Warranties and Limitation of Liability. + +a. Unless otherwise separately undertaken by the Licensor, to the extent possible, +the Licensor offers the Licensed Material as-is and as-available, and makes +no representations or warranties of any kind concerning the Licensed Material, +whether express, implied, statutory, or other. This includes, without limitation, +warranties of title, merchantability, fitness for a particular purpose, non-infringement, +absence of latent or other defects, accuracy, or the presence or absence of +errors, whether or not known or discoverable. Where disclaimers of warranties +are not allowed in full or in part, this disclaimer may not apply to You. + +b. To the extent possible, in no event will the Licensor be liable to You +on any legal theory (including, without limitation, negligence) or otherwise +for any direct, special, indirect, incidental, consequential, punitive, exemplary, +or other losses, costs, expenses, or damages arising out of this Public License +or use of the Licensed Material, even if the Licensor has been advised of +the possibility of such losses, costs, expenses, or damages. Where a limitation +of liability is not allowed in full or in part, this limitation may not apply +to You. + +c. The disclaimer of warranties and limitation of liability provided above +shall be interpreted in a manner that, to the extent possible, most closely +approximates an absolute disclaimer and waiver of all liability. + +Section 6 – Term and Termination. + +a. This Public License applies for the term of the Copyright and Similar Rights +licensed here. However, if You fail to comply with this Public License, then +Your rights under this Public License terminate automatically. + +b. Where Your right to use the Licensed Material has terminated under Section +6(a), it reinstates: + +1. automatically as of the date the violation is cured, provided it is cured +within 30 days of Your discovery of the violation; or + + 2. upon express reinstatement by the Licensor. + +c. For the avoidance of doubt, this Section 6(b) does not affect any right +the Licensor may have to seek remedies for Your violations of this Public +License. + +d. For the avoidance of doubt, the Licensor may also offer the Licensed Material +under separate terms or conditions or stop distributing the Licensed Material +at any time; however, doing so will not terminate this Public License. + + e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. + +Section 7 – Other Terms and Conditions. + +a. The Licensor shall not be bound by any additional or different terms or +conditions communicated by You unless expressly agreed. + +b. Any arrangements, understandings, or agreements regarding the Licensed +Material not stated herein are separate from and independent of the terms +and conditions of this Public License. + +Section 8 – Interpretation. + +a. For the avoidance of doubt, this Public License does not, and shall not +be interpreted to, reduce, limit, restrict, or impose conditions on any use +of the Licensed Material that could lawfully be made without permission under +this Public License. + +b. To the extent possible, if any provision of this Public License is deemed +unenforceable, it shall be automatically reformed to the minimum extent necessary +to make it enforceable. If the provision cannot be reformed, it shall be severed +from this Public License without affecting the enforceability of the remaining +terms and conditions. + +c. No term or condition of this Public License will be waived and no failure +to comply consented to unless expressly agreed to by the Licensor. + +d. Nothing in this Public License constitutes or may be interpreted as a limitation +upon, or waiver of, any privileges and immunities that apply to the Licensor +or You, including from the legal processes of any jurisdiction or authority. + +Creative Commons is not a party to its public licenses. Notwithstanding, Creative +Commons may elect to apply one of its public licenses to material it publishes +and in those instances will be considered the "Licensor." The text of the +Creative Commons public licenses is dedicated to the public domain under the +CC0 Public Domain Dedication. Except for the limited purpose of indicating +that material is shared under a Creative Commons public license or as otherwise +permitted by the Creative Commons policies published at creativecommons.org/policies, +Creative Commons does not authorize the use of the trademark "Creative Commons" +or any other trademark or logo of Creative Commons without its prior written +consent including, without limitation, in connection with any unauthorized +modifications to any of its public licenses or any other arrangements, understandings, +or agreements concerning use of licensed material. For the avoidance of doubt, +this paragraph does not form part of the public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..204b93d --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,19 @@ +MIT License Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 0000000..24a8f90 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,20 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute +this software, either in source code form or as a compiled binary, for any +purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and +to the detriment of our heirs and successors. We intend this dedication to +be an overt act of relinquishment in perpetuity of all present and future +rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH +THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, +please refer to diff --git a/README.rst.license b/README.rst.license new file mode 100644 index 0000000..11cd75d --- /dev/null +++ b/README.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/adafruit_button.py b/adafruit_button.py index 0a7bef4..8a85b43 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries # -# Copyright (c) 2019 Limor Fried for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + """ `adafruit_button` ================================================================================ diff --git a/docs/_static/favicon.ico.license b/docs/_static/favicon.ico.license new file mode 100644 index 0000000..86a3fbf --- /dev/null +++ b/docs/_static/favicon.ico.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries + +SPDX-License-Identifier: CC-BY-4.0 diff --git a/docs/api.rst.license b/docs/api.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/api.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/conf.py b/docs/conf.py index 782fd9e..886523a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + import os import sys diff --git a/docs/examples.rst.license b/docs/examples.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/examples.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/index.rst.license b/docs/index.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/index.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index bce7679..5c1d9b9 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -1,9 +1,12 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import os import board import displayio from adafruit_bitmap_font import bitmap_font -from adafruit_button import Button import adafruit_touchscreen +from adafruit_button import Button # These pins are used as both analog and digital! XL, XR and YU must be analog # and digital capable. YD just need to be digital diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index 0fe5a73..7375168 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -1,8 +1,11 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import board import displayio import terminalio -from adafruit_button import Button import adafruit_touchscreen +from adafruit_button import Button # --| Button Config |------------------------------------------------- BUTTON_X = 110 diff --git a/examples/display_button_soundboard.py b/examples/display_button_soundboard.py index 06537d2..9e56c5b 100644 --- a/examples/display_button_soundboard.py +++ b/examples/display_button_soundboard.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import time from adafruit_pyportal import PyPortal from adafruit_button import Button diff --git a/requirements.txt b/requirements.txt index f99129c..44cdfd8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + Adafruit-Blinka adafruit-blinka-displayio diff --git a/setup.py b/setup.py index 41b0ca4..868efe4 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + """A setuptools based setup module. See: From c389053c7eeb2471cbee800cf9b27ac1c70a6c47 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 23 Jan 2021 11:55:34 -0600 Subject: [PATCH 028/137] adding color properties --- adafruit_button.py | 95 ++++++++++++++++----- examples/display_button_color_properties.py | 80 +++++++++++++++++ 2 files changed, 156 insertions(+), 19 deletions(-) create mode 100644 examples/display_button_color_properties.py diff --git a/adafruit_button.py b/adafruit_button.py index 8a85b43..3a72546 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -94,19 +94,19 @@ def __init__( self._label = label self.body = self.fill = self.shadow = None - self.fill_color = _check_color(fill_color) - self.outline_color = _check_color(outline_color) + self._fill_color = _check_color(fill_color) + self._outline_color = _check_color(outline_color) self._label_color = label_color self._label_font = label_font # Selecting inverts the button colors! - self.selected_fill = _check_color(selected_fill) - self.selected_outline = _check_color(selected_outline) - self.selected_label = _check_color(selected_label) + self._selected_fill = _check_color(selected_fill) + self._selected_outline = _check_color(selected_outline) + self._selected_label = _check_color(selected_label) if self.selected_fill is None and fill_color is not None: - self.selected_fill = (~self.fill_color) & 0xFFFFFF + self.selected_fill = (~self._fill_color) & 0xFFFFFF if self.selected_outline is None and outline_color is not None: - self.selected_outline = (~self.outline_color) & 0xFFFFFF + self.selected_outline = (~self._outline_color) & 0xFFFFFF if (outline_color is not None) or (fill_color is not None): if style == Button.RECT: @@ -115,8 +115,8 @@ def __init__( 0, width, height, - fill=self.fill_color, - outline=self.outline_color, + fill=self._fill_color, + outline=self._outline_color, ) elif style == Button.ROUNDRECT: self.body = RoundRect( @@ -125,8 +125,8 @@ def __init__( width, height, r=10, - fill=self.fill_color, - outline=self.outline_color, + fill=self._fill_color, + outline=self._outline_color, ) elif style == Button.SHADOWRECT: self.shadow = Rect(2, 2, width - 2, height - 2, fill=outline_color) @@ -135,12 +135,12 @@ def __init__( 0, width - 2, height - 2, - fill=self.fill_color, - outline=self.outline_color, + fill=self._fill_color, + outline=self._outline_color, ) elif style == Button.SHADOWROUNDRECT: self.shadow = RoundRect( - 2, 2, width - 2, height - 2, r=10, fill=self.outline_color + 2, 2, width - 2, height - 2, r=10, fill=self._outline_color ) self.body = RoundRect( 0, @@ -148,8 +148,8 @@ def __init__( width - 2, height - 2, r=10, - fill=self.fill_color, - outline=self.outline_color, + fill=self._fill_color, + outline=self._outline_color, ) if self.shadow: self.append(self.shadow) @@ -200,10 +200,10 @@ def selected(self, value): new_out = self.selected_outline new_label = self.selected_label else: - new_fill = self.fill_color - new_out = self.outline_color + new_fill = self._fill_color + new_out = self._outline_color new_label = self._label_color - # update all relevant colros! + # update all relevant colors! if self.body is not None: self.body.fill = new_fill self.body.outline = new_out @@ -228,3 +228,60 @@ def contains(self, point): return (self.x <= point[0] <= self.x + self.width) and ( self.y <= point[1] <= self.y + self.height ) + + @property + def fill_color(self): + """The fill color of the button body""" + return self._fill_color + + @fill_color.setter + def fill_color(self, new_color): + self._fill_color = _check_color(new_color) + self.body.fill = self._fill_color + + @property + def outline_color(self): + """The outline color of the button body""" + return self._outline_color + + @outline_color.setter + def outline_color(self, new_color): + self._outline_color = _check_color(new_color) + self.body.outline = self._outline_color + + @property + def selected_fill(self): + """The fill color of the button body when selected""" + return self._selected_fill + + @selected_fill.setter + def selected_fill(self, new_color): + self._selected_fill = _check_color(new_color) + + @property + def selected_outline(self): + """The outline color of the button body when selected""" + return self._selected_outline + + @selected_outline.setter + def selected_outline(self, new_color): + self._selected_outline = _check_color(new_color) + + @property + def selected_label(self): + """The font color of the button when selected""" + return self._selected_label + + @selected_label.setter + def selected_label(self, new_color): + self._selected_label = _check_color(new_color) + + @property + def label_color(self): + """The font color of the button""" + return self._label_color + + @label_color.setter + def label_color(self, new_color): + self._label_color = _check_color(new_color) + self._label.color = self._label_color diff --git a/examples/display_button_color_properties.py b/examples/display_button_color_properties.py new file mode 100644 index 0000000..2e2fb20 --- /dev/null +++ b/examples/display_button_color_properties.py @@ -0,0 +1,80 @@ +# SPDX-FileCopyrightText: 2021 foamyguy for Adafruit Industries +# SPDX-License-Identifier: MIT + +""" +Basic example that illustrates how to set the various color options on the button using +properties after the button has been initialized. +""" + +import board +import displayio +import terminalio +import adafruit_touchscreen +from adafruit_button import Button + +# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.) +# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.) +# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus +display = board.DISPLAY + +# --| Button Config |------------------------------------------------- +BUTTON_X = 110 +BUTTON_Y = 95 +BUTTON_WIDTH = 100 +BUTTON_HEIGHT = 50 +BUTTON_STYLE = Button.ROUNDRECT +BUTTON_FILL_COLOR = 0xAA0000 +BUTTON_OUTLINE_COLOR = 0x0000FF +BUTTON_LABEL = "HELLO WORLD" +BUTTON_LABEL_COLOR = 0x000000 +# --| Button Config |------------------------------------------------- + +# Setup touchscreen (PyPortal) +ts = adafruit_touchscreen.Touchscreen( + board.TOUCH_XL, + board.TOUCH_XR, + board.TOUCH_YD, + board.TOUCH_YU, + calibration=((5200, 59000), (5800, 57000)), + size=(320, 240), +) + +# Make the display context +splash = displayio.Group() +display.show(splash) + +# Make the button +button = Button( + x=BUTTON_X, + y=BUTTON_Y, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + style=BUTTON_STYLE, + fill_color=BUTTON_FILL_COLOR, + outline_color=BUTTON_OUTLINE_COLOR, + label="HELLO WORLD", + label_font=terminalio.FONT, + label_color=BUTTON_LABEL_COLOR, +) + +button.fill_color = 0x00FF00 +button.outline_color = 0xFF0000 + +button.selected_fill = (0, 0, 255) +button.selected_outline = (255, 0, 0) + +button.label_color = 0xFF0000 +button.selected_label = 0x00FF00 + +# Add button to the display context +splash.append(button) + +# Loop and look for touches +while True: + p = ts.touch_point + if p: + if button.contains(p): + print(p) + button.selected = True + else: + button.selected = False From dcf63fabc2e6e14a245d359dfc8222ec271d8e38 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 24 Jan 2021 14:53:25 -0600 Subject: [PATCH 029/137] fix color changes with regards to selected --- adafruit_button.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/adafruit_button.py b/adafruit_button.py index 3a72546..187850d 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -237,7 +237,8 @@ def fill_color(self): @fill_color.setter def fill_color(self, new_color): self._fill_color = _check_color(new_color) - self.body.fill = self._fill_color + if not self.selected: + self.body.fill = self._fill_color @property def outline_color(self): @@ -247,7 +248,8 @@ def outline_color(self): @outline_color.setter def outline_color(self, new_color): self._outline_color = _check_color(new_color) - self.body.outline = self._outline_color + if not self.selected: + self.body.outline = self._outline_color @property def selected_fill(self): @@ -257,6 +259,8 @@ def selected_fill(self): @selected_fill.setter def selected_fill(self, new_color): self._selected_fill = _check_color(new_color) + if self.selected: + self.body.fill = self._selected_fill @property def selected_outline(self): @@ -266,6 +270,8 @@ def selected_outline(self): @selected_outline.setter def selected_outline(self, new_color): self._selected_outline = _check_color(new_color) + if self.selected: + self.body.outline = self._selected_outline @property def selected_label(self): From db17d149eb64fbb9933d595602f4d57861b25f34 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 31 Jan 2021 15:36:26 -0600 Subject: [PATCH 030/137] copyright name --- examples/display_button_color_properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/display_button_color_properties.py b/examples/display_button_color_properties.py index 2e2fb20..dee3591 100644 --- a/examples/display_button_color_properties.py +++ b/examples/display_button_color_properties.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 foamyguy for Adafruit Industries +# SPDX-FileCopyrightText: 2021 Tim Cocks for Adafruit Industries # SPDX-License-Identifier: MIT """ From 23c1549f32b5c75f74878669c3ceda61c5694525 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 31 Jan 2021 21:07:27 -0600 Subject: [PATCH 031/137] mutable size --- adafruit_button.py | 141 ++++++++++++++++++++++++++++++--------------- 1 file changed, 93 insertions(+), 48 deletions(-) diff --git a/adafruit_button.py b/adafruit_button.py index 187850d..9f085fa 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -58,8 +58,67 @@ class Button(displayio.Group): :param selected_fill: Inverts the fill color. :param selected_outline: Inverts the outline color. :param selected_label: Inverts the label color. - """ + + def _empty_self_group(self): + while len(self) > 0: + self.pop() + + def _create_body(self): + if (self.outline_color is not None) or (self.fill_color is not None): + if self.style == Button.RECT: + self.body = Rect( + 0, + 0, + self.width, + self.height, + fill=self._fill_color, + outline=self._outline_color, + ) + elif self.style == Button.ROUNDRECT: + self.body = RoundRect( + 0, + 0, + self.width, + self.height, + r=10, + fill=self._fill_color, + outline=self._outline_color, + ) + elif self.style == Button.SHADOWRECT: + self.shadow = Rect( + 2, 2, self.width - 2, self.height - 2, fill=self.outline_color + ) + self.body = Rect( + 0, + 0, + self.width - 2, + self.height - 2, + fill=self._fill_color, + outline=self._outline_color, + ) + elif self.style == Button.SHADOWROUNDRECT: + self.shadow = RoundRect( + 2, + 2, + self.width - 2, + self.height - 2, + r=10, + fill=self._outline_color, + ) + self.body = RoundRect( + 0, + 0, + self.width - 2, + self.height - 2, + r=10, + fill=self._fill_color, + outline=self._outline_color, + ) + if self.shadow: + self.append(self.shadow) + self.append(self.body) + RECT = const(0) ROUNDRECT = const(1) SHADOWRECT = const(2) @@ -86,13 +145,14 @@ def __init__( super().__init__(x=x, y=y) self.x = x self.y = y - self.width = width - self.height = height + self._width = width + self._height = height self._font = label_font self._selected = False self.name = name self._label = label self.body = self.fill = self.shadow = None + self.style = style self._fill_color = _check_color(fill_color) self._outline_color = _check_color(outline_color) @@ -108,51 +168,8 @@ def __init__( if self.selected_outline is None and outline_color is not None: self.selected_outline = (~self._outline_color) & 0xFFFFFF - if (outline_color is not None) or (fill_color is not None): - if style == Button.RECT: - self.body = Rect( - 0, - 0, - width, - height, - fill=self._fill_color, - outline=self._outline_color, - ) - elif style == Button.ROUNDRECT: - self.body = RoundRect( - 0, - 0, - width, - height, - r=10, - fill=self._fill_color, - outline=self._outline_color, - ) - elif style == Button.SHADOWRECT: - self.shadow = Rect(2, 2, width - 2, height - 2, fill=outline_color) - self.body = Rect( - 0, - 0, - width - 2, - height - 2, - fill=self._fill_color, - outline=self._outline_color, - ) - elif style == Button.SHADOWROUNDRECT: - self.shadow = RoundRect( - 2, 2, width - 2, height - 2, r=10, fill=self._outline_color - ) - self.body = RoundRect( - 0, - 0, - width - 2, - height - 2, - r=10, - fill=self._fill_color, - outline=self._outline_color, - ) - if self.shadow: - self.append(self.shadow) + self._create_body() + if self.body: self.append(self.body) self.label = label @@ -291,3 +308,31 @@ def label_color(self): def label_color(self, new_color): self._label_color = _check_color(new_color) self._label.color = self._label_color + + @property + def width(self): + """The width of the button""" + return self._width + + @width.setter + def width(self, new_width): + self._width = new_width + self._empty_self_group() + self._create_body() + if self.body: + self.append(self.body) + self.label = self.label + + @property + def height(self): + """The height of the button""" + return self._height + + @height.setter + def height(self, new_height): + self._height = new_height + self._empty_self_group() + self._create_body() + if self.body: + self.append(self.body) + self.label = self.label From 5256dcf372bddba80c0147c9cc03705460042081 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 8 Feb 2021 17:48:03 -0600 Subject: [PATCH 032/137] resize function --- adafruit_button.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/adafruit_button.py b/adafruit_button.py index 9f085fa..c7875c0 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -336,3 +336,16 @@ def height(self, new_height): if self.body: self.append(self.body) self.label = self.label + + def resize(self, new_width, new_height): + """Resize the button to the new width and height given + :param new_width int the desired width + :param new_height int the desired height + """ + self._width = new_width + self._height = new_height + self._empty_self_group() + self._create_body() + if self.body: + self.append(self.body) + self.label = self.label From 760084b7e970798c6b929d4778d7f84b742d121d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 8 Feb 2021 17:51:28 -0600 Subject: [PATCH 033/137] remove extra shape append --- adafruit_button.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_button.py b/adafruit_button.py index c7875c0..abd2389 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -117,7 +117,6 @@ def _create_body(self): ) if self.shadow: self.append(self.shadow) - self.append(self.body) RECT = const(0) ROUNDRECT = const(1) From 119f63871a0363f3ed4eded495575faab3753f8f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 8 Feb 2021 18:04:28 -0600 Subject: [PATCH 034/137] try to truncate text instead of raising error if button is not big enough --- adafruit_button.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/adafruit_button.py b/adafruit_button.py index abd2389..caf554b 100755 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -192,7 +192,13 @@ def label(self, newtext): self._label = Label(self._label_font, text=newtext) dims = self._label.bounding_box if dims[2] >= self.width or dims[3] >= self.height: - raise RuntimeError("Button not large enough for label") + while len(self._label.text) > 1 and ( + dims[2] >= self.width or dims[3] >= self.height + ): + self._label.text = "{}.".format(self._label.text[:-2]) + dims = self._label.bounding_box + if len(self._label.text) <= 1: + raise RuntimeError("Button not large enough for label") self._label.x = (self.width - dims[2]) // 2 self._label.y = self.height // 2 self._label.color = self._label_color From ed54a4190c9f3e3aea5ac6cfd188ed4eca2110e1 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Feb 2021 16:38:51 -0500 Subject: [PATCH 035/137] Hardcoded Black and REUSE versions Signed-off-by: dherrada --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aab5f1c..07f886c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,11 +4,11 @@ repos: - repo: https://github.com/python/black - rev: stable + rev: 20.8b1 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: latest + rev: v0.12.1 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks From 7bfc7b432372ac722aeba0d4de6a1b025bb6cc63 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Tue, 23 Feb 2021 08:53:22 -0600 Subject: [PATCH 036/137] Modify button response to drag outside of button event --- examples/display_button_simpletest.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index 7375168..8173a1e 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -42,7 +42,7 @@ style=BUTTON_STYLE, fill_color=BUTTON_FILL_COLOR, outline_color=BUTTON_OUTLINE_COLOR, - label="HELLO WORLD", + label=BUTTON_LABEL, label_font=terminalio.FONT, label_color=BUTTON_LABEL_COLOR, ) @@ -56,5 +56,7 @@ if p: if button.contains(p): button.selected = True + else: + button.selected = False # if touch is dragged outside of button else: - button.selected = False + button.selected = False # if touch is released From ef5e12bbd3cb91eec753cbcdb8422f0d07e5c9b0 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Tue, 23 Feb 2021 09:02:58 -0600 Subject: [PATCH 037/137] Updated doc-string, ran black --- examples/display_button_customfont.py | 3 +++ examples/display_button_simpletest.py | 7 +++++-- examples/display_button_soundboard.py | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index 5c1d9b9..5695881 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -1,5 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +""" +Button example with a custom font. +""" import os import board diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index 8173a1e..8d69268 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -1,5 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +""" +Simple button example. +""" import board import displayio @@ -57,6 +60,6 @@ if button.contains(p): button.selected = True else: - button.selected = False # if touch is dragged outside of button + button.selected = False # if touch is dragged outside of button else: - button.selected = False # if touch is released + button.selected = False # if touch is released diff --git a/examples/display_button_soundboard.py b/examples/display_button_soundboard.py index 9e56c5b..2fd0bad 100644 --- a/examples/display_button_soundboard.py +++ b/examples/display_button_soundboard.py @@ -1,5 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +""" +Soundboard example with buttons. +""" import time from adafruit_pyportal import PyPortal From 2bd90d4ad422d8ed7d6aa065c8aad0b1bdf259ed Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 2 Mar 2021 16:46:17 -0500 Subject: [PATCH 038/137] Removed pylint process from github workflow Signed-off-by: dherrada --- .github/workflows/build.yml | 8 ++------ .pre-commit-config.yaml | 15 +++++++++++++++ .pylintrc | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59baa53..621d5ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,18 +42,14 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit + - name: Pip install Sphinx, pre-commit run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks run: | pre-commit run --all-files - - name: PyLint - run: | - pylint $( find . -path './adafruit*.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Archive bundles diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 07f886c..354c761 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,18 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace +- repo: https://github.com/pycqa/pylint + rev: pylint-2.7.1 + hooks: + - id: pylint + name: pylint (library code) + types: [python] + exclude: "^(docs/|examples/|setup.py$)" +- repo: local + hooks: + - id: pylint_examples + name: pylint (examples code) + description: Run pylint rules on "examples/*.py" files + entry: /usr/bin/env bash -c + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + language: system diff --git a/.pylintrc b/.pylintrc index 5c31f66..9ed669e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -250,7 +250,7 @@ ignore-comments=yes ignore-docstrings=yes # Ignore imports when computing similarities. -ignore-imports=no +ignore-imports=yes # Minimum lines number of a similarity. min-similarity-lines=4 From cac21109de2c051e2d24c368bfc1c1d8dda742de Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 2 Mar 2021 17:17:50 -0500 Subject: [PATCH 039/137] Re-added pylint install to build.yml Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 621d5ef..3baf502 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,9 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install Sphinx, pre-commit + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks From 01f8f308091bff4254317fc04ea9e99c5da53647 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Tue, 23 Feb 2021 09:02:58 -0600 Subject: [PATCH 040/137] Updated doc-string, ran black --- examples/display_button_customfont.py | 3 +++ examples/display_button_simpletest.py | 7 +++++-- examples/display_button_soundboard.py | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index 5c1d9b9..5695881 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -1,5 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +""" +Button example with a custom font. +""" import os import board diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index 8173a1e..8d69268 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -1,5 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +""" +Simple button example. +""" import board import displayio @@ -57,6 +60,6 @@ if button.contains(p): button.selected = True else: - button.selected = False # if touch is dragged outside of button + button.selected = False # if touch is dragged outside of button else: - button.selected = False # if touch is released + button.selected = False # if touch is released diff --git a/examples/display_button_soundboard.py b/examples/display_button_soundboard.py index 9e56c5b..2fd0bad 100644 --- a/examples/display_button_soundboard.py +++ b/examples/display_button_soundboard.py @@ -1,5 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +""" +Soundboard example with buttons. +""" import time from adafruit_pyportal import PyPortal From f59ed60e973afefaeea059ffaec7ef8714f7418d Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 19 Mar 2021 13:46:06 -0400 Subject: [PATCH 041/137] "Increase duplicate code check threshold " --- .pylintrc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 9ed669e..0238b90 100644 --- a/.pylintrc +++ b/.pylintrc @@ -22,8 +22,7 @@ ignore-patterns= #init-hook= # Use multiple processes to speed up Pylint. -# jobs=1 -jobs=2 +jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. @@ -253,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=12 [BASIC] From debdae66d2b20901ae0f8696950e8e843c446d32 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 31 Mar 2021 21:55:29 -0400 Subject: [PATCH 042/137] Examples changes for dynamic width and height --- docs/examples.rst | 27 +++++++++++++++++++++ examples/display_button_color_properties.py | 2 +- examples/display_button_customfont.py | 8 +++--- examples/display_button_simpletest.py | 6 +++-- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index f734fd0..3960d39 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,30 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/display_button_simpletest.py :caption: examples/display_button_simpletest.py :linenos: + +Button Color Properties +----------------------- + +Demonstrate the different color possibilities present in the library + +.. literalinclude:: ../examples/display_button_color_properties.py + :caption: examples/display_button_color_properties.py + :linenos: + +Button Custom Font +------------------ + +Shows how to use different fonts with your button + +.. literalinclude:: ../examples/display_button_customfont.py + :caption: examples/display_button_customfont.py + :linenos: + +Soundboard +---------- + +A soundboard made with buttons + +.. literalinclude:: ../examples/display_button_soundboard.py + :caption: examples/display_button_soundboard.py + :linenos: diff --git a/examples/display_button_color_properties.py b/examples/display_button_color_properties.py index dee3591..2050ee3 100644 --- a/examples/display_button_color_properties.py +++ b/examples/display_button_color_properties.py @@ -36,7 +36,7 @@ board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), - size=(320, 240), + size=(display.width, display.height), ) # Make the display context diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index 5695881..00321b4 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -11,6 +11,8 @@ import adafruit_touchscreen from adafruit_button import Button +display = board.DISPLAY + # These pins are used as both analog and digital! XL, XR and YU must be analog # and digital capable. YD just need to be digital ts = adafruit_touchscreen.Touchscreen( @@ -19,7 +21,7 @@ board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), - size=(320, 240), + size=(display.width, display.height), ) # the current working directory (where this file is) @@ -37,7 +39,7 @@ # Make the display context splash = displayio.Group(max_size=20) -board.DISPLAY.show(splash) +display.show(splash) BUTTON_WIDTH = 80 BUTTON_HEIGHT = 40 BUTTON_MARGIN = 20 @@ -45,7 +47,7 @@ ########################################################################## # Make a background color fill -color_bitmap = displayio.Bitmap(320, 240, 1) +color_bitmap = displayio.Bitmap(display.width, display.height, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x404040 bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index 8d69268..c293bcd 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -10,6 +10,8 @@ import adafruit_touchscreen from adafruit_button import Button +display = board.DISPLAY + # --| Button Config |------------------------------------------------- BUTTON_X = 110 BUTTON_Y = 95 @@ -29,12 +31,12 @@ board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), - size=(320, 240), + size=(display.width, display.height), ) # Make the display context splash = displayio.Group() -board.DISPLAY.show(splash) +display.show(splash) # Make the button button = Button( From dd4fea43a45dbf355bf12b84d2ff35715d9cfe0d Mon Sep 17 00:00:00 2001 From: Adafruit Adabot Date: Sat, 3 Apr 2021 10:25:14 -0400 Subject: [PATCH 043/137] Adding MagTag to the list of displays --- examples/display_button_color_properties.py | 2 +- examples/display_button_customfont.py | 3 +++ examples/display_button_simpletest.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/display_button_color_properties.py b/examples/display_button_color_properties.py index 2050ee3..0ec1253 100644 --- a/examples/display_button_color_properties.py +++ b/examples/display_button_color_properties.py @@ -12,7 +12,7 @@ import adafruit_touchscreen from adafruit_button import Button -# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.) +# use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) # see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.) # https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus display = board.DISPLAY diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index 00321b4..15e2b5d 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -11,6 +11,9 @@ import adafruit_touchscreen from adafruit_button import Button +# use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) +# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.) +# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus display = board.DISPLAY # These pins are used as both analog and digital! XL, XR and YU must be analog diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index c293bcd..6b975a3 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -10,6 +10,9 @@ import adafruit_touchscreen from adafruit_button import Button +# use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) +# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.) +# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus display = board.DISPLAY # --| Button Config |------------------------------------------------- From ddcacd5c2aa9dcc430c3bf5050c0b38b86a9bdac Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 19 May 2021 13:32:42 -0400 Subject: [PATCH 044/137] Added pull request template Signed-off-by: dherrada --- .../adafruit_circuitpython_pr.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md new file mode 100644 index 0000000..71ef8f8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2021 Adafruit Industries +# +# SPDX-License-Identifier: MIT + +Thank you for contributing! Before you submit a pull request, please read the following. + +Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html + +If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs + +Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code + +Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. From fc1d921252f091336ed2e638a5bb37201a5a3f2d Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 19 May 2021 13:35:18 -0400 Subject: [PATCH 045/137] Added help text and problem matcher Signed-off-by: dherrada --- .github/workflows/build.yml | 2 ++ .github/workflows/failure-help-text.yml | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .github/workflows/failure-help-text.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3baf502..0ab7182 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,3 +71,5 @@ jobs: python setup.py sdist python setup.py bdist_wheel --universal twine check dist/* + - name: Setup problem matchers + uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/failure-help-text.yml b/.github/workflows/failure-help-text.yml new file mode 100644 index 0000000..0b1194f --- /dev/null +++ b/.github/workflows/failure-help-text.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Failure help text + +on: + workflow_run: + workflows: ["Build CI"] + types: + - completed + +jobs: + post-help: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} + steps: + - name: Post comment to help + uses: adafruit/circuitpython-action-library-ci-failed@v1 From 299c8ccf2b99877a2af9fce95c1a2952bb8f0db0 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 May 2021 09:54:31 -0400 Subject: [PATCH 046/137] Moved CI to Python 3.7 Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ab7182..c4c975d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.6 + - name: Set up Python 3.7 uses: actions/setup-python@v1 with: - python-version: 3.6 + python-version: 3.7 - name: Versions run: | python3 --version From 3e0c2918a67445be36d64864c68469eb3435e64f Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 7 Jun 2021 13:25:47 -0400 Subject: [PATCH 047/137] Moved default branch to main --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6de19d7..6384f2e 100644 --- a/README.rst +++ b/README.rst @@ -59,7 +59,7 @@ Contributing ============ Contributions are welcome! Please read our `Code of Conduct -`_ +`_ before contributing to help this project stay welcoming. Building locally From 9427cab3a24df71fe2d4bd5dc56ef4b7d9a155fc Mon Sep 17 00:00:00 2001 From: James Carr Date: Fri, 2 Jul 2021 12:47:04 +0100 Subject: [PATCH 048/137] Remove max_size parameter --- adafruit_button.py | 0 examples/display_button_customfont.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 adafruit_button.py diff --git a/adafruit_button.py b/adafruit_button.py old mode 100755 new mode 100644 diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index 15e2b5d..38ea90d 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -41,7 +41,7 @@ DISPLAY_STRING = "Button Text" # Make the display context -splash = displayio.Group(max_size=20) +splash = displayio.Group() display.show(splash) BUTTON_WIDTH = 80 BUTTON_HEIGHT = 40 From a8e6a6d79697aad04d7f0b49e6a134388ae5fa44 Mon Sep 17 00:00:00 2001 From: James Carr Date: Mon, 5 Jul 2021 12:55:26 +0100 Subject: [PATCH 049/137] Update the requirements for installation and docs building --- README.rst | 8 ++++---- docs/conf.py | 2 +- requirements.txt | 2 ++ setup.py | 7 ++++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 6384f2e..a4f04a1 100644 --- a/README.rst +++ b/README.rst @@ -29,17 +29,17 @@ This is easily achieved by downloading Installing from PyPI -------------------- On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from -PyPI `_. To install for current user: +PyPI `_. To install for current user: .. code-block:: shell - pip3 install adafruit-circuitpython-display_button + pip3 install adafruit-circuitpython-display-button To install system-wide (this may be required in some cases): .. code-block:: shell - sudo pip3 install adafruit-circuitpython-display_button + sudo pip3 install adafruit-circuitpython-display-button To install in a virtual environment in your current project: @@ -48,7 +48,7 @@ To install in a virtual environment in your current project: mkdir project-name && cd project-name python3 -m venv .env source .env/bin/activate - pip3 install adafruit-circuitpython-display_button + pip3 install adafruit-circuitpython-display-button Usage Example ============= diff --git a/docs/conf.py b/docs/conf.py index 886523a..f292151 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,7 @@ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -autodoc_mock_imports = ["displayio", "adafruit_display_text", "adafruit_display_shapes"] +autodoc_mock_imports = ["displayio"] intersphinx_mapping = { diff --git a/requirements.txt b/requirements.txt index 44cdfd8..14bda77 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,5 @@ Adafruit-Blinka adafruit-blinka-displayio +adafruit-circuitpython-display-text +adafruit-circuitpython-display-shapes diff --git a/setup.py b/setup.py index 868efe4..e709c6e 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,12 @@ # Author details author="Adafruit Industries", author_email="circuitpython@adafruit.com", - install_requires=["Adafruit-Blinka", "adafruit-blinka-displayio"], + install_requires=[ + "Adafruit-Blinka", + "adafruit-blinka-displayio", + "adafruit-circuitpython-display-text", + "adafruit-circuitpython-display-shapes", + ], # Choose your license license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers From aefa458e060a9487f284d3b173ea5ad97f9b2355 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 23 Sep 2021 17:52:55 -0400 Subject: [PATCH 050/137] Globally disabled consider-using-f-string pylint check Signed-off-by: dherrada --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 354c761..8810708 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,5 +30,5 @@ repos: name: pylint (examples code) description: Run pylint rules on "examples/*.py" files entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] language: system From e8b375c043225d2071661b731c9f52c1fcc7578d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 25 Oct 2021 11:27:35 -0500 Subject: [PATCH 051/137] add docs link to readme --- README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.rst b/README.rst index a4f04a1..3c66ff6 100644 --- a/README.rst +++ b/README.rst @@ -55,6 +55,11 @@ Usage Example See examples in examples/ folder. +Documentation +============= + +API documentation for this library can be found on `Read the Docs `_. + Contributing ============ From eebcb38df0dfeb51d10a66c8381ac05d9c64337e Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Nov 2021 14:40:16 -0400 Subject: [PATCH 052/137] PATCH Pylint and readthedocs patch test Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- .pre-commit-config.yaml | 26 +++++++++++++++++--------- .pylintrc | 2 +- .readthedocs.yml | 2 +- docs/requirements.txt | 5 +++++ 5 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 docs/requirements.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c4c975d..ca35544 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,9 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit + - name: Pip install Sphinx, pre-commit run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8810708..1b9fadc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,17 +18,25 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: pylint-2.7.1 + rev: v2.11.1 hooks: - id: pylint name: pylint (library code) types: [python] - exclude: "^(docs/|examples/|setup.py$)" -- repo: local - hooks: - - id: pylint_examples - name: pylint (examples code) + args: + - --disable=consider-using-f-string + exclude: "^(docs/|examples/|tests/|setup.py$)" + - id: pylint + name: pylint (example code) description: Run pylint rules on "examples/*.py" files - entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] - language: system + types: [python] + files: "^examples/" + args: + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint + name: pylint (test code) + description: Run pylint rules on "tests/*.py" files + types: [python] + files: "^tests/" + args: + - --disable=missing-docstring,consider-using-f-string,duplicate-code diff --git a/.pylintrc b/.pylintrc index 0238b90..e78bad2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=12 +min-similarity-lines=4 [BASIC] diff --git a/.readthedocs.yml b/.readthedocs.yml index ffa84c4..49dcab3 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -4,4 +4,4 @@ python: version: 3 -requirements_file: requirements.txt +requirements_file: docs/requirements.txt diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..88e6733 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +sphinx>=4.0.0 From 99c95416baec2c798f882e790269883b49a47116 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 5 Nov 2021 14:49:30 -0400 Subject: [PATCH 053/137] Disabled unspecified-encoding pylint check Signed-off-by: dherrada --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index e78bad2..cfd1c41 100644 --- a/.pylintrc +++ b/.pylintrc @@ -55,7 +55,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From dc64a85ba66cab8d27c61438d6ab34d8df486774 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 9 Nov 2021 13:31:14 -0500 Subject: [PATCH 054/137] Updated readthedocs file Signed-off-by: dherrada --- .readthedocs.yaml | 15 +++++++++++++++ .readthedocs.yml | 7 ------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .readthedocs.yaml delete mode 100644 .readthedocs.yml diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..95ec218 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +python: + version: "3.6" + install: + - requirements: docs/requirements.txt + - requirements: requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 49dcab3..0000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -python: - version: 3 -requirements_file: docs/requirements.txt From dea300c24de00775b50d03d771077c79f4c40cb8 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 23 Nov 2021 13:13:21 -0600 Subject: [PATCH 055/137] update rtd py version --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 95ec218..1335112 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.6" + version: "3.7" install: - requirements: docs/requirements.txt - requirements: requirements.txt From 3844c4eb0aa64f12d7810321087619faa1e3bbe8 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 13 Jan 2022 16:27:30 -0500 Subject: [PATCH 056/137] First part of patch Signed-off-by: dherrada --- .../PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md | 2 +- .github/workflows/build.yml | 6 +++--- .github/workflows/release.yml | 8 ++++---- .readthedocs.yaml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md index 71ef8f8..8de294e 100644 --- a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -4,7 +4,7 @@ Thank you for contributing! Before you submit a pull request, please read the following. -Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html +Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca35544..474520d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.7 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: "3.x" - name: Versions run: | python3 --version diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d0015a..a65e5de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,10 +24,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.6 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.6 + python-version: "3.x" - name: Versions run: | python3 --version @@ -67,7 +67,7 @@ jobs: echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) - name: Set up Python if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 1335112..f8b2891 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.7" + version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From d767d28e177184c7cfa7b14fd94bd2cb94998b98 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 20 Jan 2022 14:24:43 -0500 Subject: [PATCH 057/137] Fixed patch by adding bitmap font as requirement --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 14bda77..2f9e5aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ Adafruit-Blinka adafruit-blinka-displayio adafruit-circuitpython-display-text adafruit-circuitpython-display-shapes +adafruit-circuitpython-bitmap-font From b9e1caa61fc7a238fd1314efaf8f59f9ca16292d Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 Jan 2022 16:46:16 -0500 Subject: [PATCH 058/137] Updated docs link, updated python docs link, updated setup.py --- README.rst | 4 ++-- docs/conf.py | 4 ++-- docs/index.rst | 2 +- setup.py | 2 -- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 3c66ff6..107c191 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ Introduction ============ .. image:: https://readthedocs.org/projects/adafruit-circuitpython-display-button/badge/?version=latest - :target: https://circuitpython.readthedocs.io/projects/display-button/en/latest/ + :target: https://docs.circuitpython.org/projects/display-button/en/latest/ :alt: Documentation Status .. image:: https://img.shields.io/discord/327254708534116352.svg @@ -58,7 +58,7 @@ See examples in examples/ folder. Documentation ============= -API documentation for this library can be found on `Read the Docs `_. +API documentation for this library can be found on `Read the Docs `_. Contributing ============ diff --git a/docs/conf.py b/docs/conf.py index f292151..bc9bb77 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,8 +29,8 @@ intersphinx_mapping = { - "python": ("https://docs.python.org/3.4", None), - "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), + "python": ("https://docs.python.org/3", None), + "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), } # Add any paths that contain templates here, relative to this directory. diff --git a/docs/index.rst b/docs/index.rst index bf53505..d598087 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,7 +32,7 @@ Table of Contents :caption: Other Links Download - CircuitPython Reference Documentation + CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat Adafruit Learning System diff --git a/setup.py b/setup.py index e709c6e..8beeb54 100644 --- a/setup.py +++ b/setup.py @@ -49,8 +49,6 @@ "Topic :: System :: Hardware", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", ], # What does your project relate to? keywords="adafruit blinka circuitpython micropython display_button buttons UI", From 0b31708a0ad8f24aab914846627780aec18ada0d Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Thu, 10 Feb 2022 12:22:34 -0500 Subject: [PATCH 059/137] Post-patch cleanup Add link for info on building library documentation --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index 107c191..bd8bd34 100644 --- a/README.rst +++ b/README.rst @@ -60,6 +60,8 @@ Documentation API documentation for this library can be found on `Read the Docs `_. +For information on building library documentation, please check out `this guide `_. + Contributing ============ From 9dd7977b4dea95fbe52bf61fea34a0919bc86481 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 14 Feb 2022 15:35:02 -0500 Subject: [PATCH 060/137] Fixed readthedocs build Signed-off-by: dherrada --- .readthedocs.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index f8b2891..33c2a61 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,8 +8,12 @@ # Required version: 2 +build: + os: ubuntu-20.04 + tools: + python: "3" + python: - version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From bd97d5f37ba468a0c4af9a2f68d70f5df8e4de3c Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 28 Mar 2022 15:52:04 -0400 Subject: [PATCH 061/137] Update Black to latest. Signed-off-by: Kattni Rembor --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b9fadc..7467c1d 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 From 7141467784b21e3e771c3fed06d1b387e5d5e274 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Thu, 21 Apr 2022 15:00:27 -0400 Subject: [PATCH 062/137] Updated gitignore Signed-off-by: evaherrada --- .gitignore | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 9647e71..544ec4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,47 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT +# Do not include files and directories created by your personal work environment, such as the IDE +# you use, except for those already listed here. Pull requests including changes to this file will +# not be accepted. + +# This .gitignore file contains rules for files generated by working with CircuitPython libraries, +# including building Sphinx, testing with pip, and creating a virual environment, as well as the +# MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. + +# If you find that there are files being generated on your machine that should not be included in +# your git commit, you should create a .gitignore_global file on your computer to include the +# files created by your personal setup. To do so, follow the two steps below. + +# First, create a file called .gitignore_global somewhere convenient for you, and add rules for +# the files you want to exclude from git commits. + +# Second, configure Git to use the exclude file for all Git repositories by running the +# following via commandline, replacing "path/to/your/" with the actual path to your newly created +# .gitignore_global file: +# git config --global core.excludesfile path/to/your/.gitignore_global + +# CircuitPython-specific files *.mpy -.idea + +# Python-specific files __pycache__ -_build *.pyc + +# Sphinx build-specific files +_build + +# This file results from running `pip -e install .` in a local repository +*.egg-info + +# Virtual environment-specific files .env -bundles + +# MacOS-specific files *.DS_Store -.eggs -dist -**/*.egg-info + +# IDE-specific files +.idea +.vscode +*~ From 7d24e29ebd88f2fe4432060d201e04bff24485ab Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Apr 2022 15:58:33 -0400 Subject: [PATCH 063/137] Patch: Replaced discord badge image --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index bd8bd34..0dd6809 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Introduction :target: https://docs.circuitpython.org/projects/display-button/en/latest/ :alt: Documentation Status -.. image:: https://img.shields.io/discord/327254708534116352.svg +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From 91d285ec5b95208971ecffdd5b422d064a52f014 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 23 Apr 2022 12:38:54 -0500 Subject: [PATCH 064/137] adding sprite_button and refactoring to package instead of single file --- .pylintrc | 2 +- adafruit_button/__init__.py | 23 +++ .../button.py | 108 ++----------- adafruit_button/button_base.py | 152 ++++++++++++++++++ adafruit_button/sprite_button.py | 126 +++++++++++++++ setup.py | 2 +- 6 files changed, 320 insertions(+), 93 deletions(-) create mode 100644 adafruit_button/__init__.py rename adafruit_button.py => adafruit_button/button.py (73%) create mode 100644 adafruit_button/button_base.py create mode 100644 adafruit_button/sprite_button.py diff --git a/.pylintrc b/.pylintrc index cfd1c41..4abf2dc 100644 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=10 [BASIC] diff --git a/adafruit_button/__init__.py b/adafruit_button/__init__.py new file mode 100644 index 0000000..cd66773 --- /dev/null +++ b/adafruit_button/__init__.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_button.button` +================================================================================ + +UI Buttons for displayio + + +* Author(s): Limor Fried + +Implementation Notes +-------------------- + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" +from adafruit_button.button import Button diff --git a/adafruit_button.py b/adafruit_button/button.py similarity index 73% rename from adafruit_button.py rename to adafruit_button/button.py index caf554b..dc9fd7a 100644 --- a/adafruit_button.py +++ b/adafruit_button/button.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: MIT """ -`adafruit_button` +`adafruit_button.button` ================================================================================ UI Buttons for displayio @@ -22,24 +22,15 @@ """ from micropython import const -import displayio -from adafruit_display_text.label import Label from adafruit_display_shapes.rect import Rect from adafruit_display_shapes.roundrect import RoundRect +from adafruit_button.button_base import ButtonBase, _check_color __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Button.git" -def _check_color(color): - # if a tuple is supplied, convert it to a RGB number - if isinstance(color, tuple): - r, g, b = color - return int((r << 16) + (g << 8) + (b & 0xFF)) - return color - - -class Button(displayio.Group): +class Button(ButtonBase): # pylint: disable=too-many-instance-attributes, too-many-locals """Helper class for creating UI buttons for ``displayio``. @@ -141,26 +132,27 @@ def __init__( selected_outline=None, selected_label=None ): - super().__init__(x=x, y=y) - self.x = x - self.y = y - self._width = width - self._height = height - self._font = label_font - self._selected = False - self.name = name - self._label = label + super().__init__( + x=x, + y=y, + width=width, + height=height, + name=name, + label=label, + label_font=label_font, + label_color=label_color, + selected_label=selected_label, + ) + self.body = self.fill = self.shadow = None self.style = style self._fill_color = _check_color(fill_color) self._outline_color = _check_color(outline_color) - self._label_color = label_color - self._label_font = label_font + # Selecting inverts the button colors! self._selected_fill = _check_color(selected_fill) self._selected_outline = _check_color(selected_outline) - self._selected_label = _check_color(selected_label) if self.selected_fill is None and fill_color is not None: self.selected_fill = (~self._fill_color) & 0xFFFFFF @@ -173,64 +165,17 @@ def __init__( self.label = label - @property - def label(self): - """The text label of the button""" - return self._label.text - - @label.setter - def label(self, newtext): - if self._label and self and (self[-1] == self._label): - self.pop() - - self._label = None - if not newtext or (self._label_color is None): # no new text - return # nothing to do! - - if not self._label_font: - raise RuntimeError("Please provide label font") - self._label = Label(self._label_font, text=newtext) - dims = self._label.bounding_box - if dims[2] >= self.width or dims[3] >= self.height: - while len(self._label.text) > 1 and ( - dims[2] >= self.width or dims[3] >= self.height - ): - self._label.text = "{}.".format(self._label.text[:-2]) - dims = self._label.bounding_box - if len(self._label.text) <= 1: - raise RuntimeError("Button not large enough for label") - self._label.x = (self.width - dims[2]) // 2 - self._label.y = self.height // 2 - self._label.color = self._label_color - self.append(self._label) - - if (self.selected_label is None) and (self._label_color is not None): - self.selected_label = (~self._label_color) & 0xFFFFFF - - @property - def selected(self): - """Selected inverts the colors.""" - return self._selected - - @selected.setter - def selected(self, value): - if value == self._selected: - return # bail now, nothing more to do - self._selected = value + def _subclass_selected_behavior(self, value): if self._selected: new_fill = self.selected_fill new_out = self.selected_outline - new_label = self.selected_label else: new_fill = self._fill_color new_out = self._outline_color - new_label = self._label_color # update all relevant colors! if self.body is not None: self.body.fill = new_fill self.body.outline = new_out - if self._label is not None: - self._label.color = new_label @property def group(self): @@ -295,25 +240,6 @@ def selected_outline(self, new_color): if self.selected: self.body.outline = self._selected_outline - @property - def selected_label(self): - """The font color of the button when selected""" - return self._selected_label - - @selected_label.setter - def selected_label(self, new_color): - self._selected_label = _check_color(new_color) - - @property - def label_color(self): - """The font color of the button""" - return self._label_color - - @label_color.setter - def label_color(self, new_color): - self._label_color = _check_color(new_color) - self._label.color = self._label_color - @property def width(self): """The width of the button""" diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py new file mode 100644 index 0000000..29d33a9 --- /dev/null +++ b/adafruit_button/button_base.py @@ -0,0 +1,152 @@ +# SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_button.button` +================================================================================ + +UI Buttons for displayio + + +* Author(s): Limor Fried + +Implementation Notes +-------------------- + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" +from adafruit_display_text.bitmap_label import Label +from displayio import Group + + +def _check_color(color): + # if a tuple is supplied, convert it to a RGB number + if isinstance(color, tuple): + r, g, b = color + return int((r << 16) + (g << 8) + (b & 0xFF)) + return color + + +class ButtonBase(Group): + # pylint: disable=too-many-instance-attributes + """Superclass for creating UI buttons for ``displayio``. + + :param x: The x position of the button. + :param y: The y position of the button. + :param width: The width of the button in tiles. + :param height: The height of the button in tiles. + :param label: The text that appears inside the button. Defaults to not displaying the label. + :param label_font: The button label font. + :param label_color: The color of the button label text. Defaults to 0x0. + """ + + def __init__( + self, + *, + x, + y, + width, + height, + name=None, + label=None, + label_font=None, + label_color=0x0, + selected_label=None + ): + super().__init__(x=x, y=y) + self.x = x + self.y = y + self._width = width + self._height = height + self._font = label_font + self._selected = False + self.name = name + self._label = label + self._label_color = label_color + self._label_font = label_font + self._selected_label = _check_color(selected_label) + + @property + def label(self): + """The text label of the button""" + return self._label.text + + @label.setter + def label(self, newtext): + + if self._label and self and (self[-1] == self._label): + self.pop() + + self._label = None + if not newtext or (self._label_color is None): # no new text + return # nothing to do! + + if not self._label_font: + raise RuntimeError("Please provide label font") + self._label = Label(self._label_font, text=newtext) + dims = self._label.bounding_box + if dims[2] >= self.width or dims[3] >= self.height: + while len(self._label.text) > 1 and ( + dims[2] >= self.width or dims[3] >= self.height + ): + self._label.text = "{}.".format(self._label.text[:-2]) + dims = self._label.bounding_box + if len(self._label.text) <= 1: + raise RuntimeError("Button not large enough for label") + self._label.x = (self.width - dims[2]) // 2 + self._label.y = self.height // 2 + self._label.color = ( + self._label_color if not self.selected else self._selected_label + ) + self.append(self._label) + + if (self.selected_label is None) and (self._label_color is not None): + self.selected_label = (~self._label_color) & 0xFFFFFF + + def _subclass_selected_behavior(self, value): + # Subclasses should overide this! + pass + + @property + def selected(self): + """Selected inverts the colors.""" + return self._selected + + @selected.setter + def selected(self, value): + if value == self._selected: + return # bail now, nothing more to do + self._selected = value + + if self._selected: + new_label = self.selected_label + else: + new_label = self._label_color + if self._label is not None: + self._label.color = new_label + + self._subclass_selected_behavior(value) + + @property + def selected_label(self): + """The font color of the button when selected""" + return self._selected_label + + @selected_label.setter + def selected_label(self, new_color): + self._selected_label = _check_color(new_color) + + @property + def label_color(self): + """The font color of the button""" + return self._label_color + + @label_color.setter + def label_color(self, new_color): + self._label_color = _check_color(new_color) + self._label.color = self._label_color diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py new file mode 100644 index 0000000..c9ed66b --- /dev/null +++ b/adafruit_button/sprite_button.py @@ -0,0 +1,126 @@ +# SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_button.button` +================================================================================ + +Bitmap 3x3 Spritesheet based UI Button for displayio + + +* Author(s): Tim Cocks + +Implementation Notes +-------------------- + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" +from adafruit_imageload.tilegrid_inflator import inflate_tilegrid +from adafruit_imageload import load +from adafruit_button.button_base import ButtonBase + + +class SpriteButton(ButtonBase): + """Helper class for creating 3x3 Bitmap Spritesheet UI buttons for ``displayio``. + + :param x: The x position of the button. + :param y: The y position of the button. + :param width: The width of the button in tiles. + :param height: The height of the button in tiles. + :param label: The text that appears inside the button. Defaults to not displaying the label. + :param label_font: The button label font. + :param label_color: The color of the button label text. Defaults to 0x0. + :param string bmp_path: The path of the 3x3 spritesheet Bitmap file + :param string selected_bmp_path: The path of the 3x3 spritesheet Bitmap file to use when pressed + """ + + def __init__( + self, + *, + x, + y, + width, + height, + name=None, + label=None, + label_font=None, + label_color=0x0, + selected_label=None, + bmp_path=None, + selected_bmp_path=None, + transparent_index=None + ): + super().__init__( + x=x, + y=y, + width=width, + height=height, + name=name, + label=label, + label_font=label_font, + label_color=label_color, + selected_label=selected_label, + ) + + self._bmp, self._bmp_palette = load(bmp_path) + + self._selected_bmp = None + self._selected_bmp_palette = None + self._selected = False + + if selected_bmp_path is not None: + self._selected_bmp, self._selected_bmp_palette = load(selected_bmp_path) + if transparent_index is not None: + if isinstance(transparent_index, tuple): + for _index in transparent_index: + self._selected_bmp_palette.make_transparent(_index) + elif isinstance(transparent_index, int): + self._selected_bmp_palette.make_transparent(0) + + print((width // (self._bmp.width // 3), height // (self._bmp.height // 3))) + self._btn_tilegrid = inflate_tilegrid( + bmp_obj=self._bmp, + bmp_palette=self._bmp_palette, + target_size=( + width // (self._bmp.width // 3), + height // (self._bmp.height // 3), + ), + transparent_index=transparent_index, + ) + self.append(self._btn_tilegrid) + + print("setting label") + self.label = label + + @property + def width(self): + """The width of the button""" + return self._width + + @property + def height(self): + """The height of the button""" + return self._height + + def contains(self, point): + """Used to determine if a point is contained within a button. For example, + ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for + determining that a button has been touched. + """ + return (self.x <= point[0] <= self.x + self.width) and ( + self.y <= point[1] <= self.y + self.height + ) + + def _subclass_selected_behavior(self, value): + if self._selected: + if self._selected_bmp is not None: + self._btn_tilegrid.bitmap = self._selected_bmp + self._btn_tilegrid.pixel_shader = self._selected_bmp_palette + else: + self._btn_tilegrid.bitmap = self._bmp + self._btn_tilegrid.pixel_shader = self._bmp_palette diff --git a/setup.py b/setup.py index 8beeb54..3aa2af5 100644 --- a/setup.py +++ b/setup.py @@ -56,5 +56,5 @@ # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=["adafruit_button"], + packages=["adafruit_button"], ) From 17d1b2d15c57b199a268ba0763987fa2e3bdc4e1 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 23 Apr 2022 15:10:12 -0500 Subject: [PATCH 065/137] fix docs build --- adafruit_button/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_button/__init__.py b/adafruit_button/__init__.py index cd66773..2fa5ba8 100644 --- a/adafruit_button/__init__.py +++ b/adafruit_button/__init__.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: MIT """ -`adafruit_button.button` +`adafruit_button` ================================================================================ UI Buttons for displayio From 7cc0098a879029fbb7c8f8315b734b794686c2e6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 24 Apr 2022 14:03:07 -0500 Subject: [PATCH 066/137] change discord badge --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 0dd6809..dffb9b7 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Introduction :target: https://docs.circuitpython.org/projects/display-button/en/latest/ :alt: Documentation Status -.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg +.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From c991c87eeb1a005090a9140a6cb6051c7ba84124 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 15 May 2022 12:48:39 -0400 Subject: [PATCH 067/137] Patch .pre-commit-config.yaml --- .pre-commit-config.yaml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7467c1d..3343606 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,40 +3,40 @@ # SPDX-License-Identifier: Unlicense repos: -- repo: https://github.com/python/black + - repo: https://github.com/python/black rev: 22.3.0 hooks: - - id: black -- repo: https://github.com/fsfe/reuse-tool - rev: v0.12.1 + - id: black + - repo: https://github.com/fsfe/reuse-tool + rev: v0.14.0 hooks: - - id: reuse -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + - id: reuse + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace -- repo: https://github.com/pycqa/pylint + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/pycqa/pylint rev: v2.11.1 hooks: - - id: pylint + - id: pylint name: pylint (library code) types: [python] args: - --disable=consider-using-f-string exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint + - id: pylint name: pylint (example code) description: Run pylint rules on "examples/*.py" files types: [python] files: "^examples/" args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint name: pylint (test code) description: Run pylint rules on "tests/*.py" files types: [python] files: "^tests/" args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - --disable=missing-docstring,consider-using-f-string,duplicate-code From 0b2295344bfd3a09b83cf1d4a4fc0eb40218fc55 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:55 -0400 Subject: [PATCH 068/137] Increase min lines similarity Signed-off-by: Alec Delaney --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index cfd1c41..f006a4a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=12 [BASIC] From 47cb1d7db6dff7f2bfd9769b1b7605db4a599549 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:23 -0400 Subject: [PATCH 069/137] Switch to inclusive terminology Signed-off-by: Alec Delaney --- .pylintrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index f006a4a..f772971 100644 --- a/.pylintrc +++ b/.pylintrc @@ -9,11 +9,11 @@ # run arbitrary code extension-pkg-whitelist= -# Add files or directories to the blacklist. They should be base names, not +# Add files or directories to the ignore-list. They should be base names, not # paths. ignore=CVS -# Add files or directories matching the regex patterns to the blacklist. The +# Add files or directories matching the regex patterns to the ignore-list. The # regex matches against base names, not paths. ignore-patterns= From 2ed0fdaa9b74dbe1da7000a8cf076e5bfb9d8b07 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 30 May 2022 14:25:04 -0400 Subject: [PATCH 070/137] Set language to "en" for documentation Signed-off-by: Alec Delaney --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index bc9bb77..d9ebc43 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -60,7 +60,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. From ddd7c13b3256d90a6e329a9e773226ed31a7d27a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 6 Jun 2022 10:24:45 -0500 Subject: [PATCH 071/137] adding sprite button example --- examples/bmps/gradient_button_0.bmp | Bin 0 -> 3206 bytes examples/bmps/gradient_button_0.bmp.license | 2 + examples/bmps/gradient_button_1.bmp | Bin 0 -> 2822 bytes examples/bmps/gradient_button_1.bmp.license | 2 + .../display_button_spritebutton_simpletest.py | 68 ++++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 examples/bmps/gradient_button_0.bmp create mode 100644 examples/bmps/gradient_button_0.bmp.license create mode 100644 examples/bmps/gradient_button_1.bmp create mode 100644 examples/bmps/gradient_button_1.bmp.license create mode 100644 examples/display_button_spritebutton_simpletest.py diff --git a/examples/bmps/gradient_button_0.bmp b/examples/bmps/gradient_button_0.bmp new file mode 100644 index 0000000000000000000000000000000000000000..bfa8cfa18c0c192577fc329f79b4b9f870a59ccc GIT binary patch literal 3206 zcmb7_Sx{7G5QUpXK@gEa9Yl=m1O{Xq7dAziQ4t3aR8T=hMZg7IB1Aw17f=+9;J)vg zxWqN?7=4IIv?@tudDHU6hg4Zfm3c_=)H(hCcQEmRBz^Dc?{xp?-my@b@s5_hq^iY@ zs1Yu~kPCV0gFZxI!?hk_BO+qwt)}r43sx!fKbq@1S;jlr^$v8G*bQ_8J#G?vLVd45 zSBZT0%+Y1wG)p3M}R3?psmEIU@ACfBeaQlEI1ZS-$9(U9%>@C zfi`ebJ=8#)4Q7LmTBwdV7t933&BFLXc<&ZTnrY2C6!PWaVb~|mMtWnFDfTq zG#8pjTme>qOJ+kQ#7n`Y;PM$z5pn+K#4F%ez?a}>vbq2&B(4Q(!IBHa^$vV)7nn=j z0N((v&n9jXO(x!CgY3kc!Oh^-OyV}tIO1~r{q0DD(usG1JHgIT#JfeKi4P<}$;3y8 zL-E8Xqlr(6Vu+6;b3Ou!B)$|3g%Dp0f`$@b2XC370OI@p&;a5GVCy3gzU2w=qkfPt z@ni5Ycxfgyi}(vK$eZ{H_yl~~3+he$415ND>jJqFe+M3VNPG`Jvwh!V9zy(eInIjU zp&#;ze}uloznQO~Z(1?85dQ?d+=q9*gkBN9dP@A_XX59-K)({d#{BvP@o&$G-~0~! zLHy?%V#fa^XLa>h&XkiqhSi}nDg5`eB)Xr_@w-<)IeYy0iQ`fyRafoA*$Y?i>V)xt z8g74l`0$ZqM-Cr3auf|#njV4kw^c|zAnw7H{reB@Kd@ibfdhxMG5SH_rw=424@mr6 z=bp~aj*d>0YQo(ehVQ^ZN9Q?tK*zf-Z#Sy_Bd6Ogwq2$j>fYXdS$_cfjkdP7ZMr}V zGPbEpZS`W?4fz0h=ydCr)>fsrfNO2ts<(2AIxSh$ofgz)x#eit837g)zmD5Uka~FwkWLN5YqW2i=~!SX{cVc zSTC_wv$U!ui*>%TvZAuGa$!YC)v!lc89gY5+K+sCY(^&QF~- ztx)c%=u(AXK|!I^RJ8>3fzIdU<>lt(qYLwL^I<_}b=&;Be4TgXI2==^I3`Qa$$?Xq zqiD=IICMBB>-;3tgzW4|6DEK%025VrE+%3x(s{ehKHipP&$8LkZCN%OtaST$yFJTp zmu;5NZrAxtRbw(U$3Wx8jsam%Mjxj=CY?{u$iSVEktRsjQyPZU)U@=p^mN#?R5{N` z)A`XUDWj!EjU1^uTFNN2k+?>yT?(vZbl#erm~6EsCM8)>Ny*lvL~D{YF&SerT%tA6 zD!b&wB&*KH$0fwYOU0oC>K+~klaQdiK8=sl`4Q2vF|je0*jS4t+7e@d(PfE=vBbpU z40m)ib|Z9tPL!?)1Cjq6qoN|-kBW$jh>Vz{^QXc?Lc+sCL&L(u!@@)1LPEnZ;R;cU zFqtH9O6P9|1rG}vh8rz7SPbgDVZmx=ASejtrp|XQ7(6&I&`Hii7 z*Jo#D4|Q{KcXM@jadmfhb#;N<-Q8S<%sz8VC)C%k@s+AKJ@)Rn@vYip*!gGae&|1@ F{{k9?7Q+Al literal 0 HcmV?d00001 diff --git a/examples/bmps/gradient_button_0.bmp.license b/examples/bmps/gradient_button_0.bmp.license new file mode 100644 index 0000000..8f7990c --- /dev/null +++ b/examples/bmps/gradient_button_0.bmp.license @@ -0,0 +1,2 @@ +# SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries +# SPDX-License-Identifier: MIT diff --git a/examples/bmps/gradient_button_1.bmp b/examples/bmps/gradient_button_1.bmp new file mode 100644 index 0000000000000000000000000000000000000000..ba6d75c0bfd0b47efb2f89f4cd576e865f03c9ba GIT binary patch literal 2822 zcmb7FT}+#06n&1(WGw=5!jT z-l!SbTrw}zU}8+v7-!~CJWK80>>~Z{&`xAcOGl7U<3JduYm?@aX;(xJdg9kb2#(pEj;_! z5=Nd_#FI}g;_;`W7(PvWdI19?Q4Bt_jKMRDIQ3i?_r+1^}5{o8A>U5dg%TsOJ``{*(%FUN4?@@-UISwq8> z7^<$WpyBE=%CD`V`dSR;_hKmi;0}t$R+0PBI&wZ zpf6s>(6-Q1I&T|ROFhZFbD9(J8xl`rq^iE9rIIHJ?SdN8)6&ujY5cI1!?*UFMSUrUK&S6uyDa8kWKSCB)*B|V3vUSj5O zo-gfA;I4$+y;&=pvxL1{u!kltY5GbzdnLbb-`!jAk5SvPEBU{Tqo&yPJI&SGgSn`EM3WbG5>S5+Xjlm?FqC&|R6Ar3} z6>A-=cq2GiEcsHSv6NsmmMCUfq6}hkNYh+WYAiKM{!r48d^w}6ysWH@iI19fwTUHf zt}s=YE2vR7nJP?XYGyLXGRuMthFS9WCJo6~R#qP7qZ$n?4~s*juh^D+l@3dlMWn?- zlC_$pahJT+T5GMLr`Bq<*3?wjuqL4fvUp9XuC>-mzP`S$j*coKZAdt*#FhM!q#^l+ zq#^m{=H@0UK~r;MQ*#r~y2pd2CGT+9?R4xmyUk%^!3Jr&!$!<-*ljf0?2^APX-MAX zYH4x0Tu!DICsT`ygp0s}i?+;?KNiPPU5Pk)jQDe;(Wo3{vEAk- zDfy1$^mH7jB5qgQ-qB7I%{TtuixkQ`Ivluzu)Wa^7*|UkKaSm z$Cj^)lwb1QjDR{sCjx;$FhFB>cP|mEolvu%&ZNo*Tb%gyPXKO>(08zzl}6#xJL literal 0 HcmV?d00001 diff --git a/examples/bmps/gradient_button_1.bmp.license b/examples/bmps/gradient_button_1.bmp.license new file mode 100644 index 0000000..8f7990c --- /dev/null +++ b/examples/bmps/gradient_button_1.bmp.license @@ -0,0 +1,2 @@ +# SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries +# SPDX-License-Identifier: MIT diff --git a/examples/display_button_spritebutton_simpletest.py b/examples/display_button_spritebutton_simpletest.py new file mode 100644 index 0000000..8f78c48 --- /dev/null +++ b/examples/display_button_spritebutton_simpletest.py @@ -0,0 +1,68 @@ +# SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries +# SPDX-License-Identifier: MIT +import time +import board +import displayio +import adafruit_touchscreen +import terminalio +from adafruit_button.sprite_button import SpriteButton + +# These pins are used as both analog and digital! XL, XR and YU must be analog +# and digital capable. YD just need to be digital +ts = adafruit_touchscreen.Touchscreen( + board.TOUCH_XL, + board.TOUCH_XR, + board.TOUCH_YD, + board.TOUCH_YU, + calibration=((5200, 59000), (5800, 57000)), + size=(board.DISPLAY.width, board.DISPLAY.height), +) + +# Make the display context +main_group = displayio.Group() +board.DISPLAY.show(main_group) + +BUTTON_WIDTH = 10 * 16 +BUTTON_HEIGHT = 3 * 16 +BUTTON_MARGIN = 20 + +font = terminalio.FONT + +buttons = [] + + +button_0 = SpriteButton( + x=BUTTON_MARGIN, + y=BUTTON_MARGIN, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="button0", + label_font=font, + bmp_path="bmps/gradient_button_0.bmp", + selected_bmp_path="bmps/gradient_button_1.bmp", + transparent_index=0, +) + +buttons.append(button_0) + +for b in buttons: + main_group.append(b) +while True: + p = ts.touch_point + if p: + print(p) + for i, b in enumerate(buttons): + if b.contains(p): + print("Button %d pressed" % i) + b.selected = True + b.label = "pressed" + else: + b.selected = False + b.label = "button0" + + else: + for i, b in enumerate(buttons): + if b.selected: + b.selected = False + b.label = "button0" + time.sleep(0.01) From 41fac3e7769a5b66fb8c2285dca72edc4da3e04f Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 7 Jun 2022 15:34:14 -0400 Subject: [PATCH 072/137] Added cp.org link to index.rst --- docs/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index d598087..d699318 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -31,7 +31,8 @@ Table of Contents .. toctree:: :caption: Other Links - Download + Download from GitHub + Download Library Bundle CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat From 0642f85a252842d1d05103a25ca8ada9fcac5185 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Jul 2022 13:58:40 -0400 Subject: [PATCH 073/137] Changed .env to .venv in README.rst --- README.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index dffb9b7..483c91b 100644 --- a/README.rst +++ b/README.rst @@ -46,8 +46,8 @@ To install in a virtual environment in your current project: .. code-block:: shell mkdir project-name && cd project-name - python3 -m venv .env - source .env/bin/activate + python3 -m venv .venv + source .venv/bin/activate pip3 install adafruit-circuitpython-display-button Usage Example @@ -80,15 +80,15 @@ To build this library locally you'll need to install the .. code-block:: shell - python3 -m venv .env - source .env/bin/activate + python3 -m venv .venv + source .venv/bin/activate pip install circuitpython-build-tools Once installed, make sure you are in the virtual environment: .. code-block:: shell - source .env/bin/activate + source .venv/bin/activate Then run the build: @@ -104,8 +104,8 @@ install dependencies (feel free to reuse the virtual environment from above): .. code-block:: shell - python3 -m venv .env - source .env/bin/activate + python3 -m venv .venv + source .venv/bin/activate pip install Sphinx sphinx-rtd-theme Now, once you have the virtual environment activated: From eb81c10c446cc5d916058d99bcc9db72c71582b7 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 2 Aug 2022 17:00:29 -0400 Subject: [PATCH 074/137] Added Black formatting badge --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index 483c91b..7828bef 100644 --- a/README.rst +++ b/README.rst @@ -13,6 +13,10 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_Display_Button/actions :alt: Build Status +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + :alt: Code Style: Black + UI Buttons for displayio From b8d003118f0d44981ae0c9e3998b97048b99593f Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 8 Aug 2022 22:05:54 -0400 Subject: [PATCH 075/137] Switched to pyproject.toml --- .github/workflows/build.yml | 18 ++++++----- .github/workflows/release.yml | 17 ++++++---- optional_requirements.txt | 3 ++ pyproject.toml | 45 ++++++++++++++++++++++++++ requirements.txt | 6 ++-- setup.py | 60 ----------------------------------- 6 files changed, 71 insertions(+), 78 deletions(-) create mode 100644 optional_requirements.txt create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 474520d..22f6582 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,8 @@ jobs: pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags + - name: Setup problem matchers + uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - name: Pre-commit hooks run: | pre-commit run --all-files @@ -60,16 +62,16 @@ jobs: - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Build Python package - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | - pip install --upgrade setuptools wheel twine readme_renderer testresources - python setup.py sdist - python setup.py bdist_wheel --universal + pip install --upgrade build twine + for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do + sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + done; + python -m build twine check dist/* - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a65e5de..d1b4f8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,25 +61,28 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Set up Python - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install --upgrade build twine - name: Build and publish - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') env: TWINE_USERNAME: ${{ secrets.pypi_username }} TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | - python setup.py sdist + for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do + sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + done; + python -m build twine upload dist/* diff --git a/optional_requirements.txt b/optional_requirements.txt new file mode 100644 index 0000000..d4e27c4 --- /dev/null +++ b/optional_requirements.txt @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..2855373 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +[build-system] +requires = [ + "setuptools", + "wheel", +] + +[project] +name = "adafruit-circuitpython-display_button" +description = "UI Buttons for displayio" +version = "0.0.0-auto.0" +readme = "README.rst" +authors = [ + {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} +] +urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Button"} +keywords = [ + "adafruit", + "blinka", + "circuitpython", + "micropython", + "display_button", + "buttons", + "UI", +] +license = {text = "MIT"} +classifiers = [ + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Embedded Systems", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", +] +dynamic = ["dependencies", "optional-dependencies"] + +[tool.setuptools] +py-modules = ["adafruit_button"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} diff --git a/requirements.txt b/requirements.txt index 2f9e5aa..964ebbf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,9 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries # # SPDX-License-Identifier: Unlicense +Adafruit-Blinka-displayio Adafruit-Blinka -adafruit-blinka-displayio +adafruit-circuitpython-bitmap-font adafruit-circuitpython-display-text adafruit-circuitpython-display-shapes -adafruit-circuitpython-bitmap-font diff --git a/setup.py b/setup.py deleted file mode 100644 index 8beeb54..0000000 --- a/setup.py +++ /dev/null @@ -1,60 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -"""A setuptools based setup module. - -See: -https://packaging.python.org/en/latest/distributing.html -https://github.com/pypa/sampleproject -""" - -from setuptools import setup, find_packages - -# To use a consistent encoding -from codecs import open -from os import path - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, "README.rst"), encoding="utf-8") as f: - long_description = f.read() - -setup( - name="adafruit-circuitpython-display_button", - use_scm_version=True, - setup_requires=["setuptools_scm"], - description="UI Buttons for displayio", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/adafruit/Adafruit_CircuitPython_Display_Button", - # Author details - author="Adafruit Industries", - author_email="circuitpython@adafruit.com", - install_requires=[ - "Adafruit-Blinka", - "adafruit-blinka-displayio", - "adafruit-circuitpython-display-text", - "adafruit-circuitpython-display-shapes", - ], - # Choose your license - license="MIT", - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Topic :: Software Development :: Libraries", - "Topic :: System :: Hardware", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3", - ], - # What does your project relate to? - keywords="adafruit blinka circuitpython micropython display_button buttons UI", - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, - # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=["adafruit_button"], -) From ed71bd13f25f590ba8c0da28fc49faeb48256ef5 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 9 Aug 2022 12:03:54 -0400 Subject: [PATCH 076/137] Add setuptools-scm to build system requirements Signed-off-by: Alec Delaney --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 2855373..c34c497 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ requires = [ "setuptools", "wheel", + "setuptools-scm", ] [project] From f1c449acef499a5b67d8dd1c004b8c77f053e549 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 15 Aug 2022 10:32:34 -0500 Subject: [PATCH 077/137] merge main, update pyproject.toml for package instead of single file --- pyproject.toml | 2 +- setup.py | 60 -------------------------------------------------- 2 files changed, 1 insertion(+), 61 deletions(-) delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml index c34c497..1d845d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ classifiers = [ dynamic = ["dependencies", "optional-dependencies"] [tool.setuptools] -py-modules = ["adafruit_button"] +packages = ["adafruit_button"] [tool.setuptools.dynamic] dependencies = {file = ["requirements.txt"]} diff --git a/setup.py b/setup.py deleted file mode 100644 index 3aa2af5..0000000 --- a/setup.py +++ /dev/null @@ -1,60 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -"""A setuptools based setup module. - -See: -https://packaging.python.org/en/latest/distributing.html -https://github.com/pypa/sampleproject -""" - -from setuptools import setup, find_packages - -# To use a consistent encoding -from codecs import open -from os import path - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, "README.rst"), encoding="utf-8") as f: - long_description = f.read() - -setup( - name="adafruit-circuitpython-display_button", - use_scm_version=True, - setup_requires=["setuptools_scm"], - description="UI Buttons for displayio", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/adafruit/Adafruit_CircuitPython_Display_Button", - # Author details - author="Adafruit Industries", - author_email="circuitpython@adafruit.com", - install_requires=[ - "Adafruit-Blinka", - "adafruit-blinka-displayio", - "adafruit-circuitpython-display-text", - "adafruit-circuitpython-display-shapes", - ], - # Choose your license - license="MIT", - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Topic :: Software Development :: Libraries", - "Topic :: System :: Hardware", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3", - ], - # What does your project relate to? - keywords="adafruit blinka circuitpython micropython display_button buttons UI", - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, - # CHANGE `py_modules=['...']` TO `packages=['...']` - packages=["adafruit_button"], -) From 5a790599324e9359cfd5f75481a9d8f22480b9ff Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 18:09:15 -0400 Subject: [PATCH 078/137] Update version string --- adafruit_button.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_button.py b/adafruit_button.py index caf554b..8a2154d 100644 --- a/adafruit_button.py +++ b/adafruit_button.py @@ -27,7 +27,7 @@ from adafruit_display_shapes.rect import Rect from adafruit_display_shapes.roundrect import RoundRect -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Button.git" diff --git a/pyproject.toml b/pyproject.toml index c34c497..2026c32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires = [ [project] name = "adafruit-circuitpython-display_button" description = "UI Buttons for displayio" -version = "0.0.0-auto.0" +version = "0.0.0+auto.0" readme = "README.rst" authors = [ {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} From f68869c04e896600c36899024bbfba649c9cfe5c Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 21:09:15 -0400 Subject: [PATCH 079/137] Fix version strings in workflow files --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 22f6582..cb2f60e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,7 +71,7 @@ jobs: run: | pip install --upgrade build twine for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; done; python -m build twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1b4f8d..f3a0325 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; done; python -m build twine upload dist/* From 1ca574d372e3d3752b9ecc24c0d61c48de240e26 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 22 Aug 2022 21:36:32 -0400 Subject: [PATCH 080/137] Keep copyright up to date in documentation --- docs/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index d9ebc43..2a58f74 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,6 +6,7 @@ import os import sys +import datetime sys.path.insert(0, os.path.abspath("..")) @@ -43,7 +44,8 @@ # General information about the project. project = "Adafruit Display_Button Library" -copyright = "2019 Limor Fried" +current_year = str(datetime.datetime.now().year) +copyright = current_year + " Limor Fried" author = "Limor Fried" # The version info for the project you're documenting, acts as replacement for From f690d37e97c2b95f505d0646a95e2acf4e57bc2d Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 23 Aug 2022 17:26:22 -0400 Subject: [PATCH 081/137] Use year duration range for copyright attribution --- docs/conf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 2a58f74..9bce0f7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -44,8 +44,14 @@ # General information about the project. project = "Adafruit Display_Button Library" +creation_year = "2019" current_year = str(datetime.datetime.now().year) -copyright = current_year + " Limor Fried" +year_duration = ( + current_year + if current_year == creation_year + else creation_year + " - " + current_year +) +copyright = year_duration + " Limor Fried" author = "Limor Fried" # The version info for the project you're documenting, acts as replacement for From be32fd34b8b7d206860dc5702b86b4dbc6d5cdde Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:02:50 -0400 Subject: [PATCH 082/137] Switching to composite actions --- .github/workflows/build.yml | 67 +---------------------- .github/workflows/release.yml | 88 ------------------------------ .github/workflows/release_gh.yml | 14 +++++ .github/workflows/release_pypi.yml | 14 +++++ 4 files changed, 30 insertions(+), 153 deletions(-) delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/release_gh.yml create mode 100644 .github/workflows/release_pypi.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb2f60e..041a337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,68 +10,5 @@ jobs: test: runs-on: ubuntu-latest steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install dependencies - # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) - run: | - source actions-ci/install.sh - - name: Pip install Sphinx, pre-commit - run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - - name: Library version - run: git describe --dirty --always --tags - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - - name: Pre-commit hooks - run: | - pre-commit run --all-files - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Archive bundles - uses: actions/upload-artifact@v2 - with: - name: bundles - path: ${{ github.workspace }}/bundles/ - - name: Build docs - working-directory: docs - run: sphinx-build -E -W -b html . _build/html - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Build Python package - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - pip install --upgrade build twine - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; - done; - python -m build - twine check dist/* + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index f3a0325..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,88 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -name: Release Actions - -on: - release: - types: [published] - -jobs: - upload-release-assets: - runs-on: ubuntu-latest - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install deps - run: | - source actions-ci/install.sh - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Upload Release Assets - # the 'official' actions version does not yet support dynamically - # supplying asset names to upload. @csexton's version chosen based on - # discussion in the issue below, as its the simplest to implement and - # allows for selecting files with a pattern. - # https://github.com/actions/upload-release-asset/issues/4 - #uses: actions/upload-release-asset@v1.0.1 - uses: csexton/release-asset-action@master - with: - pattern: "bundles/*" - github-token: ${{ secrets.GITHUB_TOKEN }} - - upload-pypi: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Set up Python - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - python -m pip install --upgrade pip - pip install --upgrade build twine - - name: Build and publish - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - env: - TWINE_USERNAME: ${{ secrets.pypi_username }} - TWINE_PASSWORD: ${{ secrets.pypi_password }} - run: | - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; - done; - python -m build - twine upload dist/* diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main From 42d963d15c7f0a4ab11ae5683a9e3c015632ba55 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:47:00 -0400 Subject: [PATCH 083/137] Updated pylint version to 2.13.0 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3343606..4c43710 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.11.1 + rev: v2.13.0 hooks: - id: pylint name: pylint (library code) From 647cfddd0fb62129b9b6b58fb31fec693f48ca29 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 08:15:20 -0400 Subject: [PATCH 084/137] Update pylint to 2.15.5 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c43710..0e5fccc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.13.0 + rev: v2.15.5 hooks: - id: pylint name: pylint (library code) From cc352fdcaf9e7a1b5b035f1d7f04bcbbb61ec01f Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:12:45 -0400 Subject: [PATCH 085/137] Fix release CI files --- .github/workflows/release_gh.yml | 14 +++++++++----- .github/workflows/release_pypi.yml | 15 ++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index 041a337..b8aa8d6 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -2,13 +2,17 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: GitHub Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml index 041a337..65775b7 100644 --- a/.github/workflows/release_pypi.yml +++ b/.github/workflows/release_pypi.yml @@ -2,13 +2,18 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: PyPI Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run PyPI Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-pypi@main + with: + pypi-username: ${{ secrets.pypi_username }} + pypi-password: ${{ secrets.pypi_password }} From af4b80c8af53e294e0cb1a918966a60ec3fd5973 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 18:34:33 -0400 Subject: [PATCH 086/137] Update .pylintrc for v2.15.5 --- .pylintrc | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/.pylintrc b/.pylintrc index f772971..40208c3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense @@ -26,7 +26,7 @@ jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins= +load-plugins=pylint.extensions.no_self_use # Pickle collected data for later comparisons. persistent=yes @@ -54,8 +54,8 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding +# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call +disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -225,12 +225,6 @@ max-line-length=100 # Maximum number of lines in a module max-module-lines=1000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma,dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no @@ -257,38 +251,22 @@ min-similarity-lines=12 [BASIC] -# Naming hint for argument names -argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct argument names argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for attribute names -attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct attribute names attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ # Bad variable names which should always be refused, separated by a comma bad-names=foo,bar,baz,toto,tutu,tata -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - # Regular expression matching correct class attribute names class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ -# Naming hint for class names -# class-name-hint=[A-Z_][a-zA-Z0-9]+$ -class-name-hint=[A-Z_][a-zA-Z0-9_]+$ - # Regular expression matching correct class names # class-rgx=[A-Z_][a-zA-Z0-9]+$ class-rgx=[A-Z_][a-zA-Z0-9_]+$ -# Naming hint for constant names -const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - # Regular expression matching correct constant names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ @@ -296,9 +274,6 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ # ones are exempt. docstring-min-length=-1 -# Naming hint for function names -function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct function names function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ @@ -309,21 +284,12 @@ good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ # Include a hint for the correct naming format with invalid-name include-naming-hint=no -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ - # Regular expression matching correct inline iteration names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ -# Naming hint for method names -method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct method names method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - # Regular expression matching correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ @@ -339,9 +305,6 @@ no-docstring-rgx=^_ # to this list to register other decorators that produce valid properties. property-classes=abc.abstractproperty -# Naming hint for variable names -variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct variable names variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ From 54b419b0e2bea70e979ae041bcffeaa0343f7760 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:16:31 -0400 Subject: [PATCH 087/137] Add .venv to .gitignore Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From d14280a179d55eb3f2bda45429ef84af290fe42b Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:39:55 -0500 Subject: [PATCH 088/137] Add upload url to release action Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .github/workflows/release_gh.yml | 1 + 1 file changed, 1 insertion(+) 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 }} From a66c3ee8d0d411c84b1b83fdcc885d8dff2a7a56 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Tue, 9 May 2023 20:26:25 -0400 Subject: [PATCH 089/137] Update pre-commit hooks Signed-off-by: Tekktrik --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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) From 73b36fc73a84e3cca2c26d466987eb82fc98c1aa Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Sun, 14 May 2023 13:00:32 -0400 Subject: [PATCH 090/137] Update .pylintrc, fix jQuery for docs Signed-off-by: Tekktrik --- .pylintrc | 2 +- docs/conf.py | 1 + docs/requirements.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) 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/docs/conf.py b/docs/conf.py index 9bce0f7..d1f9032 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", diff --git a/docs/requirements.txt b/docs/requirements.txt index 88e6733..797aa04 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ # SPDX-License-Identifier: Unlicense sphinx>=4.0.0 +sphinxcontrib-jquery From 8d7daa65eaa38478afecdd7ddb4064d76b6be989 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 29 Jun 2023 20:13:24 -0500 Subject: [PATCH 091/137] add arg docs, add examples to rst, add modules to api.rst. --- adafruit_button/button_base.py | 2 ++ adafruit_button/sprite_button.py | 5 +++-- docs/api.rst | 9 +++++++++ docs/examples.rst | 9 +++++++++ optional_requirements.txt | 2 ++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 29d33a9..41a2286 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -40,9 +40,11 @@ class ButtonBase(Group): :param y: The y position of the button. :param width: The width of the button in tiles. :param height: The height of the button in tiles. + :param name: A name, or miscellaneous string that is stored on the button. :param label: The text that appears inside the button. Defaults to not displaying the label. :param label_font: The button label font. :param label_color: The color of the button label text. Defaults to 0x0. + :param selected_label: Text that appears when selected """ def __init__( diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index c9ed66b..75dc70a 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -32,11 +32,14 @@ class SpriteButton(ButtonBase): :param y: The y position of the button. :param width: The width of the button in tiles. :param height: The height of the button in tiles. + :param name: A name, or miscellaneous string that is stored on the button. :param label: The text that appears inside the button. Defaults to not displaying the label. :param label_font: The button label font. :param label_color: The color of the button label text. Defaults to 0x0. + :param selected_label: Text that appears when selected :param string bmp_path: The path of the 3x3 spritesheet Bitmap file :param string selected_bmp_path: The path of the 3x3 spritesheet Bitmap file to use when pressed + :param int or tuple transparent_index: Index(s) that will be made transparent on the Palette """ def __init__( @@ -82,7 +85,6 @@ def __init__( elif isinstance(transparent_index, int): self._selected_bmp_palette.make_transparent(0) - print((width // (self._bmp.width // 3), height // (self._bmp.height // 3))) self._btn_tilegrid = inflate_tilegrid( bmp_obj=self._bmp, bmp_palette=self._bmp_palette, @@ -94,7 +96,6 @@ def __init__( ) self.append(self._btn_tilegrid) - print("setting label") self.label = label @property diff --git a/docs/api.rst b/docs/api.rst index 49c1de1..b604b89 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -6,3 +6,12 @@ .. automodule:: adafruit_button :members: + +.. automodule:: adafruit_button.button_base + :members: + +.. automodule:: adafruit_button.button + :members: + +.. automodule:: adafruit_button.sprite_button + :members: diff --git a/docs/examples.rst b/docs/examples.rst index 3960d39..30c5250 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -33,3 +33,12 @@ A soundboard made with buttons .. literalinclude:: ../examples/display_button_soundboard.py :caption: examples/display_button_soundboard.py :linenos: + +Sprite Button +------------- + +Custom sprite button + +.. literalinclude:: ../examples/display_button_spritebutton_simpletest.py + :caption: examples/display_button_spritebutton_simpletest.py + :linenos: diff --git a/optional_requirements.txt b/optional_requirements.txt index d4e27c4..9c5fce5 100644 --- a/optional_requirements.txt +++ b/optional_requirements.txt @@ -1,3 +1,5 @@ # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries # # SPDX-License-Identifier: Unlicense + +adafruit-circuitpython-ImageLoad From 95bb72a2f190e9571b36067be419b51a05458a1e Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 29 Jun 2023 20:21:04 -0500 Subject: [PATCH 092/137] format --- adafruit_button/button_base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 41a2286..d33cfc4 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -80,7 +80,6 @@ def label(self): @label.setter def label(self, newtext): - if self._label and self and (self[-1] == self._label): self.pop() From ea1769a83b0b70377569b93573b3d7807da3fa6a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 29 Jun 2023 20:30:15 -0500 Subject: [PATCH 093/137] raise helpful error if missing bmp_path --- adafruit_button/sprite_button.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index 75dc70a..c2f02ba 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -58,6 +58,9 @@ def __init__( selected_bmp_path=None, transparent_index=None ): + if bmp_path is None: + raise ValueError("Please supply bmp_path. It cannot be None.") + super().__init__( x=x, y=y, From 7500dee2666665e842c844c85cff09bea1631540 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 18 Sep 2023 16:23:19 -0500 Subject: [PATCH 094/137] "fix rtd theme " --- docs/conf.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index d1f9032..17d53f5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -101,19 +101,10 @@ # 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" +html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # 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, From b640b826899f4782893ccc48cc80dd24e2947fd6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 25 Sep 2023 16:47:41 -0500 Subject: [PATCH 095/137] add bitmaptools to mocked modules --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 17d53f5..c98d9f2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,7 +27,7 @@ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -autodoc_mock_imports = ["displayio"] +autodoc_mock_imports = ["displayio", "bitmaptools"] intersphinx_mapping = { From bd65ce16c93ccd6b9ab9245fa58cc127d8edf124 Mon Sep 17 00:00:00 2001 From: Paul Cutler Date: Thu, 2 Nov 2023 19:40:11 -0500 Subject: [PATCH 096/137] Update root_group for CP 9 compatibility --- examples/display_button_color_properties.py | 2 +- examples/display_button_customfont.py | 2 +- examples/display_button_simpletest.py | 2 +- examples/display_button_spritebutton_simpletest.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/display_button_color_properties.py b/examples/display_button_color_properties.py index 0ec1253..d8bf92f 100644 --- a/examples/display_button_color_properties.py +++ b/examples/display_button_color_properties.py @@ -41,7 +41,7 @@ # Make the display context splash = displayio.Group() -display.show(splash) +display.root_group = splash # Make the button button = Button( diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index 38ea90d..189af96 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -42,7 +42,7 @@ # Make the display context splash = displayio.Group() -display.show(splash) +display.root_group = splash BUTTON_WIDTH = 80 BUTTON_HEIGHT = 40 BUTTON_MARGIN = 20 diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index 6b975a3..fa388f3 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -39,7 +39,7 @@ # Make the display context splash = displayio.Group() -display.show(splash) +display.root_group = splash # Make the button button = Button( diff --git a/examples/display_button_spritebutton_simpletest.py b/examples/display_button_spritebutton_simpletest.py index 8f78c48..838ed30 100644 --- a/examples/display_button_spritebutton_simpletest.py +++ b/examples/display_button_spritebutton_simpletest.py @@ -20,7 +20,7 @@ # Make the display context main_group = displayio.Group() -board.DISPLAY.show(main_group) +board.DISPLAY.root_group = main_group BUTTON_WIDTH = 10 * 16 BUTTON_HEIGHT = 3 * 16 From 93cbd71ff46fdaee7fb43e102ad7493151f68389 Mon Sep 17 00:00:00 2001 From: Luke McNinch Date: Sun, 3 Dec 2023 14:39:07 -0500 Subject: [PATCH 097/137] Use label scale to when centering on button --- adafruit_button/button.py | 4 +++- adafruit_button/button_base.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 007a8f1..45c87f7 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -130,7 +130,8 @@ def __init__( label_color=0x0, selected_fill=None, selected_outline=None, - selected_label=None + selected_label=None, + label_scale=None ): super().__init__( x=x, @@ -142,6 +143,7 @@ def __init__( label_font=label_font, label_color=label_color, selected_label=selected_label, + label_scale=label_scale, ) self.body = self.fill = self.shadow = None diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index d33cfc4..3d4de0b 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -58,7 +58,8 @@ def __init__( label=None, label_font=None, label_color=0x0, - selected_label=None + selected_label=None, + label_scale=None ): super().__init__(x=x, y=y) self.x = x @@ -72,6 +73,7 @@ def __init__( self._label_color = label_color self._label_font = label_font self._selected_label = _check_color(selected_label) + self._label_scale = label_scale or 1 @property def label(self): @@ -89,14 +91,18 @@ def label(self, newtext): if not self._label_font: raise RuntimeError("Please provide label font") - self._label = Label(self._label_font, text=newtext) - dims = self._label.bounding_box + self._label = Label(self._label_font, text=newtext, scale=self._label_scale) + dims = list(self._label.bounding_box) + dims[2] *= self._label.scale + dims[3] *= self._label.scale if dims[2] >= self.width or dims[3] >= self.height: while len(self._label.text) > 1 and ( dims[2] >= self.width or dims[3] >= self.height ): self._label.text = "{}.".format(self._label.text[:-2]) dims = self._label.bounding_box + dims[2] *= self._label.scale + dims[3] *= self._label.scale if len(self._label.text) <= 1: raise RuntimeError("Button not large enough for label") self._label.x = (self.width - dims[2]) // 2 From 3f006d2e2b17d806051f6089cd30e1e26ff1e61e Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Oct 2023 14:30:31 -0500 Subject: [PATCH 098/137] unpin sphinx and add sphinx-rtd-theme to docs reqs Signed-off-by: foamyguy --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 797aa04..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx sphinxcontrib-jquery +sphinx-rtd-theme From ae43b151a0b5f4e5897f66745c255d4875e64940 Mon Sep 17 00:00:00 2001 From: Luke McNinch Date: Mon, 11 Dec 2023 20:32:23 -0500 Subject: [PATCH 099/137] Add label_scale option to SpriteButton --- adafruit_button/sprite_button.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index c2f02ba..037fcd4 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -56,7 +56,8 @@ def __init__( selected_label=None, bmp_path=None, selected_bmp_path=None, - transparent_index=None + transparent_index=None, + label_scale=None ): if bmp_path is None: raise ValueError("Please supply bmp_path. It cannot be None.") @@ -71,6 +72,7 @@ def __init__( label_font=label_font, label_color=label_color, selected_label=selected_label, + label_scale=label_scale ) self._bmp, self._bmp_palette = load(bmp_path) From 7ff41a3af0f549f167169cb3520c287a9605379e Mon Sep 17 00:00:00 2001 From: Luke McNinch Date: Mon, 11 Dec 2023 21:01:41 -0500 Subject: [PATCH 100/137] Fix a bug. dims should be converted from tuple to list. --- adafruit_button/button_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 3d4de0b..bcebc7e 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -100,7 +100,7 @@ def label(self, newtext): dims[2] >= self.width or dims[3] >= self.height ): self._label.text = "{}.".format(self._label.text[:-2]) - dims = self._label.bounding_box + dims = list(self._label.bounding_box) dims[2] *= self._label.scale dims[3] *= self._label.scale if len(self._label.text) <= 1: From c8e9f55799907363b02146c5e6f1a3e4ac57bdf5 Mon Sep 17 00:00:00 2001 From: Luke McNinch Date: Mon, 11 Dec 2023 21:06:41 -0500 Subject: [PATCH 101/137] Black fix --- adafruit_button/sprite_button.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index 037fcd4..67fd9ee 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -72,7 +72,7 @@ def __init__( label_font=label_font, label_color=label_color, selected_label=selected_label, - label_scale=label_scale + label_scale=label_scale, ) self._bmp, self._bmp_palette = load(bmp_path) From 5d2cb43fc8619ba9a0afaa6351739fb6bee36d92 Mon Sep 17 00:00:00 2001 From: DJDevon3 <49322231+DJDevon3@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:44:59 -0500 Subject: [PATCH 102/137] add sprite_button example for TFT Featherwing simple menu button demo specifically for TFT featherwing touch display --- ...prite_button_tft_featherwing_simpletest.py | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 examples/sprite_button_tft_featherwing_simpletest.py diff --git a/examples/sprite_button_tft_featherwing_simpletest.py b/examples/sprite_button_tft_featherwing_simpletest.py new file mode 100644 index 0000000..ed25edf --- /dev/null +++ b/examples/sprite_button_tft_featherwing_simpletest.py @@ -0,0 +1,73 @@ +import displayio +import terminalio +import board +import digitalio +import time +from adafruit_hx8357 import HX8357 # TFT Featherwing display driver +import adafruit_stmpe610 # TFT Featherwing V1 touch driver +from adafruit_display_text import label +from adafruit_bitmap_font import bitmap_font +from adafruit_button.sprite_button import SpriteButton + +# 3.5" TFT Featherwing is 480x320 +displayio.release_displays() +DISPLAY_WIDTH = 480 +DISPLAY_HEIGHT = 320 + +# Initialize TFT Display +spi = board.SPI() +tft_cs = board.D9 +tft_dc = board.D10 +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) +display = HX8357(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT) +display.rotation = 0 +_touch_flip = (False, True) + +# Initialize 3.5" TFT Featherwing Touchscreen +ts_cs_pin = digitalio.DigitalInOut(board.D6) +touchscreen = adafruit_stmpe610.Adafruit_STMPE610_SPI( + board.SPI(), + ts_cs_pin, + calibration=((231, 3703), (287, 3787)), + size=(display.width, display.height), + disp_rotation=display.rotation, + touch_flip=_touch_flip, +) + +TEXT_WHITE = 0xFFFFFF + +# --| Button Config |-- +BUTTON_WIDTH = 7 * 16 +BUTTON_HEIGHT = 2 * 16 +BUTTON_MARGIN = 5 + +# Defiine the button +button = SpriteButton( + x=BUTTON_MARGIN, + y=BUTTON_MARGIN, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="MENU", + label_font=terminalio.FONT, + label_color=TEXT_WHITE, + bmp_path="icons/gradient_button_0.bmp", + selected_bmp_path="icons/gradient_button_1.bmp", + transparent_index=0, +) + +main_group = displayio.Group() +main_group.append(button) +display.root_group = main_group + +while True: + p = touchscreen.touch_point + if p: + if button.contains(p): + if not button.selected: + button.selected = True + time.sleep(0.25) # Wait a bit so we can see the button color change + print("Button Pressed") + else: + button.selected = False # When touch moves outside of button + else: + button.selected = False # When button is released \ No newline at end of file From 6c1d2bed719ebbf2a428fae7266e1c700c54d215 Mon Sep 17 00:00:00 2001 From: DJDevon3 <49322231+DJDevon3@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:53:31 -0500 Subject: [PATCH 103/137] make pylint happy --- examples/sprite_button_tft_featherwing_simpletest.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/sprite_button_tft_featherwing_simpletest.py b/examples/sprite_button_tft_featherwing_simpletest.py index ed25edf..f30e63e 100644 --- a/examples/sprite_button_tft_featherwing_simpletest.py +++ b/examples/sprite_button_tft_featherwing_simpletest.py @@ -1,12 +1,10 @@ +import time import displayio import terminalio import board import digitalio -import time from adafruit_hx8357 import HX8357 # TFT Featherwing display driver import adafruit_stmpe610 # TFT Featherwing V1 touch driver -from adafruit_display_text import label -from adafruit_bitmap_font import bitmap_font from adafruit_button.sprite_button import SpriteButton # 3.5" TFT Featherwing is 480x320 @@ -65,9 +63,9 @@ if button.contains(p): if not button.selected: button.selected = True - time.sleep(0.25) # Wait a bit so we can see the button color change + time.sleep(0.25) # Wait a bit so we can see the button color change print("Button Pressed") else: button.selected = False # When touch moves outside of button else: - button.selected = False # When button is released \ No newline at end of file + button.selected = False # When button is released From bce89bfeb29e68a2d5ab9e0e852e838adbbeab47 Mon Sep 17 00:00:00 2001 From: DJDevon3 <49322231+DJDevon3@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:57:16 -0500 Subject: [PATCH 104/137] included header copyright --- examples/sprite_button_tft_featherwing_simpletest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/sprite_button_tft_featherwing_simpletest.py b/examples/sprite_button_tft_featherwing_simpletest.py index f30e63e..dab7675 100644 --- a/examples/sprite_button_tft_featherwing_simpletest.py +++ b/examples/sprite_button_tft_featherwing_simpletest.py @@ -1,3 +1,5 @@ +# SPDX-FileCopyrightText: 2024 DJDevon3 +# SPDX-License-Identifier: MIT import time import displayio import terminalio From 5cf970e7c16857317f6877f9aab9a16e32005708 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 28 Jan 2024 17:56:44 -0600 Subject: [PATCH 105/137] rename, use bmps dir for paths --- ...display_button_spritebutton_tft_featherwing_simpletest.py} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename examples/{sprite_button_tft_featherwing_simpletest.py => display_button_spritebutton_tft_featherwing_simpletest.py} (95%) diff --git a/examples/sprite_button_tft_featherwing_simpletest.py b/examples/display_button_spritebutton_tft_featherwing_simpletest.py similarity index 95% rename from examples/sprite_button_tft_featherwing_simpletest.py rename to examples/display_button_spritebutton_tft_featherwing_simpletest.py index dab7675..bac2cf7 100644 --- a/examples/sprite_button_tft_featherwing_simpletest.py +++ b/examples/display_button_spritebutton_tft_featherwing_simpletest.py @@ -50,8 +50,8 @@ label="MENU", label_font=terminalio.FONT, label_color=TEXT_WHITE, - bmp_path="icons/gradient_button_0.bmp", - selected_bmp_path="icons/gradient_button_1.bmp", + bmp_path="bmps/gradient_button_0.bmp", + selected_bmp_path="bmps/gradient_button_1.bmp", transparent_index=0, ) From 3c36a115b70c6a71d70c00c17e09cc8d0100971d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 106/137] remove deprecated get_html_theme_path() call Signed-off-by: foamyguy --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index c98d9f2..8e24264 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -104,7 +104,6 @@ import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # 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, From 70db215c637fc283bd3bf168025f82c8eb58e0a3 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 26 Oct 2024 10:30:41 -0500 Subject: [PATCH 107/137] fix null error from label property / resize --- .pre-commit-config.yaml | 2 +- .pylintrc | 2 +- adafruit_button/button_base.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70ade69..374676d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.17.4 + rev: v3.3.1 hooks: - id: pylint name: pylint (library code) diff --git a/.pylintrc b/.pylintrc index f945e92..fe3f21d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -361,7 +361,7 @@ valid-metaclass-classmethod-first-arg=mcs [DESIGN] # Maximum number of arguments for function / method -max-args=5 +max-args=18 # Maximum number of attributes for a class (see R0902). # max-attributes=7 diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index bcebc7e..030f3d6 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -78,7 +78,9 @@ def __init__( @property def label(self): """The text label of the button""" - return self._label.text + if self._label is not None and hasattr(self._label, "text"): + return self._label.text + return None @label.setter def label(self, newtext): From e3e4c242138dfd4169323418ac05c384d5e5b79e Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 13 Nov 2024 15:50:47 -0600 Subject: [PATCH 108/137] use getattr --- adafruit_button/button_base.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 030f3d6..8a7709c 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -78,9 +78,7 @@ def __init__( @property def label(self): """The text label of the button""" - if self._label is not None and hasattr(self._label, "text"): - return self._label.text - return None + return getattr(self._label, "text", None) @label.setter def label(self, newtext): From 89e804b08065c9000c6b89318bf07ef7dd843df8 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Tue, 26 Nov 2024 12:32:32 -0600 Subject: [PATCH 109/137] button_base annotations in place Added annotations for the various functions. Corrected some documentation errors as well, regarding what the selected_label actually does. Additionally added terminalio.FONT as the default font. --- adafruit_button/button_base.py | 72 ++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 8a7709c..9d76b11 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -22,9 +22,15 @@ """ from adafruit_display_text.bitmap_label import Label from displayio import Group +import terminalio +try: + from typing import Optional, Union, List, Tuple, Any + from fontio import FontProtocol +except ImportError: + pass -def _check_color(color): +def _check_color(color: Optional[Union[int, tuple[int, int, int]]]) -> Optional[int]: # if a tuple is supplied, convert it to a RGB number if isinstance(color, tuple): r, g, b = color @@ -36,31 +42,31 @@ class ButtonBase(Group): # pylint: disable=too-many-instance-attributes """Superclass for creating UI buttons for ``displayio``. - :param x: The x position of the button. - :param y: The y position of the button. - :param width: The width of the button in tiles. - :param height: The height of the button in tiles. - :param name: A name, or miscellaneous string that is stored on the button. - :param label: The text that appears inside the button. Defaults to not displaying the label. - :param label_font: The button label font. - :param label_color: The color of the button label text. Defaults to 0x0. - :param selected_label: Text that appears when selected + :param int x: The x position of the button. + :param int y: The y position of the button. + :param int width: The width of the button in tiles. + :param int height: The height of the button in tiles. + :param str name: A name, or miscellaneous string that is stored on the button. + :param str label: The text that appears inside the button. Defaults to not displaying the label. + :param FontProtocol label_font: The button label font. + :param int label_color: The color of the button label text. Defaults to 0x0. + :param selected_label: The color of button label text when the button is selected. """ def __init__( self, *, - x, - y, - width, - height, - name=None, - label=None, - label_font=None, - label_color=0x0, - selected_label=None, - label_scale=None - ): + x: int, + y: int, + width: int, + height: int, + name: Optional[str] = None, + label: Optional[str] = None, + label_font: Optional[FontProtocol] = None, + label_color: Optional[int] = 0x0, + selected_label: Optional[Union[int, tuple[int, int, int]]] = None, + label_scale: Optional[int] = 1, + ) -> None: super().__init__(x=x, y=y) self.x = x self.y = y @@ -73,15 +79,15 @@ def __init__( self._label_color = label_color self._label_font = label_font self._selected_label = _check_color(selected_label) - self._label_scale = label_scale or 1 + self._label_scale = label_scale @property - def label(self): + def label(self) -> Optional[Tuple[str, str]]: """The text label of the button""" return getattr(self._label, "text", None) @label.setter - def label(self, newtext): + def label(self, newtext: str) -> None: if self._label and self and (self[-1] == self._label): self.pop() @@ -90,7 +96,7 @@ def label(self, newtext): return # nothing to do! if not self._label_font: - raise RuntimeError("Please provide label font") + self._label_font = terminalio.FONT self._label = Label(self._label_font, text=newtext, scale=self._label_scale) dims = list(self._label.bounding_box) dims[2] *= self._label.scale @@ -115,17 +121,17 @@ def label(self, newtext): if (self.selected_label is None) and (self._label_color is not None): self.selected_label = (~self._label_color) & 0xFFFFFF - def _subclass_selected_behavior(self, value): - # Subclasses should overide this! + def _subclass_selected_behavior(self, value: Optional[Any]) -> None: + # Subclasses should override this! pass @property - def selected(self): + def selected(self) -> bool: """Selected inverts the colors.""" return self._selected @selected.setter - def selected(self, value): + def selected(self, value: bool) -> None: if value == self._selected: return # bail now, nothing more to do self._selected = value @@ -140,20 +146,20 @@ def selected(self, value): self._subclass_selected_behavior(value) @property - def selected_label(self): + def selected_label(self) -> int: """The font color of the button when selected""" return self._selected_label @selected_label.setter - def selected_label(self, new_color): + def selected_label(self, new_color: int) -> None: self._selected_label = _check_color(new_color) @property - def label_color(self): + def label_color(self) -> int: """The font color of the button""" return self._label_color @label_color.setter - def label_color(self, new_color): + def label_color(self, new_color: int) -> None: self._label_color = _check_color(new_color) self._label.color = self._label_color From fdf13e9a170d8db5341cd79ad6019ca3680071f3 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:10:05 -0600 Subject: [PATCH 110/137] Add more annotations, improve documentation Added type annotations for button.py, as well as correcting/updating documentation. --- adafruit_button/button.py | 109 ++++++++++++++++++--------------- adafruit_button/button_base.py | 22 ++++--- 2 files changed, 73 insertions(+), 58 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 45c87f7..5f31705 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -26,36 +26,49 @@ from adafruit_display_shapes.roundrect import RoundRect from adafruit_button.button_base import ButtonBase, _check_color +try: + from typing import Optional, Union, Tuple, Any, List + from fontio import FontProtocol +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Button.git" class Button(ButtonBase): # pylint: disable=too-many-instance-attributes, too-many-locals - """Helper class for creating UI buttons for ``displayio``. - - :param x: The x position of the button. - :param y: The y position of the button. - :param width: The width of the button in pixels. - :param height: The height of the button in pixels. - :param name: The name of the button. + """Helper class for creating UI buttons for ``displayio``. Provides the following + buttons: + RECT: A rectangular button. SHAWDOWRECT adds a drop shadow. + ROUNDRECT: A rectangular button with rounded corners. SHADOWROUNDRECT adds + a drop shadow. + + :param int x: The x position of the button. + :param int y: The y position of the button. + :param int width: The width of the button in pixels. + :param int height: The height of the button in pixels. + :param str name: The name of the button. :param style: The style of the button. Can be RECT, ROUNDRECT, SHADOWRECT, SHADOWROUNDRECT. Defaults to RECT. - :param fill_color: The color to fill the button. Defaults to 0xFFFFFF. - :param outline_color: The color of the outline of the button. - :param label: The text that appears inside the button. Defaults to not displaying the label. - :param label_font: The button label font. - :param label_color: The color of the button label text. Defaults to 0x0. - :param selected_fill: Inverts the fill color. - :param selected_outline: Inverts the outline color. - :param selected_label: Inverts the label color. + :param int|Tuple(int, int, int) fill_color: The color to fill the button. Defaults to 0xFFFFFF. + :param int|Tuple(int, int, int) outline_color: The color of the outline of the button. + :param str label: The text that appears inside the button. Defaults to not displaying the label. + :param FontProtocol label_font: The button label font. Defaults to terminalio.FONT + :param int|Tuple(int, int, int) label_color: The color of the button label text. Defaults to 0x0. + :param int|Tuple(int, int, int) selected_fill: The fill color when the button is selected. + Defaults to the inverse of the fill_color. + :param int|Tuple(int, int, int) selected_outline: The outline color when the button is selected. + Defaults to the inverse of outline_color. + :param selected_label: The label color when the button is selected. + Defaults to inverting the label_color. """ - def _empty_self_group(self): + def _empty_self_group(self) -> None: while len(self) > 0: self.pop() - def _create_body(self): + def _create_body(self) -> None: if (self.outline_color is not None) or (self.fill_color is not None): if self.style == Button.RECT: self.body = Rect( @@ -117,21 +130,21 @@ def _create_body(self): def __init__( self, *, - x, - y, - width, - height, - name=None, - style=RECT, - fill_color=0xFFFFFF, - outline_color=0x0, - label=None, - label_font=None, - label_color=0x0, - selected_fill=None, - selected_outline=None, - selected_label=None, - label_scale=None + x: int, + y: int, + width: int, + height: int, + name: Optional[str] = None, + style = RECT, + fill_color: Optional[Union[int, tuple[int, int, int]]] = 0xFFFFFF, + outline_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, + label: Optional[str] = None, + label_font: Optional[FontProtocol] = None, + label_color: Optional[int] = 0x0, + selected_fill: Optional[Union[int, tuple[int, int , int]]] = None, + selected_outline: Optional[Union[int, tuple[int, int, int]]] = None, + selected_label: Optional[Union[int, tuple[int, int, int]]] = None, + label_scale: Optional[int] = 1 ): super().__init__( x=x, @@ -167,7 +180,7 @@ def __init__( self.label = label - def _subclass_selected_behavior(self, value): + def _subclass_selected_behavior(self, value: Optional[Any]) -> None: if self._selected: new_fill = self.selected_fill new_out = self.selected_outline @@ -180,7 +193,7 @@ def _subclass_selected_behavior(self, value): self.body.outline = new_out @property - def group(self): + def group(self) -> "Button": """Return self for compatibility with old API.""" print( "Warning: The group property is being deprecated. " @@ -189,7 +202,7 @@ def group(self): ) return self - def contains(self, point): + def contains(self, point: List[int]) -> bool: """Used to determine if a point is contained within a button. For example, ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for determining that a button has been touched. @@ -199,56 +212,56 @@ def contains(self, point): ) @property - def fill_color(self): + def fill_color(self) -> Optional[int]: """The fill color of the button body""" return self._fill_color @fill_color.setter - def fill_color(self, new_color): + def fill_color(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: self._fill_color = _check_color(new_color) if not self.selected: self.body.fill = self._fill_color @property - def outline_color(self): + def outline_color(self) -> Optional[int]: """The outline color of the button body""" return self._outline_color @outline_color.setter - def outline_color(self, new_color): + def outline_color(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: self._outline_color = _check_color(new_color) if not self.selected: self.body.outline = self._outline_color @property - def selected_fill(self): + def selected_fill(self) -> Optional[int]: """The fill color of the button body when selected""" return self._selected_fill @selected_fill.setter - def selected_fill(self, new_color): + def selected_fill(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: self._selected_fill = _check_color(new_color) if self.selected: self.body.fill = self._selected_fill @property - def selected_outline(self): + def selected_outline(self) -> Optional[int]: """The outline color of the button body when selected""" return self._selected_outline @selected_outline.setter - def selected_outline(self, new_color): + def selected_outline(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: self._selected_outline = _check_color(new_color) if self.selected: self.body.outline = self._selected_outline @property - def width(self): + def width(self) -> int: """The width of the button""" return self._width @width.setter - def width(self, new_width): + def width(self, new_width: int) -> None: self._width = new_width self._empty_self_group() self._create_body() @@ -257,12 +270,12 @@ def width(self, new_width): self.label = self.label @property - def height(self): + def height(self) -> int: """The height of the button""" return self._height @height.setter - def height(self, new_height): + def height(self, new_height: int) -> None: self._height = new_height self._empty_self_group() self._create_body() @@ -270,7 +283,7 @@ def height(self, new_height): self.append(self.body) self.label = self.label - def resize(self, new_width, new_height): + def resize(self, new_width: int, new_height: int) -> None: """Resize the button to the new width and height given :param new_width int the desired width :param new_height int the desired height diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 9d76b11..d7bd329 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -24,7 +24,7 @@ from displayio import Group import terminalio try: - from typing import Optional, Union, List, Tuple, Any + from typing import Optional, Union, Tuple, Any from fontio import FontProtocol except ImportError: pass @@ -48,9 +48,10 @@ class ButtonBase(Group): :param int height: The height of the button in tiles. :param str name: A name, or miscellaneous string that is stored on the button. :param str label: The text that appears inside the button. Defaults to not displaying the label. - :param FontProtocol label_font: The button label font. - :param int label_color: The color of the button label text. Defaults to 0x0. - :param selected_label: The color of button label text when the button is selected. + :param FontProtocol label_font: The button label font. Defaults to terminalio.FONT + :param int|Tuple(int, int, int) label_color: The color of the button label text. Defaults to 0x0. + :param int|Tuple(int, int, int) selected_label: The color of button label text when the button is selected. + :param int label_scale: The scale factor used for the label. Defaults to 1. """ def __init__( @@ -127,7 +128,7 @@ def _subclass_selected_behavior(self, value: Optional[Any]) -> None: @property def selected(self) -> bool: - """Selected inverts the colors.""" + """Returns whether the button is selected.""" return self._selected @selected.setter @@ -146,20 +147,21 @@ def selected(self, value: bool) -> None: self._subclass_selected_behavior(value) @property - def selected_label(self) -> int: - """The font color of the button when selected""" + def selected_label(self) -> Optional[Union[int, tuple[int, int, int]]]: + """The font color of the button when selected. + If no color is specified it defaults to the inverse of the label_color""" return self._selected_label @selected_label.setter - def selected_label(self, new_color: int) -> None: + def selected_label(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: self._selected_label = _check_color(new_color) @property - def label_color(self) -> int: + def label_color(self) -> Optional[Union[int, tuple[int, int, int]]]: """The font color of the button""" return self._label_color @label_color.setter - def label_color(self, new_color: int) -> None: + def label_color(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: self._label_color = _check_color(new_color) self._label.color = self._label_color From 94e60a7b018b5ae46f9846fef3742f91bc987d8b Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:25:21 -0600 Subject: [PATCH 111/137] Type annotations to SpriteButton, Further documentation changes. Completed type annotations for the sprite_button.py file as well as further improvements to documentation. --- adafruit_button/button.py | 4 +- adafruit_button/button_base.py | 13 ++++-- adafruit_button/sprite_button.py | 80 ++++++++++++++++++-------------- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 5f31705..6940a10 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -53,8 +53,8 @@ class Button(ButtonBase): Defaults to RECT. :param int|Tuple(int, int, int) fill_color: The color to fill the button. Defaults to 0xFFFFFF. :param int|Tuple(int, int, int) outline_color: The color of the outline of the button. - :param str label: The text that appears inside the button. Defaults to not displaying the label. - :param FontProtocol label_font: The button label font. Defaults to terminalio.FONT + :param str label: The text that appears inside the button. + :param FontProtocol label_font: The button label font. Defaults to ''terminalio.FONT'' :param int|Tuple(int, int, int) label_color: The color of the button label text. Defaults to 0x0. :param int|Tuple(int, int, int) selected_fill: The fill color when the button is selected. Defaults to the inverse of the fill_color. diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index d7bd329..9131229 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -1,4 +1,5 @@ # SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries +# SPDX-FileCopyrightText: 2024 Channing Ramos # # SPDX-License-Identifier: MIT @@ -9,7 +10,7 @@ UI Buttons for displayio -* Author(s): Limor Fried +* Author(s): Limor Fried, Channing Ramos Implementation Notes -------------------- @@ -47,10 +48,12 @@ class ButtonBase(Group): :param int width: The width of the button in tiles. :param int height: The height of the button in tiles. :param str name: A name, or miscellaneous string that is stored on the button. - :param str label: The text that appears inside the button. Defaults to not displaying the label. - :param FontProtocol label_font: The button label font. Defaults to terminalio.FONT - :param int|Tuple(int, int, int) label_color: The color of the button label text. Defaults to 0x0. + :param str label: The text that appears inside the button. + :param FontProtocol label_font: The button label font. Defaults to ''terminalio.FONT'' + :param int|Tuple(int, int, int) label_color: The color of the button label text. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. :param int|Tuple(int, int, int) selected_label: The color of button label text when the button is selected. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to an inverse of label_color. :param int label_scale: The scale factor used for the label. Defaults to 1. """ @@ -83,7 +86,7 @@ def __init__( self._label_scale = label_scale @property - def label(self) -> Optional[Tuple[str, str]]: + def label(self) -> Optional[str]: """The text label of the button""" return getattr(self._label, "text", None) diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index 67fd9ee..d9ab283 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -1,4 +1,5 @@ # SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries +# SPDX-FileCopyrightText: 2024 Channing Ramos # # SPDX-License-Identifier: MIT @@ -9,7 +10,7 @@ Bitmap 3x3 Spritesheet based UI Button for displayio -* Author(s): Tim Cocks +* Author(s): Tim Cocks, Channing Ramos Implementation Notes -------------------- @@ -24,40 +25,51 @@ from adafruit_imageload import load from adafruit_button.button_base import ButtonBase +try: + from typing import Optional, Union, Tuple, Any, List + from fontio import FontProtocol +except ImportError: + pass class SpriteButton(ButtonBase): - """Helper class for creating 3x3 Bitmap Spritesheet UI buttons for ``displayio``. - - :param x: The x position of the button. - :param y: The y position of the button. - :param width: The width of the button in tiles. - :param height: The height of the button in tiles. - :param name: A name, or miscellaneous string that is stored on the button. - :param label: The text that appears inside the button. Defaults to not displaying the label. - :param label_font: The button label font. - :param label_color: The color of the button label text. Defaults to 0x0. - :param selected_label: Text that appears when selected - :param string bmp_path: The path of the 3x3 spritesheet Bitmap file - :param string selected_bmp_path: The path of the 3x3 spritesheet Bitmap file to use when pressed - :param int or tuple transparent_index: Index(s) that will be made transparent on the Palette + """Helper class for creating 3x3 Bitmap Spritesheet UI buttons for ``displayio``. Compatible with any format + supported by ''adafruit_imageload''. + + :param int x: The x position of the button. + :param int y: The y position of the button. + :param int width: The width of the button in tiles. + :param int height: The height of the button in tiles. + :param Optional[str] name: A name, or miscellaneous string that is stored on the button. + :param Optional[str] label: The text that appears inside the button. + :param Optional[FontProtocol] label_font: The button label font. + :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the button label text. Accepts either + an integer or a tuple of 3 integers representing RGB values. Defaults to 0x0. + :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The color of the button label text when the button + is selected. Accepts either an integer or a tuple of 3 integers representing RGB values. Defaults to the inverse of + label_color. + :param str bmp_path: The path of the 3x3 spritesheet mage file + :param Optional[str] selected_bmp_path: The path of the 3x3 spritesheet image file to use when pressed + :param Optional[Union[int, Tuple]] transparent_index: Palette index(s) that will be set to transparent. PNG files have these index(s) + set automatically. Not compatible with JPG files. + :param Optional[int] label_scale: The scale multiplier of the button label. Defaults to 1. """ def __init__( self, *, - x, - y, - width, - height, - name=None, - label=None, - label_font=None, - label_color=0x0, - selected_label=None, - bmp_path=None, - selected_bmp_path=None, - transparent_index=None, - label_scale=None + x: int, + y: int, + width: int, + height: int, + name: Optional[str] = None, + label: Optional[str] = None, + label_font: Optional[FontProtocol] = None, + label_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, + selected_label: Optional[Union[int, tuple[int, int, int]]] = None, + bmp_path: str = None, + selected_bmp_path: Optional[str] = None, + transparent_index: Optional[Union[int, tuple]] = None, + label_scale: Optional[int] = 1 ): if bmp_path is None: raise ValueError("Please supply bmp_path. It cannot be None.") @@ -104,16 +116,16 @@ def __init__( self.label = label @property - def width(self): - """The width of the button""" + def width(self) -> int: + """The width of the button. Read-Only""" return self._width @property - def height(self): - """The height of the button""" + def height(self) -> int: + """The height of the button. Read-Only""" return self._height - def contains(self, point): + def contains(self, point: list[int]) -> bool: """Used to determine if a point is contained within a button. For example, ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for determining that a button has been touched. @@ -122,7 +134,7 @@ def contains(self, point): self.y <= point[1] <= self.y + self.height ) - def _subclass_selected_behavior(self, value): + def _subclass_selected_behavior(self, value: Optional[Any]) -> None: if self._selected: if self._selected_bmp is not None: self._btn_tilegrid.bitmap = self._selected_bmp From 86c6491aa69ab632b3b63e7ef0c0c6fa7dad91d7 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:32:09 -0600 Subject: [PATCH 112/137] Annotations correction Corrected some wrong annotations. --- adafruit_button/button_base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 9131229..830dc13 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -150,21 +150,21 @@ def selected(self, value: bool) -> None: self._subclass_selected_behavior(value) @property - def selected_label(self) -> Optional[Union[int, tuple[int, int, int]]]: + def selected_label(self) -> int: """The font color of the button when selected. If no color is specified it defaults to the inverse of the label_color""" return self._selected_label @selected_label.setter - def selected_label(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: + def selected_label(self, new_color: Union[int, tuple[int, int, int]]) -> None: self._selected_label = _check_color(new_color) @property - def label_color(self) -> Optional[Union[int, tuple[int, int, int]]]: + def label_color(self) -> int: """The font color of the button""" return self._label_color @label_color.setter - def label_color(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: + def label_color(self, new_color: Union[int, tuple[int, int, int]]) -> None: self._label_color = _check_color(new_color) self._label.color = self._label_color From 11a570c3ab232f3f02bd6564c5b8cc3adcf783e9 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Wed, 27 Nov 2024 19:49:31 -0600 Subject: [PATCH 113/137] Second Documentation Pass --- adafruit_button/button_base.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 830dc13..8854b67 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -31,7 +31,7 @@ pass -def _check_color(color: Optional[Union[int, tuple[int, int, int]]]) -> Optional[int]: +def _check_color(color: Optional[Union[int, tuple[int, int, int]]]) -> int: # if a tuple is supplied, convert it to a RGB number if isinstance(color, tuple): r, g, b = color @@ -47,14 +47,13 @@ class ButtonBase(Group): :param int y: The y position of the button. :param int width: The width of the button in tiles. :param int height: The height of the button in tiles. - :param str name: A name, or miscellaneous string that is stored on the button. - :param str label: The text that appears inside the button. - :param FontProtocol label_font: The button label font. Defaults to ''terminalio.FONT'' - :param int|Tuple(int, int, int) label_color: The color of the button label text. - Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. - :param int|Tuple(int, int, int) selected_label: The color of button label text when the button is selected. + :param Optional[str] name: A name, or miscellaneous string that is stored on the button. + :param Optional[str] label: The text that appears inside the button. + :param Optional[FontProtocol] label_font: The button label font. Defaults to ''terminalio.FONT'' + :param Optional[int] label_color: The color of the button label text. Defaults to 0x0. + :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The color of button label text when the button is selected. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to an inverse of label_color. - :param int label_scale: The scale factor used for the label. Defaults to 1. + :param Optional[int] label_scale: The scale factor used for the label. Defaults to 1. """ def __init__( From ae6ced5c49781daa75d55614be6adf65cb33f774 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Wed, 27 Nov 2024 19:56:30 -0600 Subject: [PATCH 114/137] Updated label_color for compatibility label_color now accepts a tuple as well as an int for color, bringing its behavior in line with selected_label --- adafruit_button/button_base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 8854b67..54ed1c6 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -50,7 +50,8 @@ class ButtonBase(Group): :param Optional[str] name: A name, or miscellaneous string that is stored on the button. :param Optional[str] label: The text that appears inside the button. :param Optional[FontProtocol] label_font: The button label font. Defaults to ''terminalio.FONT'' - :param Optional[int] label_color: The color of the button label text. Defaults to 0x0. + :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the button label text. Defaults to 0x0. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to an inverse of label_color. :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The color of button label text when the button is selected. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to an inverse of label_color. :param Optional[int] label_scale: The scale factor used for the label. Defaults to 1. @@ -66,7 +67,7 @@ def __init__( name: Optional[str] = None, label: Optional[str] = None, label_font: Optional[FontProtocol] = None, - label_color: Optional[int] = 0x0, + label_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, selected_label: Optional[Union[int, tuple[int, int, int]]] = None, label_scale: Optional[int] = 1, ) -> None: @@ -79,7 +80,7 @@ def __init__( self._selected = False self.name = name self._label = label - self._label_color = label_color + self._label_color = _check_color(label_color) self._label_font = label_font self._selected_label = _check_color(selected_label) self._label_scale = label_scale From 252cf7d4a3e0a645514f0ada2d17a6e897845978 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Sun, 1 Dec 2024 13:59:42 -0600 Subject: [PATCH 115/137] Button.py second pass Second pass to finalize changes --- adafruit_button/button.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 6940a10..b15d683 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -48,20 +48,24 @@ class Button(ButtonBase): :param int y: The y position of the button. :param int width: The width of the button in pixels. :param int height: The height of the button in pixels. - :param str name: The name of the button. + :param Optional[str] name: The name of the button. :param style: The style of the button. Can be RECT, ROUNDRECT, SHADOWRECT, SHADOWROUNDRECT. Defaults to RECT. - :param int|Tuple(int, int, int) fill_color: The color to fill the button. Defaults to 0xFFFFFF. - :param int|Tuple(int, int, int) outline_color: The color of the outline of the button. - :param str label: The text that appears inside the button. - :param FontProtocol label_font: The button label font. Defaults to ''terminalio.FONT'' - :param int|Tuple(int, int, int) label_color: The color of the button label text. Defaults to 0x0. - :param int|Tuple(int, int, int) selected_fill: The fill color when the button is selected. - Defaults to the inverse of the fill_color. - :param int|Tuple(int, int, int) selected_outline: The outline color when the button is selected. - Defaults to the inverse of outline_color. - :param selected_label: The label color when the button is selected. - Defaults to inverting the label_color. + :param Optional[Union[int, Tuple[int, int, int]]] fill_color: The color to fill the button. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0xFFFFFF. + :param Optional[Union[int, Tuple[int, int, int]]] outline_color: The color of the outline of the button. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. + :param Optional[str] label: The text that appears inside the button. + :param Optional[FontProtocol] label_font: The button label font. Defaults to ''terminalio.FONT'' + :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the button label text. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. + :param Optional[Union[int, Tuple[int, int, int]]] selected_fill: The fill color when the button is selected. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to the inverse of the fill_color. + :param Optional[Union[int, Tuple[int, int, int]]] selected_outline: The outline color when the button is selected. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to the inverse of outline_color. + :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The label color when the button is selected. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to inverting the label_color. + :param Optional[int] label_scale: The scale factor used for the label. Defaults to 1. """ def _empty_self_group(self) -> None: @@ -140,7 +144,7 @@ def __init__( outline_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, label: Optional[str] = None, label_font: Optional[FontProtocol] = None, - label_color: Optional[int] = 0x0, + label_color: Optional[Union[int, tuple[int, int , int]]] = 0x0, selected_fill: Optional[Union[int, tuple[int, int , int]]] = None, selected_outline: Optional[Union[int, tuple[int, int, int]]] = None, selected_label: Optional[Union[int, tuple[int, int, int]]] = None, @@ -217,7 +221,7 @@ def fill_color(self) -> Optional[int]: return self._fill_color @fill_color.setter - def fill_color(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: + def fill_color(self, new_color: Union[int, tuple[int, int, int]]) -> None: self._fill_color = _check_color(new_color) if not self.selected: self.body.fill = self._fill_color @@ -228,7 +232,7 @@ def outline_color(self) -> Optional[int]: return self._outline_color @outline_color.setter - def outline_color(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: + def outline_color(self, new_color: Union[int, tuple[int, int, int]]) -> None: self._outline_color = _check_color(new_color) if not self.selected: self.body.outline = self._outline_color @@ -239,7 +243,7 @@ def selected_fill(self) -> Optional[int]: return self._selected_fill @selected_fill.setter - def selected_fill(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: + def selected_fill(self, new_color: Union[int, tuple[int, int, int]]) -> None: self._selected_fill = _check_color(new_color) if self.selected: self.body.fill = self._selected_fill @@ -250,7 +254,7 @@ def selected_outline(self) -> Optional[int]: return self._selected_outline @selected_outline.setter - def selected_outline(self, new_color: Optional[Union[int, tuple[int, int, int]]]) -> None: + def selected_outline(self, new_color: Union[int, tuple[int, int, int]]) -> None: self._selected_outline = _check_color(new_color) if self.selected: self.body.outline = self._selected_outline From acb718a1b58c90b8551d4174bb61f79a672c8b90 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Sun, 1 Dec 2024 14:02:58 -0600 Subject: [PATCH 116/137] Fixed transparent_index The transparent index is now set to the index number given, rather than just using 0. --- adafruit_button/sprite_button.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index d9ab283..8dabb80 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -100,7 +100,7 @@ def __init__( for _index in transparent_index: self._selected_bmp_palette.make_transparent(_index) elif isinstance(transparent_index, int): - self._selected_bmp_palette.make_transparent(0) + self._selected_bmp_palette.make_transparent(transparent_index) self._btn_tilegrid = inflate_tilegrid( bmp_obj=self._bmp, From a11ed732f2d16678eaebfaa7d78a60869f40aa4d Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Sun, 1 Dec 2024 15:22:09 -0600 Subject: [PATCH 117/137] Update Licensing Added my name to the licensing portion. --- adafruit_button/button.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index b15d683..d86a7b2 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -1,4 +1,5 @@ # SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries +# SPDX-FileCopyrightText: 2024 Channing Ramos # # SPDX-License-Identifier: MIT @@ -9,7 +10,7 @@ UI Buttons for displayio -* Author(s): Limor Fried +* Author(s): Limor Fried, Channing Ramos Implementation Notes -------------------- From b2759a25e0897879e3a6f949d6005bced183dcd2 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Sun, 1 Dec 2024 15:47:32 -0600 Subject: [PATCH 118/137] Formatting Correction - button.py Correct formatting errors for the button.py file to pass ruff checks. --- adafruit_button/button.py | 43 +++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index d86a7b2..333b2eb 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -54,18 +54,21 @@ class Button(ButtonBase): Defaults to RECT. :param Optional[Union[int, Tuple[int, int, int]]] fill_color: The color to fill the button. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0xFFFFFF. - :param Optional[Union[int, Tuple[int, int, int]]] outline_color: The color of the outline of the button. - Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. + :param Optional[Union[int, Tuple[int, int, int]]] outline_color: The color of the outline of the + button. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. :param Optional[str] label: The text that appears inside the button. :param Optional[FontProtocol] label_font: The button label font. Defaults to ''terminalio.FONT'' - :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the button label text. - Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. - :param Optional[Union[int, Tuple[int, int, int]]] selected_fill: The fill color when the button is selected. - Accepts an int or a tuple of 3 integers representing RGB values. Defaults to the inverse of the fill_color. - :param Optional[Union[int, Tuple[int, int, int]]] selected_outline: The outline color when the button is selected. - Accepts an int or a tuple of 3 integers representing RGB values. Defaults to the inverse of outline_color. - :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The label color when the button is selected. - Accepts an int or a tuple of 3 integers representing RGB values. Defaults to inverting the label_color. + :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the button label + text. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. + :param Optional[Union[int, Tuple[int, int, int]]] selected_fill: The fill color when the + button is selected. Accepts an int or a tuple of 3 integers representing RGB values. + Defaults to the inverse of the fill_color. + :param Optional[Union[int, Tuple[int, int, int]]] selected_outline: The outline color when the + button is selected. Accepts an int or a tuple of 3 integers representing RGB values. + Defaults to the inverse of outline_color. + :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The label color when the + button is selected. Accepts an int or a tuple of 3 integers representing RGB values. + Defaults to inverting the label_color. :param Optional[int] label_scale: The scale factor used for the label. Defaults to 1. """ @@ -141,14 +144,14 @@ def __init__( height: int, name: Optional[str] = None, style = RECT, - fill_color: Optional[Union[int, tuple[int, int, int]]] = 0xFFFFFF, - outline_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, + fill_color: Optional[Union[int, Tuple[int, int, int]]] = 0xFFFFFF, + outline_color: Optional[Union[int, Tuple[int, int, int]]] = 0x0, label: Optional[str] = None, label_font: Optional[FontProtocol] = None, - label_color: Optional[Union[int, tuple[int, int , int]]] = 0x0, - selected_fill: Optional[Union[int, tuple[int, int , int]]] = None, - selected_outline: Optional[Union[int, tuple[int, int, int]]] = None, - selected_label: Optional[Union[int, tuple[int, int, int]]] = None, + label_color: Optional[Union[int, Tuple[int, int , int]]] = 0x0, + selected_fill: Optional[Union[int, Tuple[int, int , int]]] = None, + selected_outline: Optional[Union[int, Tuple[int, int, int]]] = None, + selected_label: Optional[Union[int, Tuple[int, int, int]]] = None, label_scale: Optional[int] = 1 ): super().__init__( @@ -222,7 +225,7 @@ def fill_color(self) -> Optional[int]: return self._fill_color @fill_color.setter - def fill_color(self, new_color: Union[int, tuple[int, int, int]]) -> None: + def fill_color(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._fill_color = _check_color(new_color) if not self.selected: self.body.fill = self._fill_color @@ -233,7 +236,7 @@ def outline_color(self) -> Optional[int]: return self._outline_color @outline_color.setter - def outline_color(self, new_color: Union[int, tuple[int, int, int]]) -> None: + def outline_color(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._outline_color = _check_color(new_color) if not self.selected: self.body.outline = self._outline_color @@ -244,7 +247,7 @@ def selected_fill(self) -> Optional[int]: return self._selected_fill @selected_fill.setter - def selected_fill(self, new_color: Union[int, tuple[int, int, int]]) -> None: + def selected_fill(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._selected_fill = _check_color(new_color) if self.selected: self.body.fill = self._selected_fill @@ -255,7 +258,7 @@ def selected_outline(self) -> Optional[int]: return self._selected_outline @selected_outline.setter - def selected_outline(self, new_color: Union[int, tuple[int, int, int]]) -> None: + def selected_outline(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._selected_outline = _check_color(new_color) if self.selected: self.body.outline = self._selected_outline From 2dd2d8ba1a6e4ab625d1761a4754503bf5c8a6c2 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Sun, 1 Dec 2024 15:54:49 -0600 Subject: [PATCH 119/137] Formatting corrections for button_base.py Correct formatting to avoid ruff errors. --- adafruit_button/button_base.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 54ed1c6..907aaf7 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -49,11 +49,13 @@ class ButtonBase(Group): :param int height: The height of the button in tiles. :param Optional[str] name: A name, or miscellaneous string that is stored on the button. :param Optional[str] label: The text that appears inside the button. - :param Optional[FontProtocol] label_font: The button label font. Defaults to ''terminalio.FONT'' - :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the button label text. Defaults to 0x0. - Accepts an int or a tuple of 3 integers representing RGB values. Defaults to an inverse of label_color. - :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The color of button label text when the button is selected. - Accepts an int or a tuple of 3 integers representing RGB values. Defaults to an inverse of label_color. + :param Optional[FontProtocol] label_font: The button label font. + Defaults to ''terminalio.FONT'' + :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the label text. + Defaults to 0x0. Accepts an int or a tuple of 3 integers representing RGB values. + :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The color of the label text + when the button is selected. Accepts an int or a tuple of 3 integers representing RGB values. + Defaults to an inverse of label_color. :param Optional[int] label_scale: The scale factor used for the label. Defaults to 1. """ @@ -67,8 +69,8 @@ def __init__( name: Optional[str] = None, label: Optional[str] = None, label_font: Optional[FontProtocol] = None, - label_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, - selected_label: Optional[Union[int, tuple[int, int, int]]] = None, + label_color: Optional[Union[int, Tuple[int, int, int]]] = 0x0, + selected_label: Optional[Union[int, Tuple[int, int, int]]] = None, label_scale: Optional[int] = 1, ) -> None: super().__init__(x=x, y=y) @@ -156,7 +158,7 @@ def selected_label(self) -> int: return self._selected_label @selected_label.setter - def selected_label(self, new_color: Union[int, tuple[int, int, int]]) -> None: + def selected_label(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._selected_label = _check_color(new_color) @property @@ -165,6 +167,6 @@ def label_color(self) -> int: return self._label_color @label_color.setter - def label_color(self, new_color: Union[int, tuple[int, int, int]]) -> None: + def label_color(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._label_color = _check_color(new_color) self._label.color = self._label_color From 3f1434dcdc8faa1bb5067010f352b18ced3e3308 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:03:00 -0600 Subject: [PATCH 120/137] Formatting for sprite_button Resolving ruff errors for sprite_button.py, some minor formatting elsewhere. --- adafruit_button/button.py | 19 ++++++++++--------- adafruit_button/sprite_button.py | 29 +++++++++++++++-------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 333b2eb..7eec017 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -53,22 +53,23 @@ class Button(ButtonBase): :param style: The style of the button. Can be RECT, ROUNDRECT, SHADOWRECT, SHADOWROUNDRECT. Defaults to RECT. :param Optional[Union[int, Tuple[int, int, int]]] fill_color: The color to fill the button. - Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0xFFFFFF. - :param Optional[Union[int, Tuple[int, int, int]]] outline_color: The color of the outline of the - button. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0xFFFFFF. + :param Optional[Union[int, Tuple[int, int, int]]] outline_color: The color of the outline of + the button. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. :param Optional[str] label: The text that appears inside the button. - :param Optional[FontProtocol] label_font: The button label font. Defaults to ''terminalio.FONT'' + :param Optional[FontProtocol] label_font: The button label font. Defaults to + ''terminalio.FONT'' :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the button label - text. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. + text. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. :param Optional[Union[int, Tuple[int, int, int]]] selected_fill: The fill color when the - button is selected. Accepts an int or a tuple of 3 integers representing RGB values. - Defaults to the inverse of the fill_color. + button is selected. Accepts an int or a tuple of 3 integers representing RGB values. + Defaults to the inverse of the fill_color. :param Optional[Union[int, Tuple[int, int, int]]] selected_outline: The outline color when the button is selected. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to the inverse of outline_color. :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The label color when the - button is selected. Accepts an int or a tuple of 3 integers representing RGB values. - Defaults to inverting the label_color. + button is selected. Accepts an int or a tuple of 3 integers representing RGB values. + Defaults to inverting the label_color. :param Optional[int] label_scale: The scale factor used for the label. Defaults to 1. """ diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index 8dabb80..25119a4 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -32,8 +32,8 @@ pass class SpriteButton(ButtonBase): - """Helper class for creating 3x3 Bitmap Spritesheet UI buttons for ``displayio``. Compatible with any format - supported by ''adafruit_imageload''. + """Helper class for creating 3x3 Bitmap Spritesheet UI buttons for ``displayio``. + Compatible with any format supported by ''adafruit_imageload''. :param int x: The x position of the button. :param int y: The y position of the button. @@ -42,15 +42,16 @@ class SpriteButton(ButtonBase): :param Optional[str] name: A name, or miscellaneous string that is stored on the button. :param Optional[str] label: The text that appears inside the button. :param Optional[FontProtocol] label_font: The button label font. - :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the button label text. Accepts either - an integer or a tuple of 3 integers representing RGB values. Defaults to 0x0. - :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The color of the button label text when the button - is selected. Accepts either an integer or a tuple of 3 integers representing RGB values. Defaults to the inverse of - label_color. + :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the label text. + Accepts either an integer or a tuple of 3 integers representing RGB values. Defaults to 0x0. + :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The color of the button label + text when the button is selected. Accepts either an integer or a tuple of 3 integers + representing RGB values. Defaults to the inverse of label_color. :param str bmp_path: The path of the 3x3 spritesheet mage file - :param Optional[str] selected_bmp_path: The path of the 3x3 spritesheet image file to use when pressed - :param Optional[Union[int, Tuple]] transparent_index: Palette index(s) that will be set to transparent. PNG files have these index(s) - set automatically. Not compatible with JPG files. + :param Optional[str] selected_bmp_path: The path of the 3x3 spritesheet image file to use when + pressed + :param Optional[Union[int, Tuple]] transparent_index: Palette index(s) that will be set to + transparent. PNG files have these index(s) set automatically. Not compatible with JPG files. :param Optional[int] label_scale: The scale multiplier of the button label. Defaults to 1. """ @@ -64,11 +65,11 @@ def __init__( name: Optional[str] = None, label: Optional[str] = None, label_font: Optional[FontProtocol] = None, - label_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, - selected_label: Optional[Union[int, tuple[int, int, int]]] = None, + label_color: Optional[Union[int, Tuple[int, int, int]]] = 0x0, + selected_label: Optional[Union[int, Tuple[int, int, int]]] = None, bmp_path: str = None, selected_bmp_path: Optional[str] = None, - transparent_index: Optional[Union[int, tuple]] = None, + transparent_index: Optional[Union[int, Tuple]] = None, label_scale: Optional[int] = 1 ): if bmp_path is None: @@ -125,7 +126,7 @@ def height(self) -> int: """The height of the button. Read-Only""" return self._height - def contains(self, point: list[int]) -> bool: + def contains(self, point: List[int]) -> bool: """Used to determine if a point is contained within a button. For example, ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for determining that a button has been touched. From a3ba72102d1caa7ccdccf48b9e3f16530ac79f73 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:13:31 -0600 Subject: [PATCH 121/137] CRLF to LF line ending conversion PyCharm has a mind of its own for settings. --- adafruit_button/button.py | 6 +++--- adafruit_button/button_base.py | 2 +- adafruit_button/sprite_button.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 7eec017..5bafa3e 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -294,8 +294,8 @@ def height(self, new_height: int) -> None: def resize(self, new_width: int, new_height: int) -> None: """Resize the button to the new width and height given - :param new_width int the desired width - :param new_height int the desired height + :param int new_width: The desired width in pixels. + :param int new_height: he desired height in pixels. """ self._width = new_width self._height = new_height @@ -303,4 +303,4 @@ def resize(self, new_width: int, new_height: int) -> None: self._create_body() if self.body: self.append(self.body) - self.label = self.label + self.label = self.label \ No newline at end of file diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 907aaf7..0c84237 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -169,4 +169,4 @@ def label_color(self) -> int: @label_color.setter def label_color(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._label_color = _check_color(new_color) - self._label.color = self._label_color + self._label.color = self._label_color \ No newline at end of file diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index 25119a4..389fe95 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -142,4 +142,4 @@ def _subclass_selected_behavior(self, value: Optional[Any]) -> None: self._btn_tilegrid.pixel_shader = self._selected_bmp_palette else: self._btn_tilegrid.bitmap = self._bmp - self._btn_tilegrid.pixel_shader = self._bmp_palette + self._btn_tilegrid.pixel_shader = self._bmp_palette \ No newline at end of file From db3d9e5e4abf834a345c530ca1c64226bd66097d Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:19:00 -0600 Subject: [PATCH 122/137] Black formatting Ran against local installation of black after correcting my own config. --- adafruit_button/button.py | 8 ++++---- adafruit_button/button_base.py | 3 ++- adafruit_button/sprite_button.py | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 5bafa3e..3a8bdd3 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -144,13 +144,13 @@ def __init__( width: int, height: int, name: Optional[str] = None, - style = RECT, + style=RECT, fill_color: Optional[Union[int, Tuple[int, int, int]]] = 0xFFFFFF, outline_color: Optional[Union[int, Tuple[int, int, int]]] = 0x0, label: Optional[str] = None, label_font: Optional[FontProtocol] = None, - label_color: Optional[Union[int, Tuple[int, int , int]]] = 0x0, - selected_fill: Optional[Union[int, Tuple[int, int , int]]] = None, + label_color: Optional[Union[int, Tuple[int, int, int]]] = 0x0, + selected_fill: Optional[Union[int, Tuple[int, int, int]]] = None, selected_outline: Optional[Union[int, Tuple[int, int, int]]] = None, selected_label: Optional[Union[int, Tuple[int, int, int]]] = None, label_scale: Optional[int] = 1 @@ -303,4 +303,4 @@ def resize(self, new_width: int, new_height: int) -> None: self._create_body() if self.body: self.append(self.body) - self.label = self.label \ No newline at end of file + self.label = self.label diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 0c84237..58f429b 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -24,6 +24,7 @@ from adafruit_display_text.bitmap_label import Label from displayio import Group import terminalio + try: from typing import Optional, Union, Tuple, Any from fontio import FontProtocol @@ -169,4 +170,4 @@ def label_color(self) -> int: @label_color.setter def label_color(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._label_color = _check_color(new_color) - self._label.color = self._label_color \ No newline at end of file + self._label.color = self._label_color diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index 389fe95..3b5feff 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -31,6 +31,7 @@ except ImportError: pass + class SpriteButton(ButtonBase): """Helper class for creating 3x3 Bitmap Spritesheet UI buttons for ``displayio``. Compatible with any format supported by ''adafruit_imageload''. @@ -142,4 +143,4 @@ def _subclass_selected_behavior(self, value: Optional[Any]) -> None: self._btn_tilegrid.pixel_shader = self._selected_bmp_palette else: self._btn_tilegrid.bitmap = self._bmp - self._btn_tilegrid.pixel_shader = self._bmp_palette \ No newline at end of file + self._btn_tilegrid.pixel_shader = self._bmp_palette From a00436d37cc1f832332a51893b4d08354a09a0bf Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:48:08 -0600 Subject: [PATCH 123/137] Allow setting label colors with Tuples Corrects issues with converting tuples of RGB values to ints, which Label objects require. --- adafruit_button/button.py | 4 ++-- adafruit_button/button_base.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 3a8bdd3..1ad1aa0 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -179,9 +179,9 @@ def __init__( self._selected_outline = _check_color(selected_outline) if self.selected_fill is None and fill_color is not None: - self.selected_fill = (~self._fill_color) & 0xFFFFFF + self.selected_fill = (~_check_color(self._fill_color)) & 0xFFFFFF if self.selected_outline is None and outline_color is not None: - self.selected_outline = (~self._outline_color) & 0xFFFFFF + self.selected_outline = (~_check_color(self._outline_color)) & 0xFFFFFF self._create_body() if self.body: diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 58f429b..167a667 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -126,7 +126,7 @@ def label(self, newtext: str) -> None: self.append(self._label) if (self.selected_label is None) and (self._label_color is not None): - self.selected_label = (~self._label_color) & 0xFFFFFF + self.selected_label = (~_check_color(self._label_color)) & 0xFFFFFF def _subclass_selected_behavior(self, value: Optional[Any]) -> None: # Subclasses should override this! From fd29d0f496920039da9d68307b6ff0bd2ea4a210 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:34:40 -0600 Subject: [PATCH 124/137] Update conf.py Point it to the new builtin libraries used, terminalio and fontio. --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 8e24264..56878d6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,7 +27,7 @@ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -autodoc_mock_imports = ["displayio", "bitmaptools"] +autodoc_mock_imports = ["displayio", "bitmaptools", "terminalio", "fontio"] intersphinx_mapping = { From 044c03acbf34fe17f6f2691250ea2351a1682249 Mon Sep 17 00:00:00 2001 From: ch4nsuk3 <134003603+ch4nsuk3@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:53:21 -0600 Subject: [PATCH 125/137] Exposed Name attribute The name attribute is not a property that can be read or set. --- adafruit_button/button_base.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 8a7709c..c8cc35d 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -68,7 +68,7 @@ def __init__( self._height = height self._font = label_font self._selected = False - self.name = name + self._name = name self._label = label self._label_color = label_color self._label_font = label_font @@ -157,3 +157,12 @@ def label_color(self): def label_color(self, new_color): self._label_color = _check_color(new_color) self._label.color = self._label_color + + @property + def name(self) -> str: + """The name of the button""" + return self._name + + @name.setter + def name(self, new_name: str) -> None: + self._name = new_name From cf32fd3d3baf8527698c7ead98c7472cee29ecd5 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Dec 2024 14:55:05 -0600 Subject: [PATCH 126/137] type annotations --- adafruit_button/button.py | 71 ++++++++++++++++++-------------- adafruit_button/button_base.py | 42 +++++++++++-------- adafruit_button/sprite_button.py | 40 ++++++++++-------- 3 files changed, 86 insertions(+), 67 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 45c87f7..22ffe55 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -26,6 +26,13 @@ from adafruit_display_shapes.roundrect import RoundRect from adafruit_button.button_base import ButtonBase, _check_color +try: + from typing import Optional, Union + from fontio import FontProtocol + from displayio import Group +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Button.git" @@ -117,22 +124,22 @@ def _create_body(self): def __init__( self, *, - x, - y, - width, - height, - name=None, - style=RECT, - fill_color=0xFFFFFF, - outline_color=0x0, - label=None, - label_font=None, - label_color=0x0, - selected_fill=None, - selected_outline=None, - selected_label=None, - label_scale=None - ): + x: int, + y: int, + width: int, + height: int, + name: Optional[str] = None, + style: int = RECT, + fill_color: Optional[Union[int, tuple[int, int, int]]] = 0xFFFFFF, + outline_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, + label: Optional[str] = None, + label_font: Optional[FontProtocol] = None, + label_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, + selected_fill: Optional[Union[int, tuple[int, int, int]]] = None, + selected_outline: Optional[Union[int, tuple[int, int, int]]] = None, + selected_label: Optional[Union[int, tuple[int, int, int]]] = None, + label_scale: Optional[int] = None + ) -> None: super().__init__( x=x, y=y, @@ -167,7 +174,7 @@ def __init__( self.label = label - def _subclass_selected_behavior(self, value): + def _subclass_selected_behavior(self, value: bool) -> None: if self._selected: new_fill = self.selected_fill new_out = self.selected_outline @@ -180,7 +187,7 @@ def _subclass_selected_behavior(self, value): self.body.outline = new_out @property - def group(self): + def group(self) -> Group: """Return self for compatibility with old API.""" print( "Warning: The group property is being deprecated. " @@ -189,7 +196,7 @@ def group(self): ) return self - def contains(self, point): + def contains(self, point: tuple[int, int]) -> bool: """Used to determine if a point is contained within a button. For example, ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for determining that a button has been touched. @@ -199,56 +206,56 @@ def contains(self, point): ) @property - def fill_color(self): + def fill_color(self) -> int: """The fill color of the button body""" return self._fill_color @fill_color.setter - def fill_color(self, new_color): + def fill_color(self, new_color: int) -> None: self._fill_color = _check_color(new_color) if not self.selected: self.body.fill = self._fill_color @property - def outline_color(self): + def outline_color(self) -> int: """The outline color of the button body""" return self._outline_color @outline_color.setter - def outline_color(self, new_color): + def outline_color(self, new_color: int) -> None: self._outline_color = _check_color(new_color) if not self.selected: self.body.outline = self._outline_color @property - def selected_fill(self): + def selected_fill(self) -> int: """The fill color of the button body when selected""" return self._selected_fill @selected_fill.setter - def selected_fill(self, new_color): + def selected_fill(self, new_color: int) -> None: self._selected_fill = _check_color(new_color) if self.selected: self.body.fill = self._selected_fill @property - def selected_outline(self): + def selected_outline(self) -> int: """The outline color of the button body when selected""" return self._selected_outline @selected_outline.setter - def selected_outline(self, new_color): + def selected_outline(self, new_color: int) -> None: self._selected_outline = _check_color(new_color) if self.selected: self.body.outline = self._selected_outline @property - def width(self): + def width(self) -> int: """The width of the button""" return self._width @width.setter - def width(self, new_width): + def width(self, new_width: int) -> None: self._width = new_width self._empty_self_group() self._create_body() @@ -257,12 +264,12 @@ def width(self, new_width): self.label = self.label @property - def height(self): + def height(self) -> int: """The height of the button""" return self._height @height.setter - def height(self, new_height): + def height(self, new_height: int) -> None: self._height = new_height self._empty_self_group() self._create_body() @@ -270,7 +277,7 @@ def height(self, new_height): self.append(self.body) self.label = self.label - def resize(self, new_width, new_height): + def resize(self, new_width: int, new_height: int) -> None: """Resize the button to the new width and height given :param new_width int the desired width :param new_height int the desired height diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 8a7709c..c906c90 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -23,6 +23,12 @@ from adafruit_display_text.bitmap_label import Label from displayio import Group +try: + from typing import Optional, Union + from fontio import FontProtocol +except ImportError: + pass + def _check_color(color): # if a tuple is supplied, convert it to a RGB number @@ -50,16 +56,16 @@ class ButtonBase(Group): def __init__( self, *, - x, - y, - width, - height, - name=None, - label=None, - label_font=None, - label_color=0x0, - selected_label=None, - label_scale=None + x: int, + y: int, + width: int, + height: int, + name: Optional[str] = None, + label: Optional[str] = None, + label_font: Optional[FontProtocol] = None, + label_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, + selected_label: Optional[Union[int, tuple[int, int, int]]] = None, + label_scale: Optional[int] = None ): super().__init__(x=x, y=y) self.x = x @@ -76,12 +82,12 @@ def __init__( self._label_scale = label_scale or 1 @property - def label(self): + def label(self) -> str: """The text label of the button""" return getattr(self._label, "text", None) @label.setter - def label(self, newtext): + def label(self, newtext: str) -> None: if self._label and self and (self[-1] == self._label): self.pop() @@ -120,12 +126,12 @@ def _subclass_selected_behavior(self, value): pass @property - def selected(self): + def selected(self) -> bool: """Selected inverts the colors.""" return self._selected @selected.setter - def selected(self, value): + def selected(self, value: bool) -> None: if value == self._selected: return # bail now, nothing more to do self._selected = value @@ -140,20 +146,20 @@ def selected(self, value): self._subclass_selected_behavior(value) @property - def selected_label(self): + def selected_label(self) -> int: """The font color of the button when selected""" return self._selected_label @selected_label.setter - def selected_label(self, new_color): + def selected_label(self, new_color: int) -> None: self._selected_label = _check_color(new_color) @property - def label_color(self): + def label_color(self) -> int: """The font color of the button""" return self._label_color @label_color.setter - def label_color(self, new_color): + def label_color(self, new_color: int): self._label_color = _check_color(new_color) self._label.color = self._label_color diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index 67fd9ee..f1ca06e 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -24,6 +24,12 @@ from adafruit_imageload import load from adafruit_button.button_base import ButtonBase +try: + from typing import Optional, Union, Tuple + from fontio import FontProtocol +except ImportError: + pass + class SpriteButton(ButtonBase): """Helper class for creating 3x3 Bitmap Spritesheet UI buttons for ``displayio``. @@ -45,19 +51,19 @@ class SpriteButton(ButtonBase): def __init__( self, *, - x, - y, - width, - height, - name=None, - label=None, - label_font=None, - label_color=0x0, - selected_label=None, - bmp_path=None, - selected_bmp_path=None, - transparent_index=None, - label_scale=None + x: int, + y: int, + width: int, + height: int, + name: Optional[str] = None, + label: Optional[str] = None, + label_font: Optional[FontProtocol] = None, + label_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, + selected_label: Optional[Union[int, tuple[int, int, int]]] = None, + bmp_path: Optional[str] = None, + selected_bmp_path: Optional[str] = None, + transparent_index: Optional[int] = None, + label_scale: Optional[int] = None ): if bmp_path is None: raise ValueError("Please supply bmp_path. It cannot be None.") @@ -104,16 +110,16 @@ def __init__( self.label = label @property - def width(self): + def width(self) -> int: """The width of the button""" return self._width @property - def height(self): + def height(self) -> int: """The height of the button""" return self._height - def contains(self, point): + def contains(self, point: Tuple[int, int]): """Used to determine if a point is contained within a button. For example, ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for determining that a button has been touched. @@ -122,7 +128,7 @@ def contains(self, point): self.y <= point[1] <= self.y + self.height ) - def _subclass_selected_behavior(self, value): + def _subclass_selected_behavior(self, value: bool) -> None: if self._selected: if self._selected_bmp is not None: self._btn_tilegrid.bitmap = self._selected_bmp From daf6bc2405e208cf2a560f07b65300dce29d4c3b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Dec 2024 15:29:24 -0600 Subject: [PATCH 127/137] use ruff --- .gitattributes | 11 +++ .pre-commit-config.yaml | 42 +++----- README.rst | 6 +- adafruit_button/__init__.py | 1 + adafruit_button/button.py | 15 ++- adafruit_button/button_base.py | 17 ++-- adafruit_button/sprite_button.py | 9 +- docs/conf.py | 8 +- examples/display_button_color_properties.py | 3 +- examples/display_button_customfont.py | 4 +- examples/display_button_simpletest.py | 3 +- examples/display_button_soundboard.py | 2 + .../display_button_spritebutton_simpletest.py | 4 +- ...spritebutton_tft_featherwing_simpletest.py | 8 +- ruff.toml | 99 +++++++++++++++++++ 15 files changed, 164 insertions(+), 68 deletions(-) create mode 100644 .gitattributes create mode 100644 ruff.toml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..21c125c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +.py text eol=lf +.rst text eol=lf +.txt text eol=lf +.yaml text eol=lf +.toml text eol=lf +.license text eol=lf +.md text eol=lf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 374676d..f27b786 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +1,22 @@ # SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers # # SPDX-License-Identifier: Unlicense repos: - - repo: https://github.com/python/black - rev: 23.3.0 - hooks: - - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/pylint - rev: v3.3.1 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string - exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint - name: pylint (example code) - description: Run pylint rules on "examples/*.py" files - types: [python] - files: "^examples/" - args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint - name: pylint (test code) - description: Run pylint rules on "tests/*.py" files - types: [python] - files: "^tests/" - args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse diff --git a/README.rst b/README.rst index 7828bef..f88b195 100644 --- a/README.rst +++ b/README.rst @@ -13,9 +13,9 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_Display_Button/actions :alt: Build Status -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code Style: Black +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: Code Style: Ruff UI Buttons for displayio diff --git a/adafruit_button/__init__.py b/adafruit_button/__init__.py index 2fa5ba8..f521f2e 100644 --- a/adafruit_button/__init__.py +++ b/adafruit_button/__init__.py @@ -20,4 +20,5 @@ https://github.com/adafruit/circuitpython/releases """ + from adafruit_button.button import Button diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 22ffe55..80ed36a 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -21,15 +21,17 @@ """ -from micropython import const from adafruit_display_shapes.rect import Rect from adafruit_display_shapes.roundrect import RoundRect +from micropython import const + from adafruit_button.button_base import ButtonBase, _check_color try: from typing import Optional, Union - from fontio import FontProtocol + from displayio import Group + from fontio import FontProtocol except ImportError: pass @@ -38,7 +40,6 @@ class Button(ButtonBase): - # pylint: disable=too-many-instance-attributes, too-many-locals """Helper class for creating UI buttons for ``displayio``. :param x: The x position of the button. @@ -84,9 +85,7 @@ def _create_body(self): outline=self._outline_color, ) elif self.style == Button.SHADOWRECT: - self.shadow = Rect( - 2, 2, self.width - 2, self.height - 2, fill=self.outline_color - ) + self.shadow = Rect(2, 2, self.width - 2, self.height - 2, fill=self.outline_color) self.body = Rect( 0, 0, @@ -121,7 +120,7 @@ def _create_body(self): SHADOWRECT = const(2) SHADOWROUNDRECT = const(3) - def __init__( + def __init__( # noqa: PLR0913 Too many arguments self, *, x: int, @@ -138,7 +137,7 @@ def __init__( selected_fill: Optional[Union[int, tuple[int, int, int]]] = None, selected_outline: Optional[Union[int, tuple[int, int, int]]] = None, selected_label: Optional[Union[int, tuple[int, int, int]]] = None, - label_scale: Optional[int] = None + label_scale: Optional[int] = None, ) -> None: super().__init__( x=x, diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index c906c90..7796bf4 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -20,11 +20,13 @@ https://github.com/adafruit/circuitpython/releases """ + from adafruit_display_text.bitmap_label import Label from displayio import Group try: from typing import Optional, Union + from fontio import FontProtocol except ImportError: pass @@ -39,7 +41,6 @@ def _check_color(color): class ButtonBase(Group): - # pylint: disable=too-many-instance-attributes """Superclass for creating UI buttons for ``displayio``. :param x: The x position of the button. @@ -53,7 +54,7 @@ class ButtonBase(Group): :param selected_label: Text that appears when selected """ - def __init__( + def __init__( # noqa: PLR0913 Too many arguments self, *, x: int, @@ -65,7 +66,7 @@ def __init__( label_font: Optional[FontProtocol] = None, label_color: Optional[Union[int, tuple[int, int, int]]] = 0x0, selected_label: Optional[Union[int, tuple[int, int, int]]] = None, - label_scale: Optional[int] = None + label_scale: Optional[int] = None, ): super().__init__(x=x, y=y) self.x = x @@ -102,10 +103,8 @@ def label(self, newtext: str) -> None: dims[2] *= self._label.scale dims[3] *= self._label.scale if dims[2] >= self.width or dims[3] >= self.height: - while len(self._label.text) > 1 and ( - dims[2] >= self.width or dims[3] >= self.height - ): - self._label.text = "{}.".format(self._label.text[:-2]) + while len(self._label.text) > 1 and (dims[2] >= self.width or dims[3] >= self.height): + self._label.text = f"{self._label.text[:-2]}." dims = list(self._label.bounding_box) dims[2] *= self._label.scale dims[3] *= self._label.scale @@ -113,9 +112,7 @@ def label(self, newtext: str) -> None: raise RuntimeError("Button not large enough for label") self._label.x = (self.width - dims[2]) // 2 self._label.y = self.height // 2 - self._label.color = ( - self._label_color if not self.selected else self._selected_label - ) + self._label.color = self._label_color if not self.selected else self._selected_label self.append(self._label) if (self.selected_label is None) and (self._label_color is not None): diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index f1ca06e..5feb312 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -20,12 +20,15 @@ https://github.com/adafruit/circuitpython/releases """ -from adafruit_imageload.tilegrid_inflator import inflate_tilegrid + from adafruit_imageload import load +from adafruit_imageload.tilegrid_inflator import inflate_tilegrid + from adafruit_button.button_base import ButtonBase try: - from typing import Optional, Union, Tuple + from typing import Optional, Tuple, Union + from fontio import FontProtocol except ImportError: pass @@ -48,7 +51,7 @@ class SpriteButton(ButtonBase): :param int or tuple transparent_index: Index(s) that will be made transparent on the Palette """ - def __init__( + def __init__( # noqa: PLR0913 Too many arguments self, *, x: int, diff --git a/docs/conf.py b/docs/conf.py index 8e24264..ed174ba 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -48,9 +46,7 @@ creation_year = "2019" current_year = str(datetime.datetime.now().year) year_duration = ( - current_year - if current_year == creation_year - else creation_year + " - " + current_year + current_year if current_year == creation_year else creation_year + " - " + current_year ) copyright = year_duration + " Limor Fried" author = "Limor Fried" diff --git a/examples/display_button_color_properties.py b/examples/display_button_color_properties.py index d8bf92f..9ad73a0 100644 --- a/examples/display_button_color_properties.py +++ b/examples/display_button_color_properties.py @@ -6,10 +6,11 @@ properties after the button has been initialized. """ +import adafruit_touchscreen import board import displayio import terminalio -import adafruit_touchscreen + from adafruit_button import Button # use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index 189af96..eb6a3ae 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -5,10 +5,12 @@ """ import os + +import adafruit_touchscreen import board import displayio from adafruit_bitmap_font import bitmap_font -import adafruit_touchscreen + from adafruit_button import Button # use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index fa388f3..f8d8546 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -4,10 +4,11 @@ Simple button example. """ +import adafruit_touchscreen import board import displayio import terminalio -import adafruit_touchscreen + from adafruit_button import Button # use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) diff --git a/examples/display_button_soundboard.py b/examples/display_button_soundboard.py index 2fd0bad..ef52c8a 100644 --- a/examples/display_button_soundboard.py +++ b/examples/display_button_soundboard.py @@ -5,7 +5,9 @@ """ import time + from adafruit_pyportal import PyPortal + from adafruit_button import Button SHOW_BUTTONS = False diff --git a/examples/display_button_spritebutton_simpletest.py b/examples/display_button_spritebutton_simpletest.py index 838ed30..1836d67 100644 --- a/examples/display_button_spritebutton_simpletest.py +++ b/examples/display_button_spritebutton_simpletest.py @@ -1,10 +1,12 @@ # SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries # SPDX-License-Identifier: MIT import time + +import adafruit_touchscreen import board import displayio -import adafruit_touchscreen import terminalio + from adafruit_button.sprite_button import SpriteButton # These pins are used as both analog and digital! XL, XR and YU must be analog diff --git a/examples/display_button_spritebutton_tft_featherwing_simpletest.py b/examples/display_button_spritebutton_tft_featherwing_simpletest.py index bac2cf7..006fd51 100644 --- a/examples/display_button_spritebutton_tft_featherwing_simpletest.py +++ b/examples/display_button_spritebutton_tft_featherwing_simpletest.py @@ -1,12 +1,14 @@ # SPDX-FileCopyrightText: 2024 DJDevon3 # SPDX-License-Identifier: MIT import time -import displayio -import terminalio + +import adafruit_stmpe610 # TFT Featherwing V1 touch driver import board import digitalio +import displayio +import terminalio from adafruit_hx8357 import HX8357 # TFT Featherwing display driver -import adafruit_stmpe610 # TFT Featherwing V1 touch driver + from adafruit_button.sprite_button import SpriteButton # 3.5" TFT Featherwing is 480x320 diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..db37c83 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,99 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +select = ["I", "PL", "UP"] + +extend-select = [ + "D419", # empty-docstring + "E501", # line-too-long + "W291", # trailing-whitespace + "PLC0414", # useless-import-alias + "PLC2401", # non-ascii-name + "PLC2801", # unnecessary-dunder-call + "PLC3002", # unnecessary-direct-lambda-call + "E999", # syntax-error + "PLE0101", # return-in-init + "F706", # return-outside-function + "F704", # yield-outside-function + "PLE0116", # continue-in-finally + "PLE0117", # nonlocal-without-binding + "PLE0241", # duplicate-bases + "PLE0302", # unexpected-special-method-signature + "PLE0604", # invalid-all-object + "PLE0605", # invalid-all-format + "PLE0643", # potential-index-error + "PLE0704", # misplaced-bare-raise + "PLE1141", # dict-iter-missing-items + "PLE1142", # await-outside-async + "PLE1205", # logging-too-many-args + "PLE1206", # logging-too-few-args + "PLE1307", # bad-string-format-type + "PLE1310", # bad-str-strip-call + "PLE1507", # invalid-envvar-value + "PLE2502", # bidirectional-unicode + "PLE2510", # invalid-character-backspace + "PLE2512", # invalid-character-sub + "PLE2513", # invalid-character-esc + "PLE2514", # invalid-character-nul + "PLE2515", # invalid-character-zero-width-space + "PLR0124", # comparison-with-itself + "PLR0202", # no-classmethod-decorator + "PLR0203", # no-staticmethod-decorator + "UP004", # useless-object-inheritance + "PLR0206", # property-with-parameters + "PLR0904", # too-many-public-methods + "PLR0911", # too-many-return-statements + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0914", # too-many-locals + "PLR0915", # too-many-statements + "PLR0916", # too-many-boolean-expressions + "PLR1702", # too-many-nested-blocks + "PLR1704", # redefined-argument-from-local + "PLR1711", # useless-return + "C416", # unnecessary-comprehension + "PLR1733", # unnecessary-dict-index-lookup + "PLR1736", # unnecessary-list-index-lookup + + # ruff reports this rule is unstable + #"PLR6301", # no-self-use + + "PLW0108", # unnecessary-lambda + "PLW0120", # useless-else-on-loop + "PLW0127", # self-assigning-variable + "PLW0129", # assert-on-string-literal + "B033", # duplicate-value + "PLW0131", # named-expr-without-context + "PLW0245", # super-without-brackets + "PLW0406", # import-self + "PLW0602", # global-variable-not-assigned + "PLW0603", # global-statement + "PLW0604", # global-at-module-level + + # fails on the try: import typing used by libraries + #"F401", # unused-import + + "F841", # unused-variable + "E722", # bare-except + "PLW0711", # binary-op-exception + "PLW1501", # bad-open-mode + "PLW1508", # invalid-envvar-default + "PLW1509", # subprocess-popen-preexec-fn + "PLW2101", # useless-with-lock + "PLW3301", # nested-min-max +] + +ignore = [ + "PLR2004", # magic-value-comparison + "UP030", # format literals + "PLW1514", # unspecified-encoding + +] + +[format] +line-ending = "lf" From f6026b2b6abbaffc617a566d3cb92e3d03a59e14 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Dec 2024 15:40:45 -0600 Subject: [PATCH 128/137] merge main, resolve conflicts --- adafruit_button/button.py | 2 +- adafruit_button/button_base.py | 1 - adafruit_button/sprite_button.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 6264822..1ab13f0 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -28,7 +28,7 @@ from adafruit_button.button_base import ButtonBase, _check_color try: - from typing import Optional, Union, Tuple, Any, List + from typing import Optional, Union, Tuple from fontio import FontProtocol from displayio import Group except ImportError: diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index e31e040..d118d04 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -32,7 +32,6 @@ pass - def _check_color(color: Optional[Union[int, tuple[int, int, int]]]) -> int: # if a tuple is supplied, convert it to a RGB number if isinstance(color, tuple): diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index 069b18e..337466a 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -26,7 +26,7 @@ from adafruit_button.button_base import ButtonBase try: - from typing import Optional, Union, Tuple, List + from typing import Optional, Union, Tuple from fontio import FontProtocol except ImportError: pass From 3466a7dfcb6d592b4390e8e6281656539f46f15a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Dec 2024 15:49:33 -0600 Subject: [PATCH 129/137] merge main, resolve conflicts --- adafruit_button/button.py | 3 ++- adafruit_button/button_base.py | 5 +++-- adafruit_button/sprite_button.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index e4af791..2e2f3ec 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -29,7 +29,8 @@ from adafruit_button.button_base import ButtonBase, _check_color try: - from typing import Optional, Union, Tuple + from typing import Optional, Tuple, Union + from displayio import Group from fontio import FontProtocol except ImportError: diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index eedf2a3..ce54eee 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -22,12 +22,13 @@ """ +import terminalio from adafruit_display_text.bitmap_label import Label from displayio import Group -import terminalio try: - from typing import Optional, Union, Tuple + from typing import Optional, Tuple, Union + from fontio import FontProtocol except ImportError: pass diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index d82e842..4ca220f 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -74,7 +74,7 @@ def __init__( # noqa: PLR0913 Too many arguments bmp_path: str = None, selected_bmp_path: Optional[str] = None, transparent_index: Optional[Union[int, Tuple]] = None, - label_scale: Optional[int] = 1 + label_scale: Optional[int] = 1, ): if bmp_path is None: raise ValueError("Please supply bmp_path. It cannot be None.") From 68760d1e06c93845e4e8ddcf33726464d66ffd40 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 5 Dec 2024 10:04:00 -0600 Subject: [PATCH 130/137] move contains() to base and add support for FocalTouch --- adafruit_button/button.py | 9 --------- adafruit_button/button_base.py | 26 +++++++++++++++++++++++++- adafruit_button/sprite_button.py | 9 --------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 2e2f3ec..d81e994 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -211,15 +211,6 @@ def group(self) -> Group: ) return self - def contains(self, point: tuple[int, int]) -> bool: - """Used to determine if a point is contained within a button. For example, - ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for - determining that a button has been touched. - """ - return (self.x <= point[0] <= self.x + self.width) and ( - self.y <= point[1] <= self.y + self.height - ) - @property def fill_color(self) -> Optional[int]: """The fill color of the button body""" diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index f4adaf9..820bc9d 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -27,7 +27,7 @@ from displayio import Group try: - from typing import Optional, Tuple, Union + from typing import Dict, List, Optional, Tuple, Union from fontio import FontProtocol except ImportError: @@ -177,3 +177,27 @@ def name(self) -> str: @name.setter def name(self, new_name: str) -> None: self._name = new_name + + def contains(self, point: Union[tuple[int, int], List[int, int], List[Dict[str, int]]]) -> bool: + """Used to determine if a point is contained within a button. For example, + ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for + determining that a button has been touched. + """ + if isinstance(point, tuple) or (isinstance(point, list) and isinstance(point[0], int)): + return (self.x <= point[0] <= self.x + self.width) and ( + self.y <= point[1] <= self.y + self.height + ) + elif isinstance(point, list): + touch_points = point + if len(touch_points) == 0: + return False + for touch_point in touch_points: + if ( + isinstance(touch_point, dict) + and "x" in touch_point.keys() + and "y" in touch_point.keys() + ): + if self.contains((touch_point["x"], touch_point["y"])): + return True + + return False diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index 4ca220f..e8f2f44 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -130,15 +130,6 @@ def height(self) -> int: """The height of the button. Read-Only""" return self._height - def contains(self, point: Tuple[int, int]) -> bool: - """Used to determine if a point is contained within a button. For example, - ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for - determining that a button has been touched. - """ - return (self.x <= point[0] <= self.x + self.width) and ( - self.y <= point[1] <= self.y + self.height - ) - def _subclass_selected_behavior(self, value: bool) -> None: if self._selected: if self._selected_bmp is not None: From ca0f247c4e35f0e099a728fcd40079bb661b8aef Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 5 Dec 2024 10:51:10 -0600 Subject: [PATCH 131/137] fix List annotation --- adafruit_button/button_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 820bc9d..7e430b6 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -178,7 +178,7 @@ def name(self) -> str: def name(self, new_name: str) -> None: self._name = new_name - def contains(self, point: Union[tuple[int, int], List[int, int], List[Dict[str, int]]]) -> bool: + def contains(self, point: Union[tuple[int, int], List[int], List[Dict[str, int]]]) -> bool: """Used to determine if a point is contained within a button. For example, ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for determining that a button has been touched. From 7da4638b1a38c047207edc7bea62ae137e3e26c1 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 5 Dec 2024 14:19:56 -0600 Subject: [PATCH 132/137] add debounced examples --- examples/display_button_debounced.py | 73 ++++++++++++++++++ .../display_button_spritebutton_debounced.py | 74 +++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 examples/display_button_debounced.py create mode 100644 examples/display_button_spritebutton_debounced.py diff --git a/examples/display_button_debounced.py b/examples/display_button_debounced.py new file mode 100644 index 0000000..8a0471b --- /dev/null +++ b/examples/display_button_debounced.py @@ -0,0 +1,73 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# SPDX-License-Identifier: MIT +""" +Basic debounced button example. +""" + +import adafruit_touchscreen +import board +import displayio +import terminalio + +from adafruit_button import Button + +# use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) +# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.) +# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus +display = board.DISPLAY + +# --| Button Config |------------------------------------------------- +BUTTON_X = 110 +BUTTON_Y = 95 +BUTTON_WIDTH = 100 +BUTTON_HEIGHT = 50 +BUTTON_STYLE = Button.ROUNDRECT +BUTTON_FILL_COLOR = 0x00FFFF +BUTTON_OUTLINE_COLOR = 0xFF00FF +BUTTON_LABEL = "HELLO WORLD" +BUTTON_LABEL_COLOR = 0x000000 +# --| Button Config |------------------------------------------------- + +# Setup touchscreen (PyPortal) +ts = adafruit_touchscreen.Touchscreen( + board.TOUCH_XL, + board.TOUCH_XR, + board.TOUCH_YD, + board.TOUCH_YU, + calibration=((5200, 59000), (5800, 57000)), + size=(display.width, display.height), +) + +# Make the display context +splash = displayio.Group() +display.root_group = splash + +# Make the button +button = Button( + x=BUTTON_X, + y=BUTTON_Y, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + style=BUTTON_STYLE, + fill_color=BUTTON_FILL_COLOR, + outline_color=BUTTON_OUTLINE_COLOR, + label=BUTTON_LABEL, + label_font=terminalio.FONT, + label_color=BUTTON_LABEL_COLOR, +) + +# Add button to the display context +splash.append(button) + +# Loop and look for touches +while True: + p = ts.touch_point + if p: + if button.contains(p): + if not button.selected: + button.selected = True + print("pressed") + else: + button.selected = False # if touch is dragged outside of button + else: + button.selected = False # if touch is released diff --git a/examples/display_button_spritebutton_debounced.py b/examples/display_button_spritebutton_debounced.py new file mode 100644 index 0000000..6d6f65f --- /dev/null +++ b/examples/display_button_spritebutton_debounced.py @@ -0,0 +1,74 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# SPDX-License-Identifier: MIT +import time + +import adafruit_touchscreen +import board +import displayio +import terminalio + +from adafruit_button.sprite_button import SpriteButton + +""" +Sprite button debounced example +""" + +# These pins are used as both analog and digital! XL, XR and YU must be analog +# and digital capable. YD just need to be digital +ts = adafruit_touchscreen.Touchscreen( + board.TOUCH_XL, + board.TOUCH_XR, + board.TOUCH_YD, + board.TOUCH_YU, + calibration=((5200, 59000), (5800, 57000)), + size=(board.DISPLAY.width, board.DISPLAY.height), +) + +# Make the display context +main_group = displayio.Group() +board.DISPLAY.root_group = main_group + +BUTTON_WIDTH = 10 * 16 +BUTTON_HEIGHT = 3 * 16 +BUTTON_MARGIN = 20 + +font = terminalio.FONT + +buttons = [] + + +button_0 = SpriteButton( + x=BUTTON_MARGIN, + y=BUTTON_MARGIN, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="button0", + label_font=font, + bmp_path="bmps/gradient_button_0.bmp", + selected_bmp_path="bmps/gradient_button_1.bmp", + transparent_index=0, +) + +buttons.append(button_0) + +for b in buttons: + main_group.append(b) +while True: + p = ts.touch_point + if p: + for i, b in enumerate(buttons): + if b.contains(p): + if not b.selected: + print("Button %d pressed" % i) + b.selected = True + b.label = "pressed" + else: + b.selected = False + b.label = f"button{i}" + + else: + for i, b in enumerate(buttons): + if b.selected: + b.selected = False + b.label = f"button{i}" + time.sleep(0.01) From 5d9aa8d15aab8b6813690fb23886e71e59ba1f61 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 133/137] add sphinx configuration to rtd.yaml Signed-off-by: foamyguy --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) 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: From 5bc4267c64b7b6f8515858fb577a7f19a64b4f16 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 16 May 2025 15:01:19 +0000 Subject: [PATCH 134/137] change to ruff --- .pre-commit-config.yaml | 3 +- .pylintrc | 399 ---------------------------------------- ruff.toml | 11 +- 3 files changed, 11 insertions(+), 402 deletions(-) delete mode 100644 .pylintrc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f27b786..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,4 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò -# SPDX-FileCopyrightText: 2024 Justin Myers +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # SPDX-License-Identifier: Unlicense diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index fe3f21d..0000000 --- a/.pylintrc +++ /dev/null @@ -1,399 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -# Add files or directories to the ignore-list. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=pylint.extensions.no_self_use - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call -disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable= - - -[REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -# notes=FIXME,XXX,TODO -notes=FIXME,XXX - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules=board - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -# expected-line-ending-format= -expected-line-ending-format=LF - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=yes - -# Minimum lines number of a similarity. -min-similarity-lines=12 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct attribute names -attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ -class-rgx=[A-Z_][a-zA-Z0-9_]+$ - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Regular expression matching correct function names -function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -# good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct variable names -variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -[IMPORTS] - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=18 - -# Maximum number of attributes for a class (see R0902). -# max-attributes=7 -max-attributes=11 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of statements in function / method body -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=1 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=builtins.Exception diff --git a/ruff.toml b/ruff.toml index db37c83..73e9efc 100644 --- a/ruff.toml +++ b/ruff.toml @@ -6,6 +6,7 @@ target-version = "py38" line-length = 100 [lint] +preview = true select = ["I", "PL", "UP"] extend-select = [ @@ -92,7 +93,15 @@ ignore = [ "PLR2004", # magic-value-comparison "UP030", # format literals "PLW1514", # unspecified-encoding - + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + "PLR0917", # too-many-positional-arguments + "PLR0904", # too-many-public-methods + "PLR0912", # too-many-branches + "PLR0916", # too-many-boolean-expressions + "PLR6301", # could-be-static no-self-use + "PLC0415", # import outside toplevel + "PLC2701", # private import ] [format] From 8566650725e22c3943b39025dc18ca5b123c42c6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 31 May 2025 11:09:17 -0500 Subject: [PATCH 135/137] displayio api update --- .../display_button_spritebutton_tft_featherwing_simpletest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/display_button_spritebutton_tft_featherwing_simpletest.py b/examples/display_button_spritebutton_tft_featherwing_simpletest.py index 006fd51..3c6ffd9 100644 --- a/examples/display_button_spritebutton_tft_featherwing_simpletest.py +++ b/examples/display_button_spritebutton_tft_featherwing_simpletest.py @@ -6,6 +6,7 @@ import board import digitalio import displayio +import fourwire import terminalio from adafruit_hx8357 import HX8357 # TFT Featherwing display driver @@ -20,7 +21,7 @@ spi = board.SPI() tft_cs = board.D9 tft_dc = board.D10 -display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) +display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs) display = HX8357(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT) display.rotation = 0 _touch_flip = (False, True) From 516504e210d5dbf2797fbab8843398e406e63cc3 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Jun 2025 10:00:20 -0500 Subject: [PATCH 136/137] update rtd.yml file Signed-off-by: foamyguy --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 88bca9f..255dafd 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -12,7 +12,7 @@ sphinx: configuration: docs/conf.py build: - os: ubuntu-20.04 + os: ubuntu-lts-latest tools: python: "3" From 91209c0425a4c619b9794d4d6887f81111b13f89 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 10 Oct 2025 16:18:40 -0500 Subject: [PATCH 137/137] remove deprecated ruff rule, workaround RTD theme property inline issue. Signed-off-by: foamyguy --- docs/_static/custom.css | 8 ++++++++ docs/conf.py | 3 +++ ruff.toml | 1 - 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 docs/_static/custom.css diff --git a/docs/_static/custom.css b/docs/_static/custom.css new file mode 100644 index 0000000..d60cf4b --- /dev/null +++ b/docs/_static/custom.css @@ -0,0 +1,8 @@ +/* SPDX-FileCopyrightText: 2025 Sam Blenny + * SPDX-License-Identifier: MIT + */ + +/* Monkey patch the rtd theme to prevent horizontal stacking of short items + * see https://github.com/readthedocs/sphinx_rtd_theme/issues/1301 + */ +.py.property{display: block !important;} diff --git a/docs/conf.py b/docs/conf.py index d657c39..013559e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -106,6 +106,9 @@ # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ["_static"] +# Include extra css to work around rtd theme glitches +html_css_files = ["custom.css"] + # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. diff --git a/ruff.toml b/ruff.toml index 73e9efc..2cc8fc7 100644 --- a/ruff.toml +++ b/ruff.toml @@ -17,7 +17,6 @@ extend-select = [ "PLC2401", # non-ascii-name "PLC2801", # unnecessary-dunder-call "PLC3002", # unnecessary-direct-lambda-call - "E999", # syntax-error "PLE0101", # return-in-init "F706", # return-outside-function "F704", # yield-outside-function