From 2c55a8138d49e5abb1c859f7d8fcc1d5356c58a4 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 21 Mar 2019 15:27:09 -0400 Subject: [PATCH] Update for release. --- .travis.yml | 4 +- README.rst | 38 +++++++++++++-- adafruit_display_shapes/circle.py | 14 ++++-- adafruit_display_shapes/rect.py | 27 ++++++++--- adafruit_display_shapes/roundrect.py | 47 ++++++++++++------- docs/api.rst | 8 +++- docs/conf.py | 2 +- docs/index.rst | 4 -- ...letest.py => display_shapes_simpletest.py} | 0 setup.py | 2 +- 10 files changed, 107 insertions(+), 39 deletions(-) rename examples/{shapes_simpletest.py => display_shapes_simpletest.py} (100%) diff --git a/.travis.yml b/.travis.yml index cf8336e..ab24b75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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" diff --git a/README.rst b/README.rst index e1b5f8d..c7b5f10 100644 --- a/README.rst +++ b/README.rst @@ -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 `_. To install for current user: @@ -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 ============ diff --git a/adafruit_display_shapes/circle.py b/adafruit_display_shapes/circle.py index 43bde48..998e74a 100644 --- a/adafruit_display_shapes/circle.py +++ b/adafruit_display_shapes/circle.py @@ -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) diff --git a/adafruit_display_shapes/rect.py b/adafruit_display_shapes/rect.py index 68604d2..951552a 100644 --- a/adafruit_display_shapes/rect.py +++ b/adafruit_display_shapes/rect.py @@ -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) @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/adafruit_display_shapes/roundrect.py b/adafruit_display_shapes/roundrect.py index 33af0c1..9c3c4d6 100644 --- a/adafruit_display_shapes/roundrect.py +++ b/adafruit_display_shapes/roundrect.py @@ -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) @@ -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 @@ -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 @@ -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 @@ -120,11 +129,11 @@ 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 @@ -132,6 +141,8 @@ def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0, @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 @@ -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 @@ -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 @@ -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) diff --git a/docs/api.rst b/docs/api.rst index 68b512a..a6c3802 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -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: diff --git a/docs/conf.py b/docs/conf.py index 7c39525..670451e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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)} diff --git a/docs/index.rst b/docs/index.rst index f6eeb89..a244b32 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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 diff --git a/examples/shapes_simpletest.py b/examples/display_shapes_simpletest.py similarity index 100% rename from examples/shapes_simpletest.py rename to examples/display_shapes_simpletest.py diff --git a/setup.py b/setup.py index 7a8614a..16ba40f 100644 --- a/setup.py +++ b/setup.py @@ -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'], )