Skip to content

Commit 911ab7f

Browse files
committed
Lint and fixup docs
1 parent 8c8df5c commit 911ab7f

File tree

6 files changed

+38
-27
lines changed

6 files changed

+38
-27
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ install:
2727
- pip install --force-reinstall pylint==1.9.2
2828

2929
script:
30-
- pylint adafruit_display_text.py
30+
- pylint adafruit_display_text/*.py
3131
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py)
3232
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-display_text --library_location .
3333
- cd docs && sphinx-build -E -W -b html . _build/html && cd ..

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ This is easily achieved by downloading
2828
Usage Example
2929
=============
3030

31+
For a board with a built-in display.
32+
3133
.. code:: python
3234
35+
import board
36+
import terminalio
37+
from adafruit_display_text import text_area
38+
39+
text = "Hello world"
40+
text_area = text_area.TextArea(terminalio.FONT, text=text, width=len(text))
41+
board.DISPLAY.show(text_area)
3342
3443
3544
Contributing

adafruit_display_text/text_area.py

Lines changed: 26 additions & 18 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_text`
23+
`adafruit_display_text.text_area`
2424
====================================================
2525
2626
Displays text using CircuitPython's displayio.
@@ -44,9 +44,15 @@
4444
__version__ = "0.0.0-auto.0"
4545
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"
4646

47-
4847
class TextArea(displayio.Group):
49-
def __init__(self, font, *, text=None, width=None, color=0xffffff, height=1):
48+
"""An area displaying a string of textself.
49+
50+
:param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``
51+
:param str text: Text to display
52+
:param int width: Area width in characters
53+
:param int height: Area height in characters
54+
:param int color: Color of all text in RGB hex"""
55+
def __init__(self, font, *, text=None, width=None, height=1, color=0xffffff):
5056
if not width and not text:
5157
raise RuntimeError("Please provide a width")
5258
super().__init__(max_size=width * height)
@@ -56,9 +62,9 @@ def __init__(self, font, *, text=None, width=None, color=0xffffff, height=1):
5662
self.font = font
5763
self._text = None
5864

59-
self.p = displayio.Palette(2)
60-
self.p.make_transparent(0)
61-
self.p[1] = color
65+
self.palette = displayio.Palette(2)
66+
self.palette.make_transparent(0)
67+
self.palette[1] = color
6268

6369
bounds = self.font.get_bounding_box()
6470
self.height = bounds[1]
@@ -71,17 +77,17 @@ def _update_text(self, new_text):
7177
x = 0
7278
y = 0
7379
i = 0
74-
first_different = self._text is not None
75-
for c in new_text:
76-
if chr(ord(c)) == '\n':
80+
for character in new_text:
81+
if character == '\n':
7782
y += int(self.height * 1.25)
7883
x = 0
7984
continue
80-
glyph = self.font.get_glyph(ord(c))
85+
glyph = self.font.get_glyph(ord(character))
8186
if not glyph:
8287
continue
83-
if not self._text or i >= len(self._text) or c != self._text[i]:
84-
face = displayio.TileGrid(glyph.bitmap, pixel_shader=self.p, default_tile=glyph.tile_index,
88+
if not self._text or i >= len(self._text) or character != self._text[i]:
89+
face = displayio.TileGrid(glyph.bitmap, pixel_shader=self.palette,
90+
default_tile=glyph.tile_index,
8591
tile_width=glyph.width, tile_height=glyph.height,
8692
position=(x, y + self.height - glyph.height - glyph.dy))
8793
if i < len(self):
@@ -99,16 +105,18 @@ def _update_text(self, new_text):
99105

100106
@property
101107
def color(self):
108+
"""Color of the text as an RGB hex number."""
102109
return self.p[1]
103110

104111
@color.setter
105-
def color(self, c):
106-
self.p[1] = c
112+
def color(self, new_color):
113+
self.p[1] = new_color
107114

108115
@property
109-
def text(self, t):
110-
self._text = t
116+
def text(self):
117+
"""Text to display."""
118+
return self._text
111119

112120
@text.setter
113-
def text(self, t):
114-
self._update_text(t)
121+
def text(self, new_text):
122+
self._update_text(new_text)

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_text
7+
.. automodule:: adafruit_display_text.text_area
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"]
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@ 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.
28-
2926
.. toctree::
3027
:caption: Related Products
3128

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.
34-
3529
.. toctree::
3630
:caption: Other Links
3731

0 commit comments

Comments
 (0)