fresh cookiecutter

This commit is contained in:
brentru 2019-06-20 17:43:24 -04:00
parent 3b50809c43
commit 08fce52fb4
13 changed files with 93 additions and 413 deletions

View file

@ -42,7 +42,7 @@ install:
- pip install --force-reinstall pylint==1.9.2
script:
- pylint adafruit_cursor.py
- pylint adafruit_cursorcontrol.py
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py)
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-cursor --library_location .
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-cursorcontrol --library_location .
- cd docs && sphinx-build -E -W -b html . _build/html && cd ..

View file

@ -1,20 +1,20 @@
Introduction
============
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-cursor/badge/?version=latest
:target: https://circuitpython.readthedocs.io/projects/cursor/en/latest/
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-cursorcontrol/badge/?version=latest
:target: https://circuitpython.readthedocs.io/projects/cursorcontrol/en/latest/
:alt: Documentation Status
.. image:: https://img.shields.io/discord/327254708534116352.svg
:target: https://discord.gg/nBQh6qu
:alt: Discord
.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_Cursor.svg?branch=master
:target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_Cursor
.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_CursorControl.svg?branch=master
:target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_CursorControl
:alt: Build Status
Mouse cursor for interaction with CircuitPython UI elements such as
`buttons <https://github.com/adafruit/Adafruit_CircuitPython_Display_Button>`_.
Mouse cursor for interaction with CircuitPython UI elements.
Dependencies
=============
@ -31,18 +31,21 @@ Installing from PyPI
.. note:: This library is not available on PyPI yet. Install documentation is included
as a standard element. Stay tuned for PyPI availability!
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
PyPI <https://pypi.org/project/adafruit-circuitpython-cursor/>`_. To install for current user:
PyPI <https://pypi.org/project/adafruit-circuitpython-cursorcontrol/>`_. To install for current user:
.. code-block:: shell
pip3 install adafruit-circuitpython-cursor
pip3 install adafruit-circuitpython-cursorcontrol
To install system-wide (this may be required in some cases):
.. code-block:: shell
sudo pip3 install adafruit-circuitpython-cursor
sudo pip3 install adafruit-circuitpython-cursorcontrol
To install in a virtual environment in your current project:
@ -51,18 +54,18 @@ To install in a virtual environment in your current project:
mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-cursor
pip3 install adafruit-circuitpython-cursorcontrol
Usage Example
=============
See examples in examples/ folder.
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
Contributing
============
Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_Cursor/blob/master/CODE_OF_CONDUCT.md>`_
<https://github.com/adafruit/Adafruit_CircuitPython_CursorControl/blob/master/CODE_OF_CONDUCT.md>`_
before contributing to help this project stay welcoming.
Building locally
@ -90,7 +93,7 @@ Then run the build:
.. code-block:: shell
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-cursor --library_location .
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-cursorcontrol --library_location .
Sphinx documentation
-----------------------

View file

@ -1,179 +0,0 @@
# The MIT License (MIT)
#
# Copyright (c) 2019 Brent Rubell for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`adafruit_cursor`
================================================================================
Mouse cursor for interaction with displayio Groups.
* Author(s): Brent Rubell
Implementation Notes
--------------------
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
"""
import displayio
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Cursor.git"
class Cursor:
"""Mouse cursor interaction for CircuitPython.
:param ~displayio.Display display: CircuitPython display object.
:param ~displayio.Group display_group: CircuitPython group object to append the cursor to.
: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
.. code-block:: python
import adafruit_cursor
# Create the display
display = board.DISPLAY
# Create the display context
splash = displayio.Group(max_size=22)
# initialize the mouse cursor object
mouse_cursor = adafruit_cursor.Cursor(display, display_group=splash)
"""
# pylint: disable=too-many-arguments
def __init__(self, display=None, display_group=None, is_hidden=False, cursor_speed=5, scale=1):
self._display = display
self._scale = scale
self._speed = cursor_speed
self._is_hidden = is_hidden
self._display_grp = display_group
self._disp_sz = display.height - 1, display.width - 1
self.generate_cursor()
@property
def scale(self):
"""Returns the cursor's scale amount as an integer."""
return self._scale
@scale.setter
def scale(self, scale_value):
"""Scales the cursor by scale_value in both directions.
:param int scale_value: Amount to scale the cursor by.
"""
if scale_value > 0:
self._scale = scale_value
self._cursor_grp.scale = scale_value
@property
def speed(self):
"""Returns the cursor's speed, in pixels."""
return self._speed
@speed.setter
def speed(self, speed):
"""Sets the speed of the cursor.
:param int speed: Cursor movement speed, in pixels.
"""
self._speed = speed
@property
def x(self):
"""Returns the cursor's x-coordinate."""
return self._cursor_grp.x
@x.setter
def x(self, x_val):
"""Sets the x-value of the cursor.
:param int x_val: cursor x-position, in pixels.
"""
if x_val < 0 and not self._is_hidden:
self._cursor_grp.x = self._cursor_grp.x
elif x_val > self._disp_sz[1] and not self._is_hidden:
self._cursor_grp.x = self._cursor_grp.x
elif not self._is_hidden:
self._cursor_grp.x = x_val
@property
def y(self):
"""Returns the cursor's y-coordinate."""
return self._cursor_grp.y
@y.setter
def y(self, y_val):
"""Sets the y-value of the cursor.
:param int y_val: cursor y-position, in pixels.
"""
if y_val < 0 and not self._is_hidden:
self._cursor_grp.y = self._cursor_grp.y
elif y_val > self._disp_sz[0] and not self._is_hidden:
self._cursor_grp.y = self._cursor_grp.y
elif not self._is_hidden:
self._cursor_grp.y = y_val
@property
def hide(self):
"""Returns True if the cursor is hidden or visible on the display."""
return self._is_hidden
@hide.setter
def hide(self, is_hidden):
if is_hidden:
self._is_hidden = True
self._display_grp.remove(self._cursor_grp)
else:
self._is_hidden = False
self._display_grp.append(self._cursor_grp)
def generate_cursor(self):
"""Generates a cursor icon"""
self._cursor_grp = displayio.Group(max_size=1, scale=self._scale)
self._cur_bmp = displayio.Bitmap(20, 20, 3)
self._cur_palette = displayio.Palette(3)
self._cur_palette.make_transparent(0)
self._cur_palette[1] = 0xFFFFFF
self._cur_palette[2] = 0x0000
# left edge, outline
for i in range(0, self._cur_bmp.height):
self._cur_bmp[0, i] = 2
# right diag outline, inside fill
for j in range(1, 15):
self._cur_bmp[j, j] = 2
for i in range(j+1, self._cur_bmp.height - j):
self._cur_bmp[j, i] = 1
# bottom diag., outline
for i in range(1, 5):
self._cur_bmp[i, self._cur_bmp.height-i] = 2
# bottom flat line, right side fill
for i in range(5, 15):
self._cur_bmp[i, 15] = 2
self._cur_bmp[i-1, 14] = 1
self._cur_bmp[i-2, 13] = 1
self._cur_bmp[i-3, 12] = 1
self._cur_bmp[i-4, 11] = 1
self._cur_sprite = displayio.TileGrid(self._cur_bmp,
pixel_shader=self._cur_palette)
self._cursor_grp.append(self._cur_sprite)
self._display_grp.append(self._cursor_grp)

53
adafruit_cursorcontrol.py Normal file
View file

@ -0,0 +1,53 @@
# The MIT License (MIT)
#
# Copyright (c) 2019 Brent Rubell for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`adafruit_cursorcontrol`
================================================================================
Mouse cursor for interaction with CircuitPython UI elements.
* Author(s): Brent Rubell
Implementation Notes
--------------------
**Hardware:**
.. todo:: Add links to any specific hardware product page(s), or category page(s). Use unordered list & hyperlink rST
inline format: "* `Link Text <url>`_"
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
.. todo:: Uncomment or remove the Bus Device and/or the Register library dependencies based on the library's use of either.
# * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
# * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
"""
# imports
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git"

View file

@ -4,5 +4,5 @@
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
.. use this format as the module name: "adafruit_foo.foo"
.. automodule:: adafruit_cursor
.. automodule:: adafruit_cursorcontrol
:members:

View file

@ -20,7 +20,7 @@ extensions = [
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
autodoc_mock_imports = ["displayio"]
# autodoc_mock_imports = ["digitalio", "busio"]
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
@ -34,7 +34,7 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'Adafruit Cursor Library'
project = u'Adafruit CursorControl Library'
copyright = u'2019 Brent Rubell'
author = u'Brent Rubell'
@ -109,7 +109,7 @@ html_static_path = ['_static']
html_favicon = '_static/favicon.ico'
# Output file base name for HTML help builder.
htmlhelp_basename = 'AdafruitCursorLibrarydoc'
htmlhelp_basename = 'AdafruitCursorcontrolLibrarydoc'
# -- Options for LaTeX output ---------------------------------------------
@ -135,7 +135,7 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'AdafruitCursorLibrary.tex', u'AdafruitCursor Library Documentation',
(master_doc, 'AdafruitCursorControlLibrary.tex', u'AdafruitCursorControl Library Documentation',
author, 'manual'),
]
@ -144,7 +144,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'AdafruitCursorlibrary', u'Adafruit Cursor Library Documentation',
(master_doc, 'AdafruitCursorControllibrary', u'Adafruit CursorControl Library Documentation',
[author], 1)
]
@ -154,7 +154,7 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitCursorLibrary', u'Adafruit Cursor Library Documentation',
author, 'AdafruitCursorLibrary', 'One line description of project.',
(master_doc, 'AdafruitCursorControlLibrary', u'Adafruit CursorControl Library Documentation',
author, 'AdafruitCursorControlLibrary', 'One line description of project.',
'Miscellaneous'),
]

View file

@ -3,6 +3,6 @@ Simple test
Ensure your device works with this simple test.
.. literalinclude:: ../examples/cursor_simpletest.py
:caption: examples/cursor_simpletest.py
.. literalinclude:: ../examples/cursorcontrol_simpletest.py
:caption: examples/cursorcontrol_simpletest.py
:linenos:

View file

@ -23,15 +23,19 @@ Table of Contents
.. toctree::
:caption: Tutorials
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
the toctree above for use later.
.. toctree::
:caption: Related Products
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
the toctree above for use later.
.. toctree::
:caption: Other Links
Download <https://github.com/adafruit/Adafruit_CircuitPython_Cursor/releases/latest>
Download <https://github.com/adafruit/Adafruit_CircuitPython_CursorControl/releases/latest>
CircuitPython Reference Documentation <https://circuitpython.readthedocs.io>
CircuitPython Support Forum <https://forums.adafruit.com/viewforum.php?f=60>
Discord Chat <https://adafru.it/discord>

View file

@ -1,143 +0,0 @@
import adafruit_cursor
import board
import digitalio
import displayio
from adafruit_bitmap_font import bitmap_font
from adafruit_button import Button
from adafruit_display_text import label
from gamepadshift import GamePadShift
from micropython import const
# PyBadge Button Masks
BUTTON_LEFT = const(128)
BUTTON_UP = const(64)
BUTTON_DOWN = const(32)
BUTTON_RIGHT = const(16)
BUTTON_A = const(2)
BUTTON_B = const(1)
# Initialize PyBadge Gamepad
pad = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK),
digitalio.DigitalInOut(board.BUTTON_OUT),
digitalio.DigitalInOut(board.BUTTON_LATCH))
# Load the font
THE_FONT = "/fonts/Arial-12.bdf"
font = bitmap_font.load_font(THE_FONT)
# Create the display
display = board.DISPLAY
# Create the display context
splash = displayio.Group(max_size=22)
##########################################################################
# Make a background color fill
color_bitmap = displayio.Bitmap(320, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x404040
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette,
x=0, y=0)
splash.append(bg_sprite)
##########################################################################
# Set up button size info
BUTTON_WIDTH = 80
BUTTON_HEIGHT = 40
BUTTON_MARGIN = 20
# Create the buttons
buttons = []
button_speed_inc = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN+BUTTON_HEIGHT,
width=BUTTON_WIDTH, height=BUTTON_HEIGHT,
label="+ Speed", label_font=font)
buttons.append(button_speed_inc)
button_speed_dec = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN*4+BUTTON_HEIGHT,
width=BUTTON_WIDTH, height=BUTTON_HEIGHT,
label="- Speed", label_font=font)
buttons.append(button_speed_dec)
button_scale_pos = Button(x=BUTTON_MARGIN*3+2*BUTTON_WIDTH, y=BUTTON_MARGIN+BUTTON_HEIGHT,
width=BUTTON_WIDTH, height=BUTTON_HEIGHT,
label="+ Scale", label_font=font, style=Button.SHADOWRECT)
buttons.append(button_scale_pos)
button_scale_neg = Button(x=BUTTON_MARGIN*3+2*BUTTON_WIDTH, y=BUTTON_MARGIN*4+BUTTON_HEIGHT,
width=BUTTON_WIDTH, height=BUTTON_HEIGHT,
label="- Scale", label_font=font, style=Button.SHADOWRECT)
buttons.append(button_scale_neg)
# Show the button
for b in buttons:
splash.append(b.group)
# Create a text label
text_label = label.Label(font, text="CircuitPython Cursor!", color=0x00FF00,
x = 100, y = 20)
splash.append(text_label)
text_speed = label.Label(font, max_glyphs = 15, color=0x00FF00,
x = 120, y = 40)
splash.append(text_speed)
text_scale = label.Label(font, max_glyphs = 15, color=0x00FF00,
x = 120, y = 60)
splash.append(text_scale)
# initialize the mouse cursor object
mouse_cursor = adafruit_cursor.Cursor(display, display_group=splash)
# show displayio group
display.show(splash)
def check_dpad(d_pad_buttons):
"""Checks the directional pad for button presses."""
if d_pad_buttons & BUTTON_RIGHT:
mouse_cursor.x += mouse_cursor.speed
elif d_pad_buttons & BUTTON_LEFT:
mouse_cursor.x -= mouse_cursor.speed
if d_pad_buttons & BUTTON_DOWN:
mouse_cursor.y += mouse_cursor.speed
elif d_pad_buttons & BUTTON_UP:
mouse_cursor.y -= mouse_cursor.speed
is_pressed = False
while True:
display.wait_for_frame()
text_speed.text = 'Speed: {0}px'.format(mouse_cursor.speed)
text_scale.text = 'Scale: {0}px'.format(mouse_cursor.scale)
pressed = pad.get_pressed()
check_dpad(pressed)
if is_pressed:
if not pressed & (BUTTON_A | BUTTON_B):
# buttons de-pressed
is_pressed = False
for i, b in enumerate(buttons):
b.selected=False
# otherwise, continue holding
continue
if pressed & BUTTON_B:
is_pressed = True
if mouse_cursor.hide:
mouse_cursor.hide = False
else:
mouse_cursor.hide = True
if pressed & BUTTON_A:
is_pressed = True
for i, b in enumerate(buttons):
if b.contains((mouse_cursor.x, mouse_cursor.y)):
print("Button %d pressed"%i)
if i == 0: # Increase the cursor speed
mouse_cursor.speed += 1
elif i == 1: # Decrease the cursor speed
mouse_cursor.speed -= 1
if i == 2: # Increase the cursor scale
mouse_cursor.scale += 1
elif i == 3: # Decrease the cursor scale
mouse_cursor.scale -= 1
b.selected=True

View file

@ -1,58 +0,0 @@
import adafruit_cursor
import board
import digitalio
import displayio
from gamepadshift import GamePadShift
from micropython import const
# PyBadge Button Masks
BUTTON_LEFT = const(128)
BUTTON_UP = const(64)
BUTTON_DOWN = const(32)
BUTTON_RIGHT = const(16)
BUTTON_A = const(2)
BUTTON_B = const(1)
# Initialize PyBadge Gamepad
pad = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK),
digitalio.DigitalInOut(board.BUTTON_OUT),
digitalio.DigitalInOut(board.BUTTON_LATCH))
# Create the display
display = board.DISPLAY
# Create the display context
splash = displayio.Group(max_size=22)
# initialize the mouse cursor object
mouse_cursor = adafruit_cursor.Cursor(display, display_group=splash)
# show displayio group
display.show(splash)
def check_dpad(d_pad_buttons):
"""Checks the directional pad for button presses."""
if d_pad_buttons & BUTTON_RIGHT:
mouse_cursor.x += mouse_cursor.speed
elif d_pad_buttons & BUTTON_LEFT:
mouse_cursor.x -= mouse_cursor.speed
if d_pad_buttons & BUTTON_DOWN:
mouse_cursor.y += mouse_cursor.speed
elif d_pad_buttons & BUTTON_UP:
mouse_cursor.y -= mouse_cursor.speed
is_pressed = False
while True:
display.wait_for_frame()
pressed = pad.get_pressed()
check_dpad(pressed)
if is_pressed:
if not pressed & (BUTTON_A | BUTTON_B):
is_pressed = False
continue
if pressed & BUTTON_A:
is_pressed = True
if mouse_cursor.hide:
mouse_cursor.hide = False
else:
mouse_cursor.hide = True

View file

View file

@ -1,2 +1,2 @@
Adafruit-Blinka
adafruit-imageload
no

View file

@ -17,17 +17,17 @@ with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()
setup(
name='adafruit-circuitpython-cursor',
name='adafruit-circuitpython-cursorcontrol',
use_scm_version=True,
setup_requires=['setuptools_scm'],
description='Simulated mouse cursor for display interaction',
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_Cursor',
url='https://github.com/adafruit/Adafruit_CircuitPython_CursorControl',
# Author details
author='Adafruit Industries',
@ -35,7 +35,7 @@ setup(
install_requires=[
'Adafruit-Blinka',
'adafruit-imageload'
'no'
],
# Choose your license
@ -54,11 +54,11 @@ setup(
],
# What does your project relate to?
keywords='adafruit blinka circuitpython micropython cursor cursor, mouse, input',
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_cursor'],
py_modules=['adafruit_cursorcontrol'],
)