Skip to content

Update for release. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cache:
# or remove the env block entirely and remove the condition in the
# deploy block.
env:
- DEPLOY_PYPI="false"
- DEPLOY_PYPI="true"

deploy:
- provider: releases
Expand All @@ -31,7 +31,7 @@ deploy:
- provider: pypi
user: adafruit-travis
password:
secure: #-- PASTE ENCRYPTED PASSWORD HERE --#
secure: mK1brDPZMNqHXM83DNW+FxcwiWIeJXg4xMVkSCPLxCgB6sSd9S7uVjsQvxSy6TRKnM6X0n4BZDwYlgGMW80EODaM0LNgg7lB/VGa/ZAAPezXzAnZ12sVwpFkhr8DxlOZzGtQ7vODPiassuGPUzjyUX+pqoX8CIqeW9gHXduJY7sPdakVOQ565oV0Bm6VrcuNpHVtIVhlza+QZ8t/K4crVf0pl/p40cidyA01BeL2OXhjVQEbObu61YRv3DTmBKZSR3XtXFbeDwhl75k83Y2jyh9qdZyClA6/RtWrc5LicXEqCjrZMMKCdyXxEQcMIsQuDK0I+uPUfu6qgnqmeH5B2zYA0QXXjLf4QEJMmscRoespLTHJ4xatg+15/DpJhy5SguPdm/YeU+Ij3IgAP/Mj6IEKSDI9I1evVn9fdfFIMvz9EPScZanCuMpQZxMYDSAShofWwYqbhkKVaEAX7XmEyBxfVtOlalMRo+hW5MnB9wnNI8Ylooznrin6JkiTx95TZ6+sxdwXlvZqPwZ/rNhbNn9xWx/Qj/7HnjIvgNPYUXMOMnWeOHQgNxXGvVbgl+XT/F394cTgTi1f74dp32+D0GE6JO6GUQOKDFRzJF/N8NQzvSGn4CUnWE0c7QALcsw5TlKZ+HWrNyiQ7nlBrq59hj4LxBthFHtsE62xdqII9d4=
on:
tags: true
condition: $DEPLOY_PYPI = "true"
Expand Down
38 changes: 33 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ This is easily achieved by downloading

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-display_shapes/>`_. To install for current user:

Expand All @@ -57,7 +53,39 @@ To install in a virtual environment in your current project:
Usage Example
=============

.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
..code-block:: python

import board
import displayio
from adafruit_display_shapes.rect import Rect
from adafruit_display_shapes.circle import Circle
from adafruit_display_shapes.roundrect import RoundRect

splash = displayio.Group(max_size=10)
board.DISPLAY.show(splash)

color_bitmap = displayio.Bitmap(320, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, position=(0, 0))
print(bg_sprite.position)
splash.append(bg_sprite)

rect = Rect(80, 20, 41, 41, fill=0x0)
splash.append(rect)

circle = Circle(100, 100, 20, fill=0x00FF00, outline=0xFF00FF)
splash.append(circle)

rect2 = Rect(50, 100, 61, 81, outline=0x0, stroke=3)
splash.append(rect2)

roundrect = RoundRect(10, 10, 61, 81, 10, fill=0x0, outline=0xFF00FF, stroke=6)
splash.append(roundrect)

while True:
pass


Contributing
============
Expand Down
14 changes: 11 additions & 3 deletions adafruit_display_shapes/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@


class Circle(RoundRect):
"""A circle, centered around (x0, y0) with radius r. Fill can be a hex
value for the color or None for transparent. Outline can be a hex value
for the color or None for no outline."""
"""A circle.

:param x0: The x-position of the center.
:param y0: The y-position of the center..
:param r: The radius of the circle.
:param fill: The color to fill the rounded-corner rectangle. Can be a hex value for a color or
``None`` for transparent.
:param outline: The outline of the rounded-corner rectangle. Can be a hex value for a color or
``None`` for no outline.

"""
def __init__(self, x0, y0, r, *, fill=None, outline=None):
super().__init__(x0-r, y0-r, 2*r+1, 2*r+1, r, fill=fill, outline=outline)
27 changes: 21 additions & 6 deletions adafruit_display_shapes/rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@


class Rect(displayio.TileGrid):
"""A rectangle, top left corner is (x, y) and size of width, height.
Stroke is used for the outline, and will not change outer bound size set
by width and height. Fill can be a hex value for the color or None for
transparent. Outline can be a hex value for the color or None for no
outline."""
def __init__(self, x, y, width, height, *, stroke=1, fill=None, outline=None):
"""A rectangle.

:param x: The x-position of the top left corner.
:param y: The y-position of the top left corner.
:param width: The width of the rectangle.
:param height: The height of the rectangle.
:param fill: The color to fill the rectangle. Can be a hex value for a color or
``None`` for transparent.
:param outline: The outline of the rectangle. Can be a hex value for a color or
``None`` for no outline.
:param stroke: Used for the outline. Will not change the outer bound size set by ``width`` and
``height``.

"""
def __init__(self, x, y, width, height, *, fill=None, outline=None, stroke=1):
self._bitmap = displayio.Bitmap(width, height, 2)
self._palette = displayio.Palette(2)

Expand All @@ -73,6 +82,8 @@ def __init__(self, x, y, width, height, *, stroke=1, fill=None, outline=None):

@property
def fill(self):
"""The fill of the rectangle. Can be a hex value for a color or ``None`` for
transparent."""
return self._palette[0]

@fill.setter
Expand All @@ -84,6 +95,8 @@ def fill(self, color):

@property
def outline(self):
"""The outline of the rectangle. Can be a hex value for a color or ``None``
for no outline."""
return self._palette[1]

@outline.setter
Expand All @@ -100,6 +113,7 @@ def x(self):

@x.setter
def x(self, x):
# pylint: disable=attribute-defined-outside-init
self.position = (x, self.position[1])

@property
Expand All @@ -109,4 +123,5 @@ def y(self):

@y.setter
def y(self, y):
# pylint: disable=attribute-defined-outside-init
self.position = (self.position[0], y)
47 changes: 31 additions & 16 deletions adafruit_display_shapes/roundrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,30 @@


class RoundRect(displayio.TileGrid):
"""A round-corner rectangle, top left corner is (x, y) and size of width, height.
r is the radius of the rounded corner. Stroke is used for the outline, and will
not change outer bound size set by width and height. Fill can be a hex value
for the color or None for transparent. Outline can be a hex value for the color
or None for no outline."""
def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1): # pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments
"""A round-corner rectangle.

:param x: The x-position of the top left corner.
:param y: The y-position of the top left corner.
:param width: The width of the rounded-corner rectangle.
:param height: The height of the rounded-corner rectangle.
:param r: The radius of the rounded corner.
:param fill: The color to fill the rounded-corner rectangle. Can be a hex value for a color or
``None`` for transparent.
:param outline: The outline of the rounded-corner rectangle. Can be a hex value for a color or
``None`` for no outline.
:param stroke: Used for the outline. Will not change the outer bound size set by ``width`` and
``height``.

"""
def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1):
self._palette = displayio.Palette(3)
self._palette.make_transparent(0)
self._bitmap = displayio.Bitmap(width, height, 3)

if fill is not None:
for i in range(0, width): # draw the center chunk
for j in range(r, height-r): # draw the center chunk
for j in range(r, height - r): # draw the center chunk
self._bitmap[i, j] = 2
self._helper(r, r, r, color=2, fill=True,
x_offset=width-2*r-1, y_offset=height-2*r-1)
Expand All @@ -68,24 +79,22 @@ def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1)
if outline is not None:
self._palette[1] = outline
# draw flat sides
for w in range(r, width-r):
for w in range(r, width - r):
for line in range(stroke):
self._bitmap[w, line] = 1
self._bitmap[w, height-line-1] = 1
for _h in range(r, height-r):
for _h in range(r, height - r):
for line in range(stroke):
self._bitmap[line, _h] = 1
self._bitmap[width-line-1, _h] = 1
# draw round corners
self._helper(r, r, r, color=1, stroke=stroke,
x_offset=width-2*r-1, y_offset=height-2*r-1)

super().__init__(self._bitmap, pixel_shader=self._palette, position=(x, y))


# pylint: disable=invalid-name, too-many-locals, too-many-branches
def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0,
stroke=1, cornerflags=0xF, fill=False):
stroke=1, corner_flags=0xF, fill=False):
f = 1 - r
ddF_x = 1
ddF_y = -2 * r
Expand All @@ -100,7 +109,7 @@ def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0,
x += 1
ddF_x += 2
f += ddF_x
if cornerflags & 0x8:
if corner_flags & 0x8:
if fill:
for w in range(x0-y, x0+y+x_offset):
self._bitmap[w, y0+x+y_offset] = color
Expand All @@ -110,7 +119,7 @@ def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0,
for line in range(stroke):
self._bitmap[x0-y+line, y0+x+y_offset] = color
self._bitmap[x0-x, y0+y+y_offset-line] = color
if cornerflags & 0x1:
if corner_flags & 0x1:
if fill:
for w in range(x0-y, x0+y+x_offset):
self._bitmap[w, y0-x] = color
Expand All @@ -120,18 +129,20 @@ def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0,
for line in range(stroke):
self._bitmap[x0-y+line, y0-x] = color
self._bitmap[x0-x, y0-y+line] = color
if cornerflags & 0x4:
if corner_flags & 0x4:
for line in range(stroke):
self._bitmap[x0+x+x_offset, y0+y+y_offset-line] = color
self._bitmap[x0+y+x_offset-line, y0+x+y_offset] = color
if cornerflags & 0x2:
if corner_flags & 0x2:
for line in range(stroke):
self._bitmap[x0+x+x_offset, y0-y+line] = color
self._bitmap[x0+y+x_offset-line, y0-x] = color
# pylint: enable=invalid-name, too-many-locals, too-many-branches

@property
def fill(self):
"""The fill of the rounded-corner rectangle. Can be a hex value for a color or ``None`` for
transparent."""
return self._palette[2]

@fill.setter
Expand All @@ -143,6 +154,8 @@ def fill(self, color):

@property
def outline(self):
"""The outline of the rounded-corner rectangle. Can be a hex value for a color or ``None``
for no outline."""
return self._palette[1]

@outline.setter
Expand All @@ -160,6 +173,7 @@ def x(self):

@x.setter
def x(self, x):
# pylint: disable=attribute-defined-outside-init
self.position = (x, self.position[1])

@property
Expand All @@ -169,4 +183,5 @@ def y(self):

@y.setter
def y(self, y):
# pylint: disable=attribute-defined-outside-init
self.position = (self.position[0], y)
8 changes: 7 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
.. 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_display_shapes
.. automodule:: adafruit_display_shapes.circle
:members:

.. automodule:: adafruit_display_shapes.rect
:members:

.. automodule:: adafruit_display_shapes.roundrect
:members:
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 = ["digitalio", "busio"]
autodoc_mock_imports = ["displayio"]


intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
Expand Down
4 changes: 0 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ 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
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@
# simple. Or you can use find_packages().
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
# CHANGE `py_modules=['...']` TO `packages=['...']`
py_modules=['adafruit_display_shapes'],
packages=['adafruit_display_shapes'],
)