Skip to content

Commit 07c588b

Browse files
authored
Merge pull request #1 from kattni/setup
Fixed up for release.
2 parents 104f351 + e4a9a6a commit 07c588b

9 files changed

+76
-57
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cache:
1515
# or remove the env block entirely and remove the condition in the
1616
# deploy block.
1717
env:
18-
- DEPLOY_PYPI="false"
18+
- DEPLOY_PYPI="true"
1919

2020
deploy:
2121
- provider: releases
@@ -31,7 +31,7 @@ deploy:
3131
- provider: pypi
3232
user: adafruit-travis
3333
password:
34-
secure: #-- PASTE ENCRYPTED PASSWORD HERE --#
34+
secure: ZxsMZrdftjJBqxdW4fowdLWFR5ykdCawV6pQt1BwRO8Q+6PGRloGkpIBQ2tj9eX85YY8q5sBIhqNwODJ5od9/B7nbx3xTo8T79O5Nq//tv9zmZaQS/uqZo8fj9TaHpaq+MVH2aCRfepey9/OzVRRsIZW/nEpaHuDPow7UtaoGFij4VsZ66RoVm88J7Zer8/bVlOdYatmMpb8SOSRE8Hj6jx7F4ayVxF2hVdzd8wOxrKObDkEFZ9ym0xYKHMWdPehtbnCOo/rgm0jtutd8plrKnTm//qNFEp6CdRcLbCEL6cQoPOWzk47p7tGe42yHllquB//f2VqmGzep3+YverAAOrPG2XOxp2ypQFc0RL6KY6CpDqWAdfYh+/H5o74oxCvRVWyUyHZ2eTHrd6YKnwlhxDTk0+A7FwforEPODm/YGxoTrRXduiD+LR4xvPFaQISAyFjIOeCYA1Yyfz4ZTQgcpXwqAa4irLlfb3rdjWRZIRnhR6mQsd1nTqDaxXcqlbL/EIH8KKG0ZBIAXL7F73ajRblaVn2iHvYkrTDKQhR8yaIFBUgAoSXdCBY1TIg3/RWU/knRyQItEKiQHXgua+gVO95GT4a2Hf2yV4y3PoaXCSoAVF24hgnHN9WRIEpyVRHgcMJpH2bLnXmDnl8KPgEqZD586tQaCqZdIdKtNJhUbo=
3535
on:
3636
tags: true
3737
condition: $DEPLOY_PYPI = "true"
@@ -42,7 +42,7 @@ install:
4242
- pip install --force-reinstall pylint==1.9.2
4343

4444
script:
45-
- pylint adafruit_display_button.py
45+
- pylint adafruit_button.py
4646
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py)
4747
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-display_button --library_location .
4848
- cd docs && sphinx-build -E -W -b html . _build/html && cd ..

README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ This is easily achieved by downloading
2828

2929
Installing from PyPI
3030
--------------------
31-
.. note:: This library is not available on PyPI yet. Install documentation is included
32-
as a standard element. Stay tuned for PyPI availability!
33-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
34-
If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
3531
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
3632
PyPI <https://pypi.org/project/adafruit-circuitpython-display_button/>`_. To install for current user:
3733

@@ -57,7 +53,7 @@ To install in a virtual environment in your current project:
5753
Usage Example
5854
=============
5955

60-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
56+
See examples in examples/ folder.
6157

6258
Contributing
6359
============

adafruit_button.py

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_display_button`
23+
`adafruit_button`
2424
================================================================================
2525
2626
UI Buttons for displayio
@@ -38,21 +38,50 @@
3838
3939
"""
4040

41+
from micropython import const
4142
import displayio
42-
from adafruit_display_text.text_area import TextArea
43-
from adafruit_bitmap_font import bitmap_font
43+
from adafruit_display_text.label import Label
4444
from adafruit_display_shapes.rect import Rect
4545
from adafruit_display_shapes.roundrect import RoundRect
4646

4747
__version__ = "0.0.0-auto.0"
4848
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Button.git"
4949

5050

51+
def _check_color(color):
52+
# if a tuple is supplied, convert it to a RGB number
53+
if isinstance(color, tuple):
54+
r, g, b = color
55+
return int((r << 16) + (g << 8) + (b & 0xff))
56+
return color
57+
58+
5159
class Button():
60+
# pylint: disable=too-many-instance-attributes, too-many-locals
61+
"""Helper class for creating UI buttons for ``displayio``.
62+
63+
:param x: The x position of the button.
64+
:param y: The y position of the button.
65+
:param width: The width of the button in pixels.
66+
:param height: The height of the button in pixels.
67+
:param name: The name of the button.
68+
:param style: The style of the button. Can be RECT, ROUNDRECT, SHADOWRECT, SHADOWROUNDRECT.
69+
Defaults to RECT.
70+
:param fill_color: The color to fill the button. Defaults to 0xFFFFFF.
71+
:param outline_color: The color of the outline of the button.
72+
:param label: The text that appears inside the button. Defaults to not displaying the label.
73+
:param label_font: The button label font.
74+
:param label_color: The color of the button label text. Defaults to 0x0.
75+
:param selected_fill: Inverts the fill color.
76+
:param selected_outline: Inverts the outline color.
77+
:param selected_label: Inverts the label color.
78+
79+
"""
5280
RECT = const(0)
5381
ROUNDRECT = const(1)
5482
SHADOWRECT = const(2)
5583
SHADOWROUNDRECT = const(3)
84+
5685
def __init__(self, *, x, y, width, height, name=None, style=RECT,
5786
fill_color=0xFFFFFF, outline_color=0x0,
5887
label=None, label_font=None, label_color=0x0,
@@ -66,66 +95,66 @@ def __init__(self, *, x, y, width, height, name=None, style=RECT,
6695
self._selected = False
6796
self.group = displayio.Group()
6897
self.name = name
98+
self.label = label
6999

70-
self.fill_color = fill_color
71-
self.outline_color = outline_color
100+
self.fill_color = _check_color(fill_color)
101+
self.outline_color = _check_color(outline_color)
72102
self.label_color = label_color
73103
# Selecting inverts the button colors!
74-
self.selected_fill = selected_fill
75-
self.selected_outline = selected_outline
76-
self.selected_label = selected_label
104+
self.selected_fill = _check_color(selected_fill)
105+
self.selected_outline = _check_color(selected_outline)
106+
self.selected_label = _check_color(selected_label)
77107

78108
if self.selected_fill is None and fill_color is not None:
79-
self.selected_fill = (~fill_color) & 0xFFFFFF
109+
self.selected_fill = (~self.fill_color) & 0xFFFFFF
80110
if self.selected_outline is None and outline_color is not None:
81-
self.selected_outline = (~outline_color) & 0xFFFFFF
111+
self.selected_outline = (~self.outline_color) & 0xFFFFFF
82112

83113
if outline_color or fill_color:
84114
self.body = self.shadow = None
85-
if style == RECT:
115+
if style == Button.RECT:
86116
self.body = Rect(x, y, width, height,
87-
fill=fill_color, outline=outline_color)
88-
elif style == ROUNDRECT:
117+
fill=self.fill_color, outline=self.outline_color)
118+
elif style == Button.ROUNDRECT:
89119
self.body = RoundRect(x, y, width, height, r=10,
90-
fill=fill_color, outline=outline_color)
91-
elif style == SHADOWRECT:
92-
self.shadow = Rect(x+2, y+2, width-2, height-2,
93-
fill=outline_color)
94-
self.body = Rect(x, y, width-2, height-2,
95-
fill=fill_color, outline=outline_color)
96-
elif style == SHADOWROUNDRECT:
97-
self.shadow = RoundRect(x+2, y+2, width-2, height-2, r=10,
120+
fill=self.fill_color, outline=self.outline_color)
121+
elif style == Button.SHADOWRECT:
122+
self.shadow = Rect(x + 2, y + 2, width - 2, height - 2,
98123
fill=outline_color)
99-
self.body = RoundRect(x, y, width-2, height-2, r=10,
100-
fill=fill_color, outline=outline_color)
124+
self.body = Rect(x, y, width - 2, height - 2,
125+
fill=self.fill_color, outline=self.outline_color)
126+
elif style == Button.SHADOWROUNDRECT:
127+
self.shadow = RoundRect(x + 2, y + 2, width - 2, height - 2, r=10,
128+
fill=self.outline_color)
129+
self.body = RoundRect(x, y, width - 2, height - 2, r=10,
130+
fill=self.fill_color, outline=self.outline_color)
101131
if self.shadow:
102132
self.group.append(self.shadow)
103133
self.group.append(self.body)
104134

105-
if label and (label_color is not None): # button with text label
135+
if label and (label_color is not None): # button with text label
106136
if not label_font:
107137
raise RuntimeError("Please provide label font")
108138
dims = label_font.text_bounding_box(label)
109139
if dims[2] >= width or dims[3] >= height:
110140
raise RuntimeError("Button not large enough for label")
111-
self.label = TextArea(label_font, text=label)
112-
self.label.x = x + (width - dims[2])//2
141+
self.label = Label(label_font, text=label)
142+
self.label.x = x + (width - dims[2]) // 2
113143
self.label.y = y + (height - dims[3])
114144
self.label.color = label_color
115145
self.group.append(self.label)
116146

117147
if self.selected_label is None and label_color is not None:
118148
self.selected_label = (~label_color) & 0xFFFFFF
119-
#print(dims)
149+
# print(dims)
120150

121-
"""
122-
#else: # ok just a bounding box
123-
#self.bodyshape = displayio.Shape(width, height)
124-
#self.group.append(self.bodyshape)
125-
"""
151+
# else: # ok just a bounding box
152+
# self.bodyshape = displayio.Shape(width, height)
153+
# self.group.append(self.bodyshape)
126154

127155
@property
128156
def selected(self):
157+
"""Selected inverts the colors."""
129158
return self._selected
130159

131160
@selected.setter
@@ -142,4 +171,9 @@ def selected(self, value):
142171
self.label.color = self.label_color
143172

144173
def contains(self, point):
145-
return (self.x <= point[0] <= self.x+self.width) and (self.y <= point[1] <= self.y+self.height)
174+
"""Used to determine if a point is contained within a button. For example,
175+
``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for
176+
determining that a button has been touched.
177+
"""
178+
return (self.x <= point[0] <= self.x + self.width) and (self.y <= point[1] <=
179+
self.y + self.height)

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
55
.. use this format as the module name: "adafruit_foo.foo"
66
7-
.. automodule:: adafruit_display_button
7+
.. automodule:: adafruit_button
88
:members:

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Uncomment the below if you use native CircuitPython modules such as
2121
# digitalio, micropython and busio. List the modules you use. Without it, the
2222
# autodoc module docs will fail to generate with a warning.
23-
# autodoc_mock_imports = ["digitalio", "busio"]
23+
autodoc_mock_imports = ["displayio", "adafruit_display_text", "adafruit_display_shapes"]
2424

2525

2626
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}

docs/index.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
2826

2927
.. toctree::
3028
:caption: Related Products
3129

32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
3430

3531
.. toctree::
3632
:caption: Other Links

examples/display_button_simpletest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import time
1+
import os
22
import board
33
import displayio
4-
import os
5-
from adafruit_display_text.text_area import TextArea
64
from adafruit_bitmap_font import bitmap_font
7-
from adafruit_display_shapes.rect import Rect
85
from adafruit_button import Button
96
import adafruit_touchscreen
107

@@ -17,8 +14,8 @@
1714

1815
# the current working directory (where this file is)
1916
cwd = ("/"+__file__).rsplit('/', 1)[0]
20-
fonts = [file for file in os.listdir(cwd+"/fonts/")
21-
if (file.endswith(".bdf") and not file.startswith("._"))]
17+
fonts = [file for file in os.listdir(cwd+"/fonts/")
18+
if (file.endswith(".bdf") and not file.startswith("._"))]
2219
for i, filename in enumerate(fonts):
2320
fonts[i] = cwd+"/fonts/"+filename
2421
print(fonts)

examples/display_button_soundboard.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import time
2-
import board
3-
import displayio
42
from adafruit_pyportal import PyPortal
53
from adafruit_button import Button
64

0 commit comments

Comments
 (0)