From 49b99916938ee4da721fbf2232d6d87f28ab49e5 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 9 Nov 2021 13:31:14 -0500 Subject: [PATCH 01/77] 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 c6cfe4e223bb665a5a3be667084ab5985de52133 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 15 Nov 2021 11:14:01 -0500 Subject: [PATCH 02/77] Remove gamepadshift from autodoc_mock_imports --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 46dc049..2e4a1b6 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", "gamepadshift"] +autodoc_mock_imports = ["displayio"] intersphinx_mapping = { From 0c6c613fdfc4e460e74067d9a9c6e30e2d052b99 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 15 Nov 2021 11:22:19 -0500 Subject: [PATCH 03/77] Modify library to swap GamePadShift with ShiftRegisterKeys --- .../cursorcontrol_cursormanager.py | 68 +++++++++++-------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 1b4cbcf..4d9e841 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -9,19 +9,19 @@ * Author(s): Brent Rubell """ import board -import digitalio from micropython import const import analogio -from gamepadshift import GamePadShift +from keypad import ShiftRegisterKeys from adafruit_debouncer import Debouncer + # PyBadge -PYBADGE_BUTTON_LEFT = const(128) -PYBADGE_BUTTON_UP = const(64) -PYBADGE_BUTTON_DOWN = const(32) -PYBADGE_BUTTON_RIGHT = const(16) +PYBADGE_BUTTON_LEFT = const(7) +PYBADGE_BUTTON_UP = const(6) +PYBADGE_BUTTON_DOWN = const(5) +PYBADGE_BUTTON_RIGHT = const(4) # PyBadge & PyGamer -PYBADGE_BUTTON_A = const(2) +PYBADGE_BUTTON_A = const(1) class CursorManager: @@ -66,6 +66,7 @@ def _init_hardware(self): "btn_down": PYBADGE_BUTTON_DOWN, "btn_a": PYBADGE_BUTTON_A, } + self._pad_states = 0 elif hasattr(board, "JOYSTICK_X"): self._joystick_x = analogio.AnalogIn(board.JOYSTICK_X) self._joystick_y = analogio.AnalogIn(board.JOYSTICK_Y) @@ -77,10 +78,12 @@ def _init_hardware(self): raise AttributeError( "Board must have a D-Pad or Joystick for use with CursorManager!" ) - self._pad = GamePadShift( - digitalio.DigitalInOut(board.BUTTON_CLOCK), - digitalio.DigitalInOut(board.BUTTON_OUT), - digitalio.DigitalInOut(board.BUTTON_LATCH), + self._pad = ShiftRegisterKeys( + clock = board.BUTTON_CLOCK, + data = board.BUTTON_OUT, + latch = board.BUTTON_LATCH, + key_count=8, + value_when_pressed=True ) @property @@ -92,11 +95,12 @@ def is_clicked(self): def update(self): """Updates the cursor object.""" - pressed = self._pad.get_pressed() - self._check_cursor_movement(pressed) + event = self._pad.events.get() + self._store_button_states(event) + self._check_cursor_movement(event) if self._is_clicked: self._is_clicked = False - elif pressed & self._pad_btns["btn_a"]: + elif self._pad_states & (1 << self._pad_btns["btn_a"]): self._is_clicked = True def _read_joystick_x(self, samples=3): @@ -118,24 +122,34 @@ def _read_joystick_y(self, samples=3): reading = 0 # pylint: disable=unused-variable if hasattr(board, "JOYSTICK_Y"): - for sample in range(0, samples): + for _ in range(0, samples): reading += self._joystick_y.value reading /= samples return reading - def _check_cursor_movement(self, pressed=None): - """Checks the PyBadge D-Pad or the PyGamer's Joystick for movement. - :param int pressed: 8-bit number with bits that correspond to buttons - which have been pressed down since the last call to get_pressed(). + def _store_button_states(self, event): + """Stores the state of the PyBadge's D-Pad or the PyGamer's Joystick + into a byte + + :param Event event: The latest button press transition event detected. """ + if event: + bit_index = event.key_number + current_state = (self._pad_states >> bit_index) + if current_state != event.pressed: + self._pad_states = (1 << bit_index) ^ self._pad_states + + def _check_cursor_movement(self): + """Checks the PyBadge D-Pad or the PyGamer's Joystick for movement.""" if hasattr(board, "BUTTON_CLOCK") and not hasattr(board, "JOYSTICK_X"): - if pressed & self._pad_btns["btn_right"]: + if self._pad_states & (1 << self._pad_btns["btn_right"]): self._cursor.x += self._cursor.speed - elif pressed & self._pad_btns["btn_left"]: + elif self._pad_states & (1 << self._pad_btns["btn_left"]): self._cursor.x -= self._cursor.speed - if pressed & self._pad_btns["btn_up"]: + + if self._pad_states & (1 << self._pad_btns["btn_up"]): self._cursor.y -= self._cursor.speed - elif pressed & self._pad_btns["btn_down"]: + elif self._pad_states & (1 << self._pad_btns["btn_down"]): self._cursor.y += self._cursor.speed elif hasattr(board, "JOYSTICK_X"): joy_x = self._read_joystick_x() @@ -165,9 +179,8 @@ class DebouncedCursorManager(CursorManager): def __init__(self, cursor, debounce_interval=0.01): CursorManager.__init__(self, cursor) - self._pressed = 0 self._debouncer = Debouncer( - lambda: bool(self._pressed & self._pad_btns["btn_a"]), + lambda: bool(self._pad_states & (1 << self._pad_btns["btn_a"])), interval=debounce_interval, ) @@ -194,6 +207,7 @@ def held(self): def update(self): """Updates the cursor object.""" - self._pressed = self._pad.get_pressed() - self._check_cursor_movement(self._pressed) + event = self._pad.events.get() + self._store_button_states(event) + self._check_cursor_movement() self._debouncer.update() From cc018cd6f8fdaa09d6a5e86fa412efed0eb85a2d Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 15 Nov 2021 11:23:54 -0500 Subject: [PATCH 04/77] Add license to __init --- adafruit_cursorcontrol/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adafruit_cursorcontrol/__init__.py b/adafruit_cursorcontrol/__init__.py index e69de29..097ed25 100644 --- a/adafruit_cursorcontrol/__init__.py +++ b/adafruit_cursorcontrol/__init__.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2019 Brent Rubell for Adafruit Industries +# +# SPDX-License-Identifier: MIT + From 1c128525819f8280aa42b9c89193432771c1cdd9 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 15 Nov 2021 11:24:10 -0500 Subject: [PATCH 05/77] Add version and repo information --- adafruit_cursorcontrol/__init__.py | 3 +++ adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/adafruit_cursorcontrol/__init__.py b/adafruit_cursorcontrol/__init__.py index 097ed25..464cd24 100644 --- a/adafruit_cursorcontrol/__init__.py +++ b/adafruit_cursorcontrol/__init__.py @@ -2,3 +2,6 @@ # # SPDX-License-Identifier: MIT +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" + diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 4d9e841..637baff 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -14,6 +14,9 @@ from keypad import ShiftRegisterKeys from adafruit_debouncer import Debouncer +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_Eddystone.git" + # PyBadge PYBADGE_BUTTON_LEFT = const(7) From 10d26316a597e05e8f25b72c5775fbde84010f64 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 15 Nov 2021 11:34:44 -0500 Subject: [PATCH 06/77] Add module docstring for __init__.py --- adafruit_cursorcontrol/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/adafruit_cursorcontrol/__init__.py b/adafruit_cursorcontrol/__init__.py index 464cd24..d2e86af 100644 --- a/adafruit_cursorcontrol/__init__.py +++ b/adafruit_cursorcontrol/__init__.py @@ -1,7 +1,14 @@ # SPDX-FileCopyrightText: 2019 Brent Rubell for Adafruit Industries # # SPDX-License-Identifier: MIT +""" +`adafruit_cursorcontrol.cursorcontrol_cursormanager` +================================================================================ +Mouse cursor for interaction with CircuitPython UI elements +* Author(s): Brent Rubell + +""" __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" From b0d6861962047ec9b9f43d29848fdca44e6e368e Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 15 Nov 2021 11:35:00 -0500 Subject: [PATCH 07/77] Fix repo variable --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 637baff..cc8a3e0 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -15,7 +15,7 @@ from adafruit_debouncer import Debouncer __version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_Eddystone.git" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" # PyBadge From 6e5884b0c895eac87b3a55e94bd1e8687c8b3fcf Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 15 Nov 2021 11:35:21 -0500 Subject: [PATCH 08/77] Add _pad_states to __init__() per pylint recommendation --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index cc8a3e0..07841d4 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -36,6 +36,7 @@ class CursorManager: def __init__(self, cursor): self._cursor = cursor self._is_clicked = False + self._pad_states = 0 self._init_hardware() def __enter__(self): From 092e3e66435a2b950e9c3ba1c490bec89a580129 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 15 Nov 2021 11:35:47 -0500 Subject: [PATCH 09/77] Remove event argument from _check_cursor_movement() --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 07841d4..854c4e1 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -101,7 +101,7 @@ def update(self): """Updates the cursor object.""" event = self._pad.events.get() self._store_button_states(event) - self._check_cursor_movement(event) + self._check_cursor_movement() if self._is_clicked: self._is_clicked = False elif self._pad_states & (1 << self._pad_btns["btn_a"]): From 65802879084cd365fada427c50745b8000b368a9 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 15 Nov 2021 11:36:04 -0500 Subject: [PATCH 10/77] Reformatted per pre-commit --- adafruit_cursorcontrol/__init__.py | 1 - .../cursorcontrol_cursormanager.py | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/adafruit_cursorcontrol/__init__.py b/adafruit_cursorcontrol/__init__.py index d2e86af..b49f500 100644 --- a/adafruit_cursorcontrol/__init__.py +++ b/adafruit_cursorcontrol/__init__.py @@ -11,4 +11,3 @@ """ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" - diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 854c4e1..5c559ea 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -83,11 +83,11 @@ def _init_hardware(self): "Board must have a D-Pad or Joystick for use with CursorManager!" ) self._pad = ShiftRegisterKeys( - clock = board.BUTTON_CLOCK, - data = board.BUTTON_OUT, - latch = board.BUTTON_LATCH, + clock=board.BUTTON_CLOCK, + data=board.BUTTON_OUT, + latch=board.BUTTON_LATCH, key_count=8, - value_when_pressed=True + value_when_pressed=True, ) @property @@ -134,12 +134,12 @@ def _read_joystick_y(self, samples=3): def _store_button_states(self, event): """Stores the state of the PyBadge's D-Pad or the PyGamer's Joystick into a byte - + :param Event event: The latest button press transition event detected. """ if event: bit_index = event.key_number - current_state = (self._pad_states >> bit_index) + current_state = self._pad_states >> bit_index if current_state != event.pressed: self._pad_states = (1 << bit_index) ^ self._pad_states From 72abb178548f4569d71dddfc33198460de2f527a Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Mon, 15 Nov 2021 20:50:02 -0500 Subject: [PATCH 11/77] Switch to use get_into, add missing bit mask operation --- .../cursorcontrol_cursormanager.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 5c559ea..6789599 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -37,6 +37,7 @@ def __init__(self, cursor): self._cursor = cursor self._is_clicked = False self._pad_states = 0 + self._event = None self._init_hardware() def __enter__(self): @@ -99,8 +100,8 @@ def is_clicked(self): def update(self): """Updates the cursor object.""" - event = self._pad.events.get() - self._store_button_states(event) + if self._pad.events.get_into(self._event): + self._store_button_states() self._check_cursor_movement() if self._is_clicked: self._is_clicked = False @@ -131,17 +132,16 @@ def _read_joystick_y(self, samples=3): reading /= samples return reading - def _store_button_states(self, event): + def _store_button_states(self): """Stores the state of the PyBadge's D-Pad or the PyGamer's Joystick into a byte :param Event event: The latest button press transition event detected. """ - if event: - bit_index = event.key_number - current_state = self._pad_states >> bit_index - if current_state != event.pressed: - self._pad_states = (1 << bit_index) ^ self._pad_states + bit_index = self._event.key_number + current_state = (self._pad_states >> bit_index) & 1 + if current_state != self._event.pressed: + self._pad_states = (1 << bit_index) ^ self._pad_states def _check_cursor_movement(self): """Checks the PyBadge D-Pad or the PyGamer's Joystick for movement.""" @@ -211,7 +211,7 @@ def held(self): def update(self): """Updates the cursor object.""" - event = self._pad.events.get() - self._store_button_states(event) + if self._pad.events.get_into(self._event): + self._store_button_states() self._check_cursor_movement() self._debouncer.update() From b6101eae57f663707b0275bb1119faa6a444cc70 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Mon, 15 Nov 2021 20:50:19 -0500 Subject: [PATCH 12/77] Use underscore for throwaway variable --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 6789599..e6676aa 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -115,7 +115,7 @@ def _read_joystick_x(self, samples=3): reading = 0 # pylint: disable=unused-variable if hasattr(board, "JOYSTICK_X"): - for sample in range(0, samples): + for _ in range(0, samples): reading += self._joystick_x.value reading /= samples return reading From a91babc7557590988eca9f294747d85e2ebcd2f9 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Mon, 15 Nov 2021 22:24:29 -0500 Subject: [PATCH 13/77] Initialize self._event as Event --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index e6676aa..c06c22b 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -11,7 +11,7 @@ import board from micropython import const import analogio -from keypad import ShiftRegisterKeys +from keypad import ShiftRegisterKeys, Event from adafruit_debouncer import Debouncer __version__ = "0.0.0-auto.0" @@ -37,7 +37,7 @@ def __init__(self, cursor): self._cursor = cursor self._is_clicked = False self._pad_states = 0 - self._event = None + self._event = Event() self._init_hardware() def __enter__(self): From 0f9df2b4fbad68d71c352b68c644c7af6a6e871f Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Mon, 15 Nov 2021 22:25:33 -0500 Subject: [PATCH 14/77] Deinit self._event to None when needed --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index c06c22b..3ebe4c6 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -52,6 +52,7 @@ def deinit(self): self._pad.deinit() self._cursor.deinit() self._cursor = None + self._event = None def _is_deinited(self): """Checks if CursorManager object has been deinitd.""" From cb0d0f9be40db8a2873b109a77523afd56c494e4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 23 Nov 2021 13:13:02 -0600 Subject: [PATCH 15/77] 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 73653bbc7c50b4282702b8e52a5661b7aab6e0b0 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 09:53:15 -0500 Subject: [PATCH 16/77] Update cursor param to be of type Cursor in CursorManager class docstring --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 3ebe4c6..439eb01 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -30,7 +30,7 @@ class CursorManager: """Simple interaction user interface interaction for Adafruit_CursorControl. - :param adafruit_cursorcontrol cursor: The cursor object we are using. + :param Cursor cursor: The cursor object we are using. """ def __init__(self, cursor): From 41badb4150fe1a5947269c0f58f171ab0d046bf8 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 09:53:43 -0500 Subject: [PATCH 17/77] Remove event param from _store_button_states() method docstring --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 439eb01..983891d 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -136,8 +136,6 @@ def _read_joystick_y(self, samples=3): def _store_button_states(self): """Stores the state of the PyBadge's D-Pad or the PyGamer's Joystick into a byte - - :param Event event: The latest button press transition event detected. """ bit_index = self._event.key_number current_state = (self._pad_states >> bit_index) & 1 From e11fd780afb4733e2af48054bd4c74af657aaa2d Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 09:54:25 -0500 Subject: [PATCH 18/77] Change cursor param type to Cursor in DebouncedCursorManager class docstring --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 983891d..5850c73 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -177,7 +177,7 @@ class DebouncedCursorManager(CursorManager): the button is just pressed, and just released, as well it's current state. "Just" in this context means "since the previous call to update." - :param adafruit_cursorcontrol cursor: The cursor object we are using. + :param Cursor cursor: The cursor object we are using. """ def __init__(self, cursor, debounce_interval=0.01): From df9845722ca3b37cbcdf1bea37e6dc00bce8f92d Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 09:54:37 -0500 Subject: [PATCH 19/77] Add type hints for cursorcontrol_cursormanager.py --- .../cursorcontrol_cursormanager.py | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 5850c73..06be50b 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -14,6 +14,13 @@ from keypad import ShiftRegisterKeys, Event from adafruit_debouncer import Debouncer +try: + from typing import Optional, Type + from types import TracebackType + from adafruit_cursorcontrol.cursorcontrol import Cursor +except ImportError: + pass + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" @@ -33,20 +40,20 @@ class CursorManager: :param Cursor cursor: The cursor object we are using. """ - def __init__(self, cursor): + def __init__(self, cursor: Cursor) -> None: self._cursor = cursor self._is_clicked = False self._pad_states = 0 self._event = Event() self._init_hardware() - def __enter__(self): + def __enter__(self) -> 'CursorManager': return self - def __exit__(self, exception_type, exception_value, traceback): + def __exit__(self, exception_type: Optional[Type[type]], exception_value: Optional[BaseException], traceback: Optional[TracebackType]) -> None: self.deinit() - def deinit(self): + def deinit(self) -> None: """Deinitializes a CursorManager object.""" self._is_deinited() self._pad.deinit() @@ -54,7 +61,7 @@ def deinit(self): self._cursor = None self._event = None - def _is_deinited(self): + def _is_deinited(self) -> None: """Checks if CursorManager object has been deinitd.""" if self._cursor is None: raise ValueError( @@ -62,7 +69,7 @@ def _is_deinited(self): "be used. Create a new CursorManager object." ) - def _init_hardware(self): + def _init_hardware(self) -> None: """Initializes PyBadge or PyGamer hardware.""" if hasattr(board, "BUTTON_CLOCK") and not hasattr(board, "JOYSTICK_X"): self._pad_btns = { @@ -93,13 +100,13 @@ def _init_hardware(self): ) @property - def is_clicked(self): + def is_clicked(self) -> bool: """Returns True if the cursor button was pressed during previous call to update() """ return self._is_clicked - def update(self): + def update(self) -> None: """Updates the cursor object.""" if self._pad.events.get_into(self._event): self._store_button_states() @@ -109,7 +116,7 @@ def update(self): elif self._pad_states & (1 << self._pad_btns["btn_a"]): self._is_clicked = True - def _read_joystick_x(self, samples=3): + def _read_joystick_x(self, samples: int = 3) -> float: """Read the X analog joystick on the PyGamer. :param int samples: How many samples to read and average. """ @@ -121,7 +128,7 @@ def _read_joystick_x(self, samples=3): reading /= samples return reading - def _read_joystick_y(self, samples=3): + def _read_joystick_y(self, samples: int = 3) -> float: """Read the Y analog joystick on the PyGamer. :param int samples: How many samples to read and average. """ @@ -133,7 +140,7 @@ def _read_joystick_y(self, samples=3): reading /= samples return reading - def _store_button_states(self): + def _store_button_states(self) -> None: """Stores the state of the PyBadge's D-Pad or the PyGamer's Joystick into a byte """ @@ -142,7 +149,7 @@ def _store_button_states(self): if current_state != self._event.pressed: self._pad_states = (1 << bit_index) ^ self._pad_states - def _check_cursor_movement(self): + def _check_cursor_movement(self) -> None: """Checks the PyBadge D-Pad or the PyGamer's Joystick for movement.""" if hasattr(board, "BUTTON_CLOCK") and not hasattr(board, "JOYSTICK_X"): if self._pad_states & (1 << self._pad_btns["btn_right"]): @@ -180,7 +187,7 @@ class DebouncedCursorManager(CursorManager): :param Cursor cursor: The cursor object we are using. """ - def __init__(self, cursor, debounce_interval=0.01): + def __init__(self, cursor: Cursor, debounce_interval: float = 0.01) -> None: CursorManager.__init__(self, cursor) self._debouncer = Debouncer( lambda: bool(self._pad_states & (1 << self._pad_btns["btn_a"])), @@ -188,7 +195,7 @@ def __init__(self, cursor, debounce_interval=0.01): ) @property - def is_clicked(self): + def is_clicked(self) -> bool: """Returns True if the cursor button was pressed during previous call to update() """ @@ -197,18 +204,18 @@ def is_clicked(self): pressed = is_clicked @property - def released(self): + def released(self) -> bool: """Returns True if the cursor button was released during previous call to update() """ return self._debouncer.fell @property - def held(self): + def held(self) -> bool: """Returns True if the cursor button is currently being held""" return self._debouncer.value - def update(self): + def update(self) -> None: """Updates the cursor object.""" if self._pad.events.get_into(self._event): self._store_button_states() From 2830cd2a4a347d1077d0751ff0caf503e82a30c8 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 10:13:23 -0500 Subject: [PATCH 20/77] Moved is_hidden param for Cursor class docstring before cursor_speed --- adafruit_cursorcontrol/cursorcontrol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index 2e6e6a3..72c618d 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -31,9 +31,9 @@ class Cursor: :param ~displayio.Display display: CircuitPython display object. :param ~displayio.Group display_group: CircuitPython group object to append the cursor to. + :param bool is_hidden: Cursor is hidden on init. :param int cursor_speed: Speed of the cursor, in pixels. :param int scale: Scale amount for the cursor in both directions. - :param bool is_hidden: Cursor is hidden on init. Example for creating a cursor layer From 1d3c90f9e36dc72ec7542e4c84e2af683dbc2e9b Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 10:15:21 -0500 Subject: [PATCH 21/77] Added bmp param in Cursor class docstring --- adafruit_cursorcontrol/cursorcontrol.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index 72c618d..815dd81 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -31,6 +31,7 @@ class Cursor: :param ~displayio.Display display: CircuitPython display object. :param ~displayio.Group display_group: CircuitPython group object to append the cursor to. + :param ~displayio.Bitmap bmp: CircuitPython bitmap object to use as the cursor :param bool is_hidden: Cursor is hidden on init. :param int cursor_speed: Speed of the cursor, in pixels. :param int scale: Scale amount for the cursor in both directions. From d9cc55efb5de8a69a6b9c6f7fbc74095edda8808 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 10:23:21 -0500 Subject: [PATCH 22/77] Add type to bmp param in Cursor.cursor_bitmap() docstring --- adafruit_cursorcontrol/cursorcontrol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index 815dd81..532891f 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -218,7 +218,7 @@ def cursor_bitmap(self): def cursor_bitmap(self, bmp): """Set a new cursor bitmap. - :param bmp: A Bitmap to use for the cursor + :param ~displayio.Bitmap bmp: A Bitmap to use for the cursor """ self._cursor_bitmap = bmp self._cursor_grp.remove(self._cur_sprite) From 47547ad65d8f6af41644c4da07f8eb1ad5aadd53 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 10:27:01 -0500 Subject: [PATCH 23/77] Add bmp param to docstring of Cursor.generate_cursor() --- adafruit_cursorcontrol/cursorcontrol.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index 532891f..ce9c3be 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -226,7 +226,10 @@ def cursor_bitmap(self, bmp): self._cursor_grp.append(self._cur_sprite) def generate_cursor(self, bmp): - """Generates a cursor icon""" + """Generates a cursor icon + + :param ~displayio.Bitmap bmp: Bitmap to use for the cursor + """ self._is_deinited() self._cursor_grp = displayio.Group(scale=self._scale) self._cur_palette = displayio.Palette(3) From 73297547e37224ae83dbab9799adc780c728c32c Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 10:29:38 -0500 Subject: [PATCH 24/77] Update bmp param text in Cursor.generate_cursor() docstring --- adafruit_cursorcontrol/cursorcontrol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index ce9c3be..6355fb7 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -228,7 +228,7 @@ def cursor_bitmap(self, bmp): def generate_cursor(self, bmp): """Generates a cursor icon - :param ~displayio.Bitmap bmp: Bitmap to use for the cursor + :param ~displayio.Bitmap bmp: A Bitmap to use for the cursor """ self._is_deinited() self._cursor_grp = displayio.Group(scale=self._scale) From 74b48dedb994991e6cee4355d5228fc071d18498 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 10:30:12 -0500 Subject: [PATCH 25/77] Add type hints for cursorcontrol.py --- adafruit_cursorcontrol/cursorcontrol.py | 58 ++++++++++++++----------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index 6355fb7..9f58e33 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -22,6 +22,12 @@ """ import displayio +try: + from typing import Optional, Type + from types import TracebackType +except ImportError: + pass + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" @@ -54,12 +60,12 @@ class Cursor: # pylint: disable=too-many-arguments,line-too-long def __init__( self, - display=None, - display_group=None, - bmp=None, - is_hidden=False, - cursor_speed=5, - scale=1, + display: Optional[displayio.Display] = None, + display_group: Optional[displayio.Group] = None, + bmp: Optional[displayio.Bitmap] = None, + is_hidden: bool = False, + cursor_speed: int = 5, + scale: int = 1, ): self._display = display self._scale = scale @@ -76,19 +82,19 @@ def __init__( # pylint: enable=too-many-arguments,line-too-long - def __enter__(self): + def __enter__(self) -> 'Cursor': return self - def __exit__(self, exception_type, exception_value, traceback): + def __exit__(self, exception_type: Optional[Type[type]], exception_value: Optional[BaseException], traceback: Optional[TracebackType]) -> None: self.deinit() - def deinit(self): + def deinit(self) -> None: """deinitializes the cursor object.""" self._is_deinited() self._scale = None self._display_grp.remove(self._cursor_grp) - def _is_deinited(self): + def _is_deinited(self) -> None: """checks cursor deinitialization""" if self._scale is None: raise ValueError( @@ -97,12 +103,12 @@ def _is_deinited(self): ) @property - def scale(self): + def scale(self) -> int: """Returns the cursor's scale amount as an integer.""" return self._scale @scale.setter - def scale(self, scale_value): + def scale(self, scale_value: int) -> None: """Scales the cursor by scale_value in both directions. :param int scale_value: Amount to scale the cursor by. """ @@ -112,12 +118,12 @@ def scale(self, scale_value): self._cursor_grp.scale = scale_value @property - def speed(self): + def speed(self) -> int: """Returns the cursor's speed, in pixels.""" return self._speed @speed.setter - def speed(self, speed): + def speed(self, speed: int) -> None: """Sets the speed of the cursor. :param int speed: Cursor movement speed, in pixels. """ @@ -126,12 +132,12 @@ def speed(self, speed): self._speed = speed @property - def x(self): + def x(self) -> int: """Returns the cursor's x-coordinate.""" return self._cursor_grp.x @x.setter - def x(self, x_val): + def x(self, x_val: int) -> None: """Sets the x-value of the cursor. :param int x_val: cursor x-position, in pixels. """ @@ -144,12 +150,12 @@ def x(self, x_val): self._cursor_grp.x = x_val @property - def y(self): + def y(self) -> int: """Returns the cursor's y-coordinate.""" return self._cursor_grp.y @y.setter - def y(self, y_val): + def y(self, y_val: int) -> None: """Sets the y-value of the cursor. :param int y_val: cursor y-position, in pixels. """ @@ -162,12 +168,12 @@ def y(self, y_val): self._cursor_grp.y = y_val @property - def hidden(self): + def hidden(self) -> bool: """Returns True if the cursor is hidden or visible on the display.""" return self._is_hidden @hidden.setter - def hidden(self, is_hidden): + def hidden(self, is_hidden: bool) -> None: self._is_deinited() if is_hidden: self._is_hidden = True @@ -176,16 +182,16 @@ def hidden(self, is_hidden): self._is_hidden = False self._display_grp.append(self._cursor_grp) - def hide(self): + def hide(self) -> None: """Hide the cursor.""" self.hidden = True - def show(self): + def show(self) -> None: """Show the cursor.""" self.hidden = False # pylint:disable=no-self-use - def _default_cursor_bitmap(self): + def _default_cursor_bitmap(self) -> displayio.Bitmap: bmp = displayio.Bitmap(20, 20, 3) # left edge, outline for i in range(0, bmp.height): @@ -210,12 +216,12 @@ def _default_cursor_bitmap(self): # pylint:enable=no-self-use @property - def cursor_bitmap(self): + def cursor_bitmap(self) -> displayio.Bitmap: """Return the cursor bitmap.""" return self._cursor_bitmap @cursor_bitmap.setter - def cursor_bitmap(self, bmp): + def cursor_bitmap(self, bmp: displayio.Bitmap) -> None: """Set a new cursor bitmap. :param ~displayio.Bitmap bmp: A Bitmap to use for the cursor @@ -225,7 +231,7 @@ def cursor_bitmap(self, bmp): self._cur_sprite = displayio.TileGrid(bmp, pixel_shader=self._cur_palette) self._cursor_grp.append(self._cur_sprite) - def generate_cursor(self, bmp): + def generate_cursor(self, bmp: displayio.Bitmap) -> None: """Generates a cursor icon :param ~displayio.Bitmap bmp: A Bitmap to use for the cursor From 214cbc6e2d3db7a8e2e5373106d9160d9ede22c6 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 15 Dec 2021 10:31:10 -0500 Subject: [PATCH 26/77] Reformatted per pre-commit --- adafruit_cursorcontrol/cursorcontrol.py | 11 ++++++++--- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index 9f58e33..7eec0cf 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -82,10 +82,15 @@ def __init__( # pylint: enable=too-many-arguments,line-too-long - def __enter__(self) -> 'Cursor': + def __enter__(self) -> "Cursor": return self - def __exit__(self, exception_type: Optional[Type[type]], exception_value: Optional[BaseException], traceback: Optional[TracebackType]) -> None: + def __exit__( + self, + exception_type: Optional[Type[type]], + exception_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: self.deinit() def deinit(self) -> None: @@ -233,7 +238,7 @@ def cursor_bitmap(self, bmp: displayio.Bitmap) -> None: def generate_cursor(self, bmp: displayio.Bitmap) -> None: """Generates a cursor icon - + :param ~displayio.Bitmap bmp: A Bitmap to use for the cursor """ self._is_deinited() diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 06be50b..7526ff3 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -47,10 +47,15 @@ def __init__(self, cursor: Cursor) -> None: self._event = Event() self._init_hardware() - def __enter__(self) -> 'CursorManager': + def __enter__(self) -> "CursorManager": return self - def __exit__(self, exception_type: Optional[Type[type]], exception_value: Optional[BaseException], traceback: Optional[TracebackType]) -> None: + def __exit__( + self, + exception_type: Optional[Type[type]], + exception_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: self.deinit() def deinit(self) -> None: From 5d70444559c7cb2e0ff7ddc4de9e0a1162d30b87 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 15 Dec 2021 20:38:52 -0600 Subject: [PATCH 27/77] implement is_alt_clicked --- .../cursorcontrol_cursormanager.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 7526ff3..e36cf47 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -32,6 +32,7 @@ PYBADGE_BUTTON_RIGHT = const(4) # PyBadge & PyGamer PYBADGE_BUTTON_A = const(1) +PYBADGE_BUTTON_B = const(0) class CursorManager: @@ -43,6 +44,7 @@ class CursorManager: def __init__(self, cursor: Cursor) -> None: self._cursor = cursor self._is_clicked = False + self._is_alt_clicked = False self._pad_states = 0 self._event = Event() self._init_hardware() @@ -83,12 +85,13 @@ def _init_hardware(self) -> None: "btn_up": PYBADGE_BUTTON_UP, "btn_down": PYBADGE_BUTTON_DOWN, "btn_a": PYBADGE_BUTTON_A, + "btn_b": PYBADGE_BUTTON_B, } self._pad_states = 0 elif hasattr(board, "JOYSTICK_X"): self._joystick_x = analogio.AnalogIn(board.JOYSTICK_X) self._joystick_y = analogio.AnalogIn(board.JOYSTICK_Y) - self._pad_btns = {"btn_a": PYBADGE_BUTTON_A} + self._pad_btns = {"btn_a": PYBADGE_BUTTON_A, "btn_b": PYBADGE_BUTTON_B} # Sample the center points of the joystick self._center_x = self._joystick_x.value self._center_y = self._joystick_y.value @@ -111,6 +114,13 @@ def is_clicked(self) -> bool: """ return self._is_clicked + @property + def is_alt_clicked(self) -> bool: + """Returns True if the cursor button was pressed + during previous call to update() + """ + return self._is_alt_clicked + def update(self) -> None: """Updates the cursor object.""" if self._pad.events.get_into(self._event): @@ -121,6 +131,11 @@ def update(self) -> None: elif self._pad_states & (1 << self._pad_btns["btn_a"]): self._is_clicked = True + if self._is_alt_clicked: + self._is_alt_clicked = False + elif self._pad_states & (1 << self._pad_btns["btn_b"]): + self._is_alt_clicked = True + def _read_joystick_x(self, samples: int = 3) -> float: """Read the X analog joystick on the PyGamer. :param int samples: How many samples to read and average. From f0cdda462a872eccf297cc0b77f7a945ea6b1f06 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 13 Jan 2022 16:27:30 -0500 Subject: [PATCH 28/77] 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 afe153969746cf69a87b221cba2f914adaaea185 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 Jan 2022 16:46:16 -0500 Subject: [PATCH 29/77] 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 8520452..8e9cab6 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ Introduction ============ .. image:: https://readthedocs.org/projects/cursorcontrol/badge/?version=latest - :target: https://circuitpython.readthedocs.io/projects/cursorcontrol/en/latest/ + :target: https://docs.circuitpython.org/projects/cursorcontrol/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 2e4a1b6..9676807 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 fd29c85..8b03c2f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,7 +30,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 96da48e..ae75042 100644 --- a/setup.py +++ b/setup.py @@ -44,8 +44,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 cursorcontrol mouse, cursor, ui", From 162f56b7d63563f80e49ed711264ef5a6bab564d Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Thu, 10 Feb 2022 09:41:59 -0500 Subject: [PATCH 30/77] Consolidate Documentation sections of README --- README.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 8e9cab6..64c4f4d 100644 --- a/README.rst +++ b/README.rst @@ -60,14 +60,11 @@ 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 ============ Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. - -Documentation -============= - -For information on building library documentation, please check out `this guide `_. From 43ff5c65287f6c339d39b0aff7ce7cd022984d5a Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 14 Feb 2022 15:35:02 -0500 Subject: [PATCH 31/77] 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 9a7326debd98bfec83227627b74ad44a69856a02 Mon Sep 17 00:00:00 2001 From: Florin Maticu Date: Sat, 26 Feb 2022 21:12:17 +0100 Subject: [PATCH 32/77] CursorManager: Add support for Start and Select buttons for PyGamer. --- .../cursorcontrol_cursormanager.py | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index e36cf47..4e0fe3a 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -31,6 +31,8 @@ PYBADGE_BUTTON_DOWN = const(5) PYBADGE_BUTTON_RIGHT = const(4) # PyBadge & PyGamer +PYBADGE_BUTTON_SELECT = const(3) +PYBADGE_BUTTON_START = const(2) PYBADGE_BUTTON_A = const(1) PYBADGE_BUTTON_B = const(0) @@ -45,6 +47,8 @@ def __init__(self, cursor: Cursor) -> None: self._cursor = cursor self._is_clicked = False self._is_alt_clicked = False + self._is_select_clicked = False + self._is_start_clicked = False self._pad_states = 0 self._event = Event() self._init_hardware() @@ -91,7 +95,10 @@ def _init_hardware(self) -> None: elif hasattr(board, "JOYSTICK_X"): self._joystick_x = analogio.AnalogIn(board.JOYSTICK_X) self._joystick_y = analogio.AnalogIn(board.JOYSTICK_Y) - self._pad_btns = {"btn_a": PYBADGE_BUTTON_A, "btn_b": PYBADGE_BUTTON_B} + self._pad_btns = {"btn_a": PYBADGE_BUTTON_A, + "btn_b": PYBADGE_BUTTON_B, + "btn_select": PYBADGE_BUTTON_SELECT, + "btn_start": PYBADGE_BUTTON_START} # Sample the center points of the joystick self._center_x = self._joystick_x.value self._center_y = self._joystick_y.value @@ -109,18 +116,32 @@ def _init_hardware(self) -> None: @property def is_clicked(self) -> bool: - """Returns True if the cursor button was pressed + """Returns True if the cursor A button was pressed during previous call to update() """ return self._is_clicked @property def is_alt_clicked(self) -> bool: - """Returns True if the cursor button was pressed + """Returns True if the cursor B button was pressed during previous call to update() """ return self._is_alt_clicked + @property + def is_select_clicked(self) -> bool: + """Returns True if the Select button was pressed + during previous call to update() + """ + return self._is_select_clicked + + @property + def is_start_clicked(self) -> bool: + """Returns True if the Start button was pressed + during previous call to update() + """ + return self._is_start_clicked + def update(self) -> None: """Updates the cursor object.""" if self._pad.events.get_into(self._event): @@ -136,6 +157,16 @@ def update(self) -> None: elif self._pad_states & (1 << self._pad_btns["btn_b"]): self._is_alt_clicked = True + if self._is_select_clicked: + self._is_select_clicked = False + elif self._pad_states & (1 << self._pad_btns["btn_select"]): + self._is_select_clicked = True + + if self._is_start_clicked: + self._is_start_clicked = False + elif self._pad_states & (1 << self._pad_btns["btn_start"]): + self._is_start_clicked = True + def _read_joystick_x(self, samples: int = 3) -> float: """Read the X analog joystick on the PyGamer. :param int samples: How many samples to read and average. From c0f902db520f43d1b3c6b35b22917ab9cc39a056 Mon Sep 17 00:00:00 2001 From: Florin Maticu Date: Sat, 26 Feb 2022 22:17:22 +0100 Subject: [PATCH 33/77] Disable pylint's attribute instances check. --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 4e0fe3a..ed0eb4f 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -42,6 +42,7 @@ class CursorManager: :param Cursor cursor: The cursor object we are using. """ + # pylint: disable=too-many-instance-attributes def __init__(self, cursor: Cursor) -> None: self._cursor = cursor From 75ec76394cd7b71c0662c306c67531a1724b7d99 Mon Sep 17 00:00:00 2001 From: Florin Maticu Date: Sat, 26 Feb 2022 22:26:17 +0100 Subject: [PATCH 34/77] Fix pylint errors. --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index ed0eb4f..d8c83eb 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -42,6 +42,7 @@ class CursorManager: :param Cursor cursor: The cursor object we are using. """ + # pylint: disable=too-many-instance-attributes def __init__(self, cursor: Cursor) -> None: @@ -96,10 +97,12 @@ def _init_hardware(self) -> None: elif hasattr(board, "JOYSTICK_X"): self._joystick_x = analogio.AnalogIn(board.JOYSTICK_X) self._joystick_y = analogio.AnalogIn(board.JOYSTICK_Y) - self._pad_btns = {"btn_a": PYBADGE_BUTTON_A, - "btn_b": PYBADGE_BUTTON_B, - "btn_select": PYBADGE_BUTTON_SELECT, - "btn_start": PYBADGE_BUTTON_START} + self._pad_btns = { + "btn_a": PYBADGE_BUTTON_A, + "btn_b": PYBADGE_BUTTON_B, + "btn_select": PYBADGE_BUTTON_SELECT, + "btn_start": PYBADGE_BUTTON_START, + } # Sample the center points of the joystick self._center_x = self._joystick_x.value self._center_y = self._joystick_y.value From eb648daa4adfd956dad839ad13aafe35d38f1c7e Mon Sep 17 00:00:00 2001 From: Florin Maticu Date: Sun, 27 Feb 2022 18:39:50 +0100 Subject: [PATCH 35/77] PyBadge: Add select and start button support. --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index d8c83eb..dd46f9d 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -92,6 +92,8 @@ def _init_hardware(self) -> None: "btn_down": PYBADGE_BUTTON_DOWN, "btn_a": PYBADGE_BUTTON_A, "btn_b": PYBADGE_BUTTON_B, + "btn_select": PYBADGE_BUTTON_SELECT, + "btn_start": PYBADGE_BUTTON_START, } self._pad_states = 0 elif hasattr(board, "JOYSTICK_X"): From 5e75cadc20763607abdfc5f6d599e35afdac5e19 Mon Sep 17 00:00:00 2001 From: Florin Maticu Date: Sun, 27 Feb 2022 19:02:51 +0100 Subject: [PATCH 36/77] Add debouncer support for B,Select and Start buttons. --- .../cursorcontrol_cursormanager.py | 90 +++++++++++++++---- 1 file changed, 74 insertions(+), 16 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index dd46f9d..4208247 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -236,45 +236,103 @@ def _check_cursor_movement(self) -> None: class DebouncedCursorManager(CursorManager): - """Simple interaction user interface interaction for Adafruit_CursorControl. - This subclass provide a debounced version on the A button and provides queries for when - the button is just pressed, and just released, as well it's current state. "Just" in this - context means "since the previous call to update." + """Simple user interface interaction for Adafruit_CursorControl. + This subclass provide a debounced version on the A, B, Start or Select buttons + and provides queries for when the buttons are just pressed, and just released, + as well their current state. "Just" in this context means "since the previous call to update." :param Cursor cursor: The cursor object we are using. """ def __init__(self, cursor: Cursor, debounce_interval: float = 0.01) -> None: CursorManager.__init__(self, cursor) - self._debouncer = Debouncer( - lambda: bool(self._pad_states & (1 << self._pad_btns["btn_a"])), - interval=debounce_interval, - ) + self._debouncers = {} + for btn, _ in self._pad_btns.items(): + self._debouncers[btn] = Debouncer( + lambda btn=btn: bool((self._pad_states & (1 << self._pad_btns[btn]))), + interval=debounce_interval, + ) @property def is_clicked(self) -> bool: - """Returns True if the cursor button was pressed + """Returns True if the cursor A button was pressed + during previous call to update() + """ + return self._debouncers["btn_a"].rose + + @property + def is_alt_clicked(self) -> bool: + """Returns True if the cursor B button was pressed during previous call to update() """ - return self._debouncer.rose + return self._debouncers["btn_b"].rose - pressed = is_clicked + @property + def is_select_clicked(self) -> bool: + """Returns True if the Select button was pressed + during previous call to update() + """ + return self._debouncers["btn_select"].rose + + @property + def is_start_clicked(self) -> bool: + """Returns True if the Start button was pressed + during previous call to update() + """ + return self._debouncers["btn_start"].rose @property def released(self) -> bool: - """Returns True if the cursor button was released + """Returns True if the cursor A button was released + during previous call to update() + """ + return self._debouncers["btn_a"].fell + + @property + def alt_released(self) -> bool: + """Returns True if the cursor B button was released during previous call to update() """ - return self._debouncer.fell + return self._debouncers["btn_b"].fell + + @property + def start_released(self) -> bool: + """Returns True if the cursor Start button was released + during previous call to update() + """ + return self._debouncers["btn_start"].fell + + @property + def select_released(self) -> bool: + """Returns True if the cursor Select button was released + during previous call to update() + """ + return self._debouncers["btn_select"].fell @property def held(self) -> bool: - """Returns True if the cursor button is currently being held""" - return self._debouncer.value + """Returns True if the cursor A button is currently being held""" + return self._debouncers["btn_a"].value + + @property + def alt_held(self) -> bool: + """Returns True if the cursor B button is currently being held""" + return self._debouncers["btn_b"].value + + @property + def start_held(self) -> bool: + """Returns True if the cursor Start button is currently being held""" + return self._debouncers["btn_start"].value + + @property + def select_held(self) -> bool: + """Returns True if the cursor Select is currently being held""" + return self._debouncers["btn_select"].value def update(self) -> None: """Updates the cursor object.""" if self._pad.events.get_into(self._event): self._store_button_states() self._check_cursor_movement() - self._debouncer.update() + for debouncer in self._debouncers.values(): + debouncer.update() From 649e84a78643ee2e73a1e17b056eaa69485ec2ca Mon Sep 17 00:00:00 2001 From: Florin Maticu Date: Mon, 28 Feb 2022 19:35:48 +0100 Subject: [PATCH 37/77] Add code example for debounced buttons + fix review comments. --- .../cursorcontrol_cursormanager.py | 2 +- examples/cursorcontrol_buttons_debounced.py | 158 ++++++++++++++++++ 2 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 examples/cursorcontrol_buttons_debounced.py diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 4208247..49cf53a 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -247,7 +247,7 @@ class DebouncedCursorManager(CursorManager): def __init__(self, cursor: Cursor, debounce_interval: float = 0.01) -> None: CursorManager.__init__(self, cursor) self._debouncers = {} - for btn, _ in self._pad_btns.items(): + for btn in self._pad_btns: self._debouncers[btn] = Debouncer( lambda btn=btn: bool((self._pad_states & (1 << self._pad_btns[btn]))), interval=debounce_interval, diff --git a/examples/cursorcontrol_buttons_debounced.py b/examples/cursorcontrol_buttons_debounced.py new file mode 100644 index 0000000..f1a9459 --- /dev/null +++ b/examples/cursorcontrol_buttons_debounced.py @@ -0,0 +1,158 @@ +# SPDX-FileCopyrightText: 2022 flom84 for Adafruit Industries +# SPDX-License-Identifier: MIT + +import time +import board +import displayio +import terminalio + +from adafruit_button import Button +from adafruit_cursorcontrol.cursorcontrol import Cursor +from adafruit_cursorcontrol.cursorcontrol_cursormanager import DebouncedCursorManager + +SELECT_BUTTON_X = 0 +SELECT_BUTTON_Y = 103 +SELECT_BUTTON_WIDTH = 60 +SELECT_BUTTON_HEIGHT = 25 +SELECT_BUTTON_STYLE = Button.ROUNDRECT +SELECT_BUTTON_OUTLINE_COLOR = 0xFFFFFF +SELECT_BUTTON_LABEL = "Select" +SELECT_BUTTON_LABEL_COLOR = 0xFFFFFF + +START_BUTTON_X = 100 +START_BUTTON_Y = 103 +START_BUTTON_WIDTH = 60 +START_BUTTON_HEIGHT = 25 +START_BUTTON_STYLE = Button.ROUNDRECT +START_BUTTON_OUTLINE_COLOR = 0xFFFFFF +START_BUTTON_LABEL = "Start" +START_BUTTON_LABEL_COLOR = 0xFFFFFF + +A_BUTTON_X = 120 +A_BUTTON_Y = 20 +A_BUTTON_WIDTH = 30 +A_BUTTON_HEIGHT = 30 +A_BUTTON_STYLE = Button.ROUNDRECT +A_BUTTON_OUTLINE_COLOR = 0xFFFFFF +A_BUTTON_LABEL = "A" +A_BUTTON_LABEL_COLOR = 0xFFFFFF + +B_BUTTON_X = 80 +B_BUTTON_Y = 30 +B_BUTTON_WIDTH = 30 +B_BUTTON_HEIGHT = 30 +B_BUTTON_STYLE = Button.ROUNDRECT +B_BUTTON_OUTLINE_COLOR = 0xFFFFFF +B_BUTTON_LABEL = "B" +B_BUTTON_LABEL_COLOR = 0xFFFFFF + +BUTTON_FILL_PURPLE = 0xB400FF +BUTTON_FILL_BLACK = 0x000000 + +start_button = Button( + x=START_BUTTON_X, + y=START_BUTTON_Y, + width=START_BUTTON_WIDTH, + height=START_BUTTON_HEIGHT, + style=START_BUTTON_STYLE, + fill_color=BUTTON_FILL_BLACK, + outline_color=START_BUTTON_OUTLINE_COLOR, + label=START_BUTTON_LABEL, + label_font=terminalio.FONT, + label_color=START_BUTTON_LABEL_COLOR, +) + +select_button = Button( + x=SELECT_BUTTON_X, + y=SELECT_BUTTON_Y, + width=SELECT_BUTTON_WIDTH, + height=SELECT_BUTTON_HEIGHT, + style=SELECT_BUTTON_STYLE, + fill_color=BUTTON_FILL_BLACK, + outline_color=SELECT_BUTTON_OUTLINE_COLOR, + label=SELECT_BUTTON_LABEL, + label_font=terminalio.FONT, + label_color=SELECT_BUTTON_LABEL_COLOR, +) + +a_button = Button( + x=A_BUTTON_X, + y=A_BUTTON_Y, + width=A_BUTTON_WIDTH, + height=A_BUTTON_HEIGHT, + style=A_BUTTON_STYLE, + fill_color=BUTTON_FILL_BLACK, + outline_color=A_BUTTON_OUTLINE_COLOR, + label=A_BUTTON_LABEL, + label_font=terminalio.FONT, + label_color=A_BUTTON_LABEL_COLOR, +) + +b_button = Button( + x=B_BUTTON_X, + y=B_BUTTON_Y, + width=B_BUTTON_WIDTH, + height=B_BUTTON_HEIGHT, + style=B_BUTTON_STYLE, + fill_color=BUTTON_FILL_BLACK, + outline_color=B_BUTTON_OUTLINE_COLOR, + label=B_BUTTON_LABEL, + label_font=terminalio.FONT, + label_color=B_BUTTON_LABEL_COLOR, +) + +# Create the display +display = board.DISPLAY + +# Create the display context +splash = displayio.Group() + +# initialize the mouse cursor object +mouse_cursor = Cursor(display, display_group=splash) + +# initialize the debounced cursor manager +debounced_cursor = DebouncedCursorManager(mouse_cursor) + +# create displayio group +splash.append(start_button) +splash.append(select_button) +splash.append(a_button) +splash.append(b_button) +display.show(splash) + +while True: + debounced_cursor.update() + + if debounced_cursor.is_clicked: + a_button.fill_color = BUTTON_FILL_PURPLE + print("A pressed: " + str(debounced_cursor.held)) + + if debounced_cursor.released: + a_button.fill_color = BUTTON_FILL_BLACK + print("A pressed: " + str(debounced_cursor.held)) + + if debounced_cursor.is_alt_clicked: + b_button.fill_color = BUTTON_FILL_PURPLE + print("B pressed: " + str(debounced_cursor.alt_held)) + + if debounced_cursor.alt_released: + b_button.fill_color = BUTTON_FILL_BLACK + print("B pressed: " + str(debounced_cursor.alt_held)) + + if debounced_cursor.is_start_clicked: + start_button.fill_color = BUTTON_FILL_PURPLE + print("Start pressed: " + str(debounced_cursor.start_held)) + + if debounced_cursor.start_released: + start_button.fill_color = BUTTON_FILL_BLACK + print("Start pressed: " + str(debounced_cursor.start_held)) + + if debounced_cursor.is_select_clicked: + select_button.fill_color = BUTTON_FILL_PURPLE + print("Select pressed: " + str(debounced_cursor.select_held)) + + if debounced_cursor.select_released: + select_button.fill_color = BUTTON_FILL_BLACK + print("Select pressed: " + str(debounced_cursor.select_held)) + + time.sleep(0.01) From fcbea4fdc8faba1f7d09578a3cc8749d037311f0 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 28 Mar 2022 15:52:04 -0400 Subject: [PATCH 38/77] 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 43d1385..29230db 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 af1b0b73abdba98c65a09fd1672dfbaf1761eba3 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Thu, 21 Apr 2022 15:00:27 -0400 Subject: [PATCH 39/77] 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 76491b903322b60396910451e95d742cac3363b0 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Apr 2022 15:58:31 -0400 Subject: [PATCH 40/77] Patch: Replaced discord badge image --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 64c4f4d..4c81c7c 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Introduction :target: https://docs.circuitpython.org/projects/cursorcontrol/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 168c3e92f61be75691c60d417f03f0fdf9ae729e Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 24 Apr 2022 14:02:48 -0500 Subject: [PATCH 41/77] change discord badge --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 4c81c7c..f236fc6 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Introduction :target: https://docs.circuitpython.org/projects/cursorcontrol/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 959da1ca5754412ec7b0185569110464aed82d82 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 15 May 2022 12:48:36 -0400 Subject: [PATCH 42/77] 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 29230db..0a91a11 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,duplicate-code 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 1016aea633f0378cf5ef4e6889d5a44aec5392fe Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:55 -0400 Subject: [PATCH 43/77] 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 4fa13019499c4a7b2db2d82cfde21e8e176d411e Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:23 -0400 Subject: [PATCH 44/77] 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 f62631cb9dd2a7ae9ea3a62f541d884f0ddd04f0 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 30 May 2022 14:25:04 -0400 Subject: [PATCH 45/77] 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 9676807..06710ea 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 4d0c463b3b5be8a10ee73c374597d58fed87d7b3 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 7 Jun 2022 15:34:13 -0400 Subject: [PATCH 46/77] 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 8b03c2f..45d268e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -29,7 +29,8 @@ Table of Contents .. toctree:: :caption: Other Links - Download + Download from GitHub + Download Library Bundle CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat From 7470e712312555a21a84c2cedf6380867f808177 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 21 Jun 2022 17:00:37 -0400 Subject: [PATCH 47/77] Removed duplicate-code from library pylint disable Signed-off-by: evaherrada --- .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 0a91a11..3343606 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: name: pylint (library code) types: [python] args: - - --disable=consider-using-f-string,duplicate-code + - --disable=consider-using-f-string exclude: "^(docs/|examples/|tests/|setup.py$)" - id: pylint name: pylint (example code) From 36b4c318dffbb2e04d37ced26c1fca5fab798fbe Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Jul 2022 13:58:39 -0400 Subject: [PATCH 48/77] Changed .env to .venv in README.rst --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index f236fc6..ef975e2 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-cursorcontrol Usage Example From 0a27264b6babc90b345176a337c362d441b36039 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 2 Aug 2022 17:00:28 -0400 Subject: [PATCH 49/77] Added Black formatting badge --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index ef975e2..0502518 100644 --- a/README.rst +++ b/README.rst @@ -13,6 +13,10 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_CursorControl/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 + Mouse cursor for interaction with CircuitPython UI elements such as `buttons `_. From f6af9969fe627ad57c96d69c1ad1c281a5ec9ab9 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 8 Aug 2022 22:05:54 -0400 Subject: [PATCH 50/77] Switched to pyproject.toml --- .github/workflows/build.yml | 18 +++++++----- .github/workflows/release.yml | 17 ++++++----- optional_requirements.txt | 3 ++ pyproject.toml | 46 +++++++++++++++++++++++++++++ requirements.txt | 2 +- setup.py | 55 ----------------------------------- 6 files changed, 70 insertions(+), 71 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..032e09f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,46 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +[build-system] +requires = [ + "setuptools", + "wheel", +] + +[project] +name = "adafruit-circuitpython-cursorcontrol" +description = "Mouse cursor for interaction with CircuitPython UI elements." +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_CursorControl"} +keywords = [ + "adafruit", + "blinka", + "circuitpython", + "micropython", + "cursorcontrol", + "mouse,", + "cursor,", + "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_cursorcontrol"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} diff --git a/requirements.txt b/requirements.txt index 40ae99f..25f7d7f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries # # SPDX-License-Identifier: Unlicense diff --git a/setup.py b/setup.py deleted file mode 100644 index ae75042..0000000 --- a/setup.py +++ /dev/null @@ -1,55 +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-cursorcontrol", - use_scm_version=True, - setup_requires=["setuptools_scm"], - description="Mouse cursor for interaction with CircuitPython UI elements.", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/adafruit/Adafruit_CircuitPython_CursorControl", - # Author details - author="Adafruit Industries", - author_email="circuitpython@adafruit.com", - install_requires=["Adafruit-Blinka", "adafruit-circuitpython-debouncer"], - # 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 cursorcontrol mouse, cursor, 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_cursorcontrol"], -) From d2a7a698c0c5827a8cc454f17a159f3c4dc21697 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 9 Aug 2022 12:03:54 -0400 Subject: [PATCH 51/77] 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 032e09f..8485ba6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ requires = [ "setuptools", "wheel", + "setuptools-scm", ] [project] From cd39fde30668873139c04ee1890ed6a3a3808d34 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 18:09:15 -0400 Subject: [PATCH 52/77] Update version string --- adafruit_cursorcontrol/__init__.py | 2 +- adafruit_cursorcontrol/cursorcontrol.py | 2 +- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 2 +- pyproject.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_cursorcontrol/__init__.py b/adafruit_cursorcontrol/__init__.py index b49f500..ba53aa2 100644 --- a/adafruit_cursorcontrol/__init__.py +++ b/adafruit_cursorcontrol/__init__.py @@ -9,5 +9,5 @@ * Author(s): Brent Rubell """ -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index 7eec0cf..7153992 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -28,7 +28,7 @@ except ImportError: pass -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 49cf53a..6921c2b 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -21,7 +21,7 @@ except ImportError: pass -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" diff --git a/pyproject.toml b/pyproject.toml index 8485ba6..9ace362 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires = [ [project] name = "adafruit-circuitpython-cursorcontrol" description = "Mouse cursor for interaction with CircuitPython UI elements." -version = "0.0.0-auto.0" +version = "0.0.0+auto.0" readme = "README.rst" authors = [ {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} From 4cc3f243bbf5120fad5b902a01020d80e7914ec7 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 21:09:15 -0400 Subject: [PATCH 53/77] 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 21186dec1e9137d84c31e8547ee0853dc9bd4cc1 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 22 Aug 2022 21:36:32 -0400 Subject: [PATCH 54/77] 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 06710ea..30b775d 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 CursorControl Library" -copyright = "2019 Brent Rubell" +current_year = str(datetime.datetime.now().year) +copyright = current_year + " Brent Rubell" author = "Brent Rubell" # The version info for the project you're documenting, acts as replacement for From afb2cdff718e6f1d6fb4fbb0dd1593619e7e834b Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 23 Aug 2022 17:26:22 -0400 Subject: [PATCH 55/77] 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 30b775d..4ecf20a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -44,8 +44,14 @@ # General information about the project. project = "Adafruit CursorControl Library" +creation_year = "2019" current_year = str(datetime.datetime.now().year) -copyright = current_year + " Brent Rubell" +year_duration = ( + current_year + if current_year == creation_year + else creation_year + " - " + current_year +) +copyright = year_duration + " Brent Rubell" author = "Brent Rubell" # The version info for the project you're documenting, acts as replacement for From dab05ee747474aa43658d9315effc153121752f0 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 56/77] 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 1ebc60f1c5e1b1fda7939bcba80deacdf034eae6 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 57/77] 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 6c7fd6d633ddcdd0ed3ef0185f3d3c76ff993c34 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 58/77] 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 4ecfb97c0c080d73c17c167f2fa8a0f9c329d9ac 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 59/77] 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 87b7386226fc132710911bef167f012e0c5ebf86 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 18:17:06 -0400 Subject: [PATCH 60/77] 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 e84ab3be55eebcdbd7d4459be7293af9e37be4a1 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 61/77] 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 d2f40f09a3e59fac5aac26a3b3d360bcc7823272 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 62/77] 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 463fe17a4e5f867a2125ccbc70310e1554889d28 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Tue, 9 May 2023 20:26:25 -0400 Subject: [PATCH 63/77] 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 7e17e75ebbb56076b6f8c4b436217d54e23b5c88 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Sun, 14 May 2023 13:00:32 -0400 Subject: [PATCH 64/77] 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 4ecf20a..9b99167 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 526dd50919453b10c9ecb82f074e7970f7aa6a68 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Wed, 31 May 2023 18:25:37 -0400 Subject: [PATCH 65/77] Update packaging specification in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9ace362..a7bb191 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ classifiers = [ dynamic = ["dependencies", "optional-dependencies"] [tool.setuptools] -py-modules = ["adafruit_cursorcontrol"] +packages = ["adafruit_cursorcontrol"] [tool.setuptools.dynamic] dependencies = {file = ["requirements.txt"]} From 97983d7e85985f56d511758479dd5d9c7c73493c Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 18 Sep 2023 16:22:41 -0500 Subject: [PATCH 66/77] "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 9b99167..d9fa191 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 b6706d74d9042d5d7409184a8c0978e3684551b1 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Wed, 1 Nov 2023 23:39:30 -0400 Subject: [PATCH 67/77] Replace depreciated .show fixes #37 --- examples/cursorcontrol_buttons_debounced.py | 2 +- examples/cursorcontrol_buttons_text.py | 2 +- examples/cursorcontrol_custom_cursor.py | 2 +- examples/cursorcontrol_simpletest.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/cursorcontrol_buttons_debounced.py b/examples/cursorcontrol_buttons_debounced.py index f1a9459..972eeba 100644 --- a/examples/cursorcontrol_buttons_debounced.py +++ b/examples/cursorcontrol_buttons_debounced.py @@ -118,7 +118,7 @@ splash.append(select_button) splash.append(a_button) splash.append(b_button) -display.show(splash) +display.root_group = splash while True: debounced_cursor.update() diff --git a/examples/cursorcontrol_buttons_text.py b/examples/cursorcontrol_buttons_text.py index 57520c0..7db003b 100644 --- a/examples/cursorcontrol_buttons_text.py +++ b/examples/cursorcontrol_buttons_text.py @@ -115,7 +115,7 @@ cursor = CursorManager(mouse_cursor) # show displayio group -display.show(splash) +display.root_group = splash prev_btn = None while True: diff --git a/examples/cursorcontrol_custom_cursor.py b/examples/cursorcontrol_custom_cursor.py index 83091e2..a66d15d 100644 --- a/examples/cursorcontrol_custom_cursor.py +++ b/examples/cursorcontrol_custom_cursor.py @@ -28,7 +28,7 @@ cursor = CursorManager(mouse_cursor) # show displayio group -display.show(splash) +display.root_group = splash while True: cursor.update() diff --git a/examples/cursorcontrol_simpletest.py b/examples/cursorcontrol_simpletest.py index aa50208..b599eec 100644 --- a/examples/cursorcontrol_simpletest.py +++ b/examples/cursorcontrol_simpletest.py @@ -20,7 +20,7 @@ cursor = CursorManager(mouse_cursor) # show displayio group -display.show(splash) +display.root_group = splash while True: cursor.update() From 9f6aac985dd8e984a77d15405456694ec012ab39 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Oct 2023 14:30:31 -0500 Subject: [PATCH 68/77] 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 ec944e49fc61c071063a172a921558c8e6e40e02 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 69/77] 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 d9fa191..a95749b 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 93d355e63285685eca8ba53c1335f19d3ba96477 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 13 Nov 2024 12:21:23 -0600 Subject: [PATCH 70/77] accept an initialized ShiftRegisterKeys --- .../cursorcontrol_cursormanager.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) mode change 100755 => 100644 adafruit_cursorcontrol/cursorcontrol_cursormanager.py diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py old mode 100755 new mode 100644 index 6921c2b..900daec --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -24,7 +24,6 @@ __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" - # PyBadge PYBADGE_BUTTON_LEFT = const(7) PYBADGE_BUTTON_UP = const(6) @@ -41,11 +40,15 @@ class CursorManager: """Simple interaction user interface interaction for Adafruit_CursorControl. :param Cursor cursor: The cursor object we are using. + :param ShiftRegisterKeys shift_register_keys: Optional initialized ShiftRegisterKeys object + to use instead of having CursorManager initialize and control it. """ # pylint: disable=too-many-instance-attributes - def __init__(self, cursor: Cursor) -> None: + def __init__( + self, cursor: Cursor, shift_register_keys: ShiftRegisterKeys = None + ) -> None: self._cursor = cursor self._is_clicked = False self._is_alt_clicked = False @@ -53,6 +56,7 @@ def __init__(self, cursor: Cursor) -> None: self._is_start_clicked = False self._pad_states = 0 self._event = Event() + self._pad = shift_register_keys self._init_hardware() def __enter__(self) -> "CursorManager": @@ -112,13 +116,14 @@ def _init_hardware(self) -> None: raise AttributeError( "Board must have a D-Pad or Joystick for use with CursorManager!" ) - self._pad = ShiftRegisterKeys( - clock=board.BUTTON_CLOCK, - data=board.BUTTON_OUT, - latch=board.BUTTON_LATCH, - key_count=8, - value_when_pressed=True, - ) + if self._pad is None: + self._pad = ShiftRegisterKeys( + clock=board.BUTTON_CLOCK, + data=board.BUTTON_OUT, + latch=board.BUTTON_LATCH, + key_count=8, + value_when_pressed=True, + ) @property def is_clicked(self) -> bool: From 3b7dea29d6e5305dbfd4b77dc08e2bcf9ed88b8a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 13 Nov 2024 14:04:17 -0600 Subject: [PATCH 71/77] Optional annotation --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 900daec..81d97df 100644 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -47,7 +47,7 @@ class CursorManager: # pylint: disable=too-many-instance-attributes def __init__( - self, cursor: Cursor, shift_register_keys: ShiftRegisterKeys = None + self, cursor: Cursor, shift_register_keys: Optional[ShiftRegisterKeys] = None ) -> None: self._cursor = cursor self._is_clicked = False From 32d5bc35cea00b428552dc4504d590f6627ccd6a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 72/77] 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 640022139a6dac1845b2d74795f4415467c5b49f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 16 May 2025 14:04:54 +0000 Subject: [PATCH 73/77] change to ruff --- .gitattributes | 11 + .pre-commit-config.yaml | 43 +- .pylintrc | 399 ------------------ README.rst | 6 +- adafruit_cursorcontrol/__init__.py | 1 + adafruit_cursorcontrol/cursorcontrol.py | 6 +- .../cursorcontrol_cursormanager.py | 24 +- docs/api.rst | 3 + docs/conf.py | 8 +- examples/cursorcontrol_buttons_debounced.py | 3 +- examples/cursorcontrol_buttons_text.py | 8 +- examples/cursorcontrol_custom_cursor.py | 2 + examples/cursorcontrol_simpletest.py | 2 + ruff.toml | 108 +++++ 14 files changed, 161 insertions(+), 463 deletions(-) create mode 100644 .gitattributes delete mode 100644 .pylintrc 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 70ade69..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +1,21 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # 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: v2.17.4 + - 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/.pylintrc b/.pylintrc deleted file mode 100644 index f945e92..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=5 - -# 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/README.rst b/README.rst index 0502518..c931674 100644 --- a/README.rst +++ b/README.rst @@ -13,9 +13,9 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_CursorControl/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 Mouse cursor for interaction with CircuitPython UI elements such as `buttons `_. diff --git a/adafruit_cursorcontrol/__init__.py b/adafruit_cursorcontrol/__init__.py index ba53aa2..13e6291 100644 --- a/adafruit_cursorcontrol/__init__.py +++ b/adafruit_cursorcontrol/__init__.py @@ -9,5 +9,6 @@ * Author(s): Brent Rubell """ + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git" diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index 7153992..2b476c4 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -20,11 +20,12 @@ https://github.com/adafruit/circuitpython/releases """ + import displayio try: - from typing import Optional, Type from types import TracebackType + from typing import Optional, Type except ImportError: pass @@ -57,7 +58,6 @@ class Cursor: mouse_cursor = Cursor(display, display_group=splash) """ - # pylint: disable=too-many-arguments,line-too-long def __init__( self, display: Optional[displayio.Display] = None, @@ -80,8 +80,6 @@ def __init__( self._cursor_bitmap = bmp self.generate_cursor(self._cursor_bitmap) - # pylint: enable=too-many-arguments,line-too-long - def __enter__(self) -> "Cursor": return self diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 81d97df..79acfb2 100644 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -8,15 +8,17 @@ Simple interaction user interface interaction for Adafruit_CursorControl. * Author(s): Brent Rubell """ -import board -from micropython import const + import analogio -from keypad import ShiftRegisterKeys, Event +import board from adafruit_debouncer import Debouncer +from keypad import Event, ShiftRegisterKeys +from micropython import const try: - from typing import Optional, Type from types import TracebackType + from typing import Optional, Type + from adafruit_cursorcontrol.cursorcontrol import Cursor except ImportError: pass @@ -44,8 +46,6 @@ class CursorManager: to use instead of having CursorManager initialize and control it. """ - # pylint: disable=too-many-instance-attributes - def __init__( self, cursor: Cursor, shift_register_keys: Optional[ShiftRegisterKeys] = None ) -> None: @@ -113,9 +113,7 @@ def _init_hardware(self) -> None: self._center_x = self._joystick_x.value self._center_y = self._joystick_y.value else: - raise AttributeError( - "Board must have a D-Pad or Joystick for use with CursorManager!" - ) + raise AttributeError("Board must have a D-Pad or Joystick for use with CursorManager!") if self._pad is None: self._pad = ShiftRegisterKeys( clock=board.BUTTON_CLOCK, @@ -183,7 +181,6 @@ def _read_joystick_x(self, samples: int = 3) -> float: :param int samples: How many samples to read and average. """ reading = 0 - # pylint: disable=unused-variable if hasattr(board, "JOYSTICK_X"): for _ in range(0, samples): reading += self._joystick_x.value @@ -195,7 +192,6 @@ def _read_joystick_y(self, samples: int = 3) -> float: :param int samples: How many samples to read and average. """ reading = 0 - # pylint: disable=unused-variable if hasattr(board, "JOYSTICK_Y"): for _ in range(0, samples): reading += self._joystick_y.value @@ -235,9 +231,7 @@ def _check_cursor_movement(self) -> None: elif joy_y < self._center_y - 1000: self._cursor.y -= self._cursor.speed else: - raise AttributeError( - "Board must have a D-Pad or Joystick for use with CursorManager!" - ) + raise AttributeError("Board must have a D-Pad or Joystick for use with CursorManager!") class DebouncedCursorManager(CursorManager): @@ -254,7 +248,7 @@ def __init__(self, cursor: Cursor, debounce_interval: float = 0.01) -> None: self._debouncers = {} for btn in self._pad_btns: self._debouncers[btn] = Debouncer( - lambda btn=btn: bool((self._pad_states & (1 << self._pad_btns[btn]))), + lambda btn=btn: bool(self._pad_states & (1 << self._pad_btns[btn])), interval=debounce_interval, ) diff --git a/docs/api.rst b/docs/api.rst index 5981c96..36ad4d7 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,3 +1,6 @@ +API Reference +############# + .. automodule:: adafruit_cursorcontrol.cursorcontrol :members: diff --git a/docs/conf.py b/docs/conf.py index a95749b..1303dba 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 + " Brent Rubell" author = "Brent Rubell" diff --git a/examples/cursorcontrol_buttons_debounced.py b/examples/cursorcontrol_buttons_debounced.py index 972eeba..b718c3a 100644 --- a/examples/cursorcontrol_buttons_debounced.py +++ b/examples/cursorcontrol_buttons_debounced.py @@ -2,11 +2,12 @@ # SPDX-License-Identifier: MIT import time + import board import displayio import terminalio - from adafruit_button import Button + from adafruit_cursorcontrol.cursorcontrol import Cursor from adafruit_cursorcontrol.cursorcontrol_cursormanager import DebouncedCursorManager diff --git a/examples/cursorcontrol_buttons_text.py b/examples/cursorcontrol_buttons_text.py index 7db003b..53dc566 100644 --- a/examples/cursorcontrol_buttons_text.py +++ b/examples/cursorcontrol_buttons_text.py @@ -2,11 +2,13 @@ # SPDX-License-Identifier: MIT import time + import board import displayio +import terminalio from adafruit_button import Button from adafruit_display_text import label -import terminalio + from adafruit_cursorcontrol.cursorcontrol import Cursor from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager @@ -136,6 +138,6 @@ prev_btn = b elif prev_btn is not None: prev_btn.selected = False - text_speed.text = "Speed: {0}px".format(mouse_cursor.speed) - text_scale.text = "Scale: {0}px".format(mouse_cursor.scale) + text_speed.text = f"Speed: {mouse_cursor.speed}px" + text_scale.text = f"Scale: {mouse_cursor.scale}px" time.sleep(0.1) diff --git a/examples/cursorcontrol_custom_cursor.py b/examples/cursorcontrol_custom_cursor.py index a66d15d..6386e3d 100644 --- a/examples/cursorcontrol_custom_cursor.py +++ b/examples/cursorcontrol_custom_cursor.py @@ -2,8 +2,10 @@ # SPDX-License-Identifier: MIT import time + import board import displayio + from adafruit_cursorcontrol.cursorcontrol import Cursor from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager diff --git a/examples/cursorcontrol_simpletest.py b/examples/cursorcontrol_simpletest.py index b599eec..953f221 100644 --- a/examples/cursorcontrol_simpletest.py +++ b/examples/cursorcontrol_simpletest.py @@ -2,8 +2,10 @@ # SPDX-License-Identifier: MIT import time + import board import displayio + from adafruit_cursorcontrol.cursorcontrol import Cursor from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..73e9efc --- /dev/null +++ b/ruff.toml @@ -0,0 +1,108 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +preview = true +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 + "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] +line-ending = "lf" From 32a0877541d43739d834dd3a6450e7903ca1d6a1 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 30 May 2025 11:26:19 -0500 Subject: [PATCH 74/77] displayio api updates --- adafruit_cursorcontrol/cursorcontrol.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index 2b476c4..d4404b0 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -26,6 +26,8 @@ try: from types import TracebackType from typing import Optional, Type + + from circuitpython_typing.displayio import AnyDisplay except ImportError: pass @@ -36,7 +38,7 @@ class Cursor: """Mouse cursor interaction for CircuitPython. - :param ~displayio.Display display: CircuitPython display object. + :param ~AnyDisplay display: CircuitPython display object. :param ~displayio.Group display_group: CircuitPython group object to append the cursor to. :param ~displayio.Bitmap bmp: CircuitPython bitmap object to use as the cursor :param bool is_hidden: Cursor is hidden on init. @@ -60,7 +62,7 @@ class Cursor: def __init__( self, - display: Optional[displayio.Display] = None, + display: Optional[AnyDisplay] = None, display_group: Optional[displayio.Group] = None, bmp: Optional[displayio.Bitmap] = None, is_hidden: bool = False, From 862c98534c41c46507b99675bdbe73b0ca0a877f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 30 May 2025 11:27:50 -0500 Subject: [PATCH 75/77] add typing req --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 25f7d7f..8cb7c61 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ Adafruit-Blinka adafruit-circuitpython-debouncer +adafruit-circuitpython-typing From 71b7c2aaf23fd11b9d41469c75b35b6f06f09b85 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 30 May 2025 13:45:13 -0500 Subject: [PATCH 76/77] add blinka-displayio to reqs --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 8cb7c61..81629c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,6 @@ # SPDX-License-Identifier: Unlicense Adafruit-Blinka +Adafruit-Blinka-Displayio adafruit-circuitpython-debouncer adafruit-circuitpython-typing From a607b7f231480e8d7cf82a15b8c6c666cff2b4ef Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Jun 2025 10:00:20 -0500 Subject: [PATCH 77/77] 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" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy