Skip to content

Commit 19183b7

Browse files
committed
Ran black, made pylint 2.x compatible
1 parent 509f956 commit 19183b7

File tree

7 files changed

+157
-96
lines changed

7 files changed

+157
-96
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_display_text/label.py

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
__version__ = "0.0.0-auto.0"
4545
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"
4646

47+
4748
class Label(displayio.Group):
4849
"""A label displaying a string of text. The origin point set by ``x`` and ``y``
4950
properties will be the left edge of the bounding box, and in the center of a M
@@ -56,8 +57,20 @@ class Label(displayio.Group):
5657
:param int max_glyphs: The largest quantity of glyphs we will display
5758
:param int color: Color of all text in RGB hex
5859
:param double line_spacing: Line spacing of text to display"""
59-
def __init__(self, font, *, x=0, y=0, text=None, max_glyphs=None, color=0xffffff,
60-
background_color=None, line_spacing=1.25, **kwargs):
60+
61+
def __init__(
62+
self,
63+
font,
64+
*,
65+
x=0,
66+
y=0,
67+
text=None,
68+
max_glyphs=None,
69+
color=0xFFFFFF,
70+
background_color=None,
71+
line_spacing=1.25,
72+
**kwargs
73+
):
6174
if not max_glyphs and not text:
6275
raise RuntimeError("Please provide a max size, or initial text")
6376
if not max_glyphs:
@@ -89,41 +102,58 @@ def __init__(self, font, *, x=0, y=0, text=None, max_glyphs=None, color=0xffffff
89102
if text is not None:
90103
self._update_text(str(text))
91104

92-
93-
def _update_text(self, new_text): # pylint: disable=too-many-locals
105+
def _update_text(self, new_text): # pylint: disable=too-many-locals
94106
x = 0
95107
y = 0
96108
i = 0
97109
old_c = 0
98-
y_offset = int((self.font.get_glyph(ord('M')).height -
99-
new_text.count('\n') * self.height * self.line_spacing) / 2)
100-
#print("y offset from baseline", y_offset)
110+
y_offset = int(
111+
(
112+
self.font.get_glyph(ord("M")).height
113+
- new_text.count("\n") * self.height * self.line_spacing
114+
)
115+
/ 2
116+
)
117+
# print("y offset from baseline", y_offset)
101118
left = right = top = bottom = 0
102119
for character in new_text:
103-
if character == '\n':
120+
if character == "\n":
104121
y += int(self.height * self._line_spacing)
105122
x = 0
106123
continue
107124
glyph = self.font.get_glyph(ord(character))
108125
if not glyph:
109126
continue
110-
right = max(right, x+glyph.width)
111-
if y == 0: # first line, find the Ascender height
112-
top = min(top, -glyph.height+y_offset)
113-
bottom = max(bottom, y-glyph.dy+y_offset)
127+
right = max(right, x + glyph.width)
128+
if y == 0: # first line, find the Ascender height
129+
top = min(top, -glyph.height + y_offset)
130+
bottom = max(bottom, y - glyph.dy + y_offset)
114131
position_y = y - glyph.height - glyph.dy + y_offset
115132
position_x = x + glyph.dx
116-
if not self._text or old_c >= len(self._text) or character != self._text[old_c]:
133+
if (
134+
not self._text
135+
or old_c >= len(self._text)
136+
or character != self._text[old_c]
137+
):
117138
try:
118-
face = displayio.TileGrid(glyph.bitmap, pixel_shader=self.palette,
119-
default_tile=glyph.tile_index,
120-
tile_width=glyph.width, tile_height=glyph.height,
121-
position=(position_x, position_y))
139+
face = displayio.TileGrid(
140+
glyph.bitmap,
141+
pixel_shader=self.palette,
142+
default_tile=glyph.tile_index,
143+
tile_width=glyph.width,
144+
tile_height=glyph.height,
145+
position=(position_x, position_y),
146+
)
122147
except TypeError:
123-
face = displayio.TileGrid(glyph.bitmap, pixel_shader=self.palette,
124-
default_tile=glyph.tile_index,
125-
tile_width=glyph.width, tile_height=glyph.height,
126-
x=position_x, y=position_y)
148+
face = displayio.TileGrid(
149+
glyph.bitmap,
150+
pixel_shader=self.palette,
151+
default_tile=glyph.tile_index,
152+
tile_width=glyph.width,
153+
tile_height=glyph.height,
154+
x=position_x,
155+
y=position_y,
156+
)
127157
if i < len(self):
128158
self[i] = face
129159
else:
@@ -141,14 +171,20 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
141171
i += 1
142172
old_c += 1
143173
# skip all non-prinables in the old string
144-
while (self._text and old_c < len(self._text) and
145-
(self._text[old_c] == '\n' or not self.font.get_glyph(ord(self._text[old_c])))):
174+
while (
175+
self._text
176+
and old_c < len(self._text)
177+
and (
178+
self._text[old_c] == "\n"
179+
or not self.font.get_glyph(ord(self._text[old_c]))
180+
)
181+
):
146182
old_c += 1
147183
# Remove the rest
148184
while len(self) > i:
149185
self.pop()
150186
self._text = new_text
151-
self._boundingbox = (left, top, left+right, bottom-top)
187+
self._boundingbox = (left, top, left + right, bottom - top)
152188

153189
@property
154190
def bounding_box(self):
@@ -217,10 +253,12 @@ def anchor_point(self, new_anchor_point):
217253
def anchored_position(self):
218254
"""Position relative to the anchor_point. Tuple containing x,y
219255
pixel coordinates."""
220-
return (self.x-self._boundingbox[2]*self._anchor_point[0],
221-
self.y-self._boundingbox[3]*self._anchor_point[1])
256+
return (
257+
self.x - self._boundingbox[2] * self._anchor_point[0],
258+
self.y - self._boundingbox[3] * self._anchor_point[1],
259+
)
222260

223261
@anchored_position.setter
224262
def anchored_position(self, new_position):
225-
self.x = int(new_position[0]-(self._boundingbox[2]*self._anchor_point[0]))
226-
self.y = int(new_position[1]-(self._boundingbox[3]*self._anchor_point[1]))
263+
self.x = int(new_position[0] - (self._boundingbox[2] * self._anchor_point[0]))
264+
self.y = int(new_position[1] - (self._boundingbox[3] * self._anchor_point[1]))

docs/conf.py

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('..'))
5+
6+
sys.path.insert(0, os.path.abspath(".."))
67

78
# -- General configuration ------------------------------------------------
89

910
# Add any Sphinx extension module names here, as strings. They can be
1011
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1112
# ones.
1213
extensions = [
13-
'sphinx.ext.autodoc',
14-
'sphinx.ext.intersphinx',
15-
'sphinx.ext.napoleon',
16-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.napoleon",
17+
"sphinx.ext.todo",
1718
]
1819

1920
# TODO: Please Read!
@@ -23,29 +24,32 @@
2324
autodoc_mock_imports = ["displayio"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
27+
intersphinx_mapping = {
28+
"python": ("https://docs.python.org/3.4", None),
29+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
30+
}
2731

2832
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
33+
templates_path = ["_templates"]
3034

31-
source_suffix = '.rst'
35+
source_suffix = ".rst"
3236

3337
# The master toctree document.
34-
master_doc = 'index'
38+
master_doc = "index"
3539

3640
# General information about the project.
37-
project = u'Adafruit Display_Text Library'
38-
copyright = u'2019 Scott Shawcroft'
39-
author = u'Scott Shawcroft'
41+
project = u"Adafruit Display_Text Library"
42+
copyright = u"2019 Scott Shawcroft"
43+
author = u"Scott Shawcroft"
4044

4145
# The version info for the project you're documenting, acts as replacement for
4246
# |version| and |release|, also used in various other places throughout the
4347
# built documents.
4448
#
4549
# The short X.Y version.
46-
version = u'1.0'
50+
version = u"1.0"
4751
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
52+
release = u"1.0"
4953

5054
# The language for content autogenerated by Sphinx. Refer to documentation
5155
# for a list of supported languages.
@@ -57,7 +61,7 @@
5761
# List of patterns, relative to source directory, that match files and
5862
# directories to ignore when looking for source files.
5963
# This patterns also effect to html_static_path and html_extra_path
60-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
64+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6165

6266
# The reST default role (used for this markup: `text`) to use for all
6367
# documents.
@@ -69,7 +73,7 @@
6973
add_function_parentheses = True
7074

7175
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7377

7478
# If true, `todo` and `todoList` produce output, else they produce nothing.
7579
todo_include_todos = False
@@ -84,68 +88,76 @@
8488
# The theme to use for HTML and HTML Help pages. See the documentation for
8589
# a list of builtin themes.
8690
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
91+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8892

8993
if not on_rtd: # only import and set the theme if we're building docs locally
9094
try:
9195
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
96+
97+
html_theme = "sphinx_rtd_theme"
98+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9499
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
100+
html_theme = "default"
101+
html_theme_path = ["."]
97102
else:
98-
html_theme_path = ['.']
103+
html_theme_path = ["."]
99104

100105
# Add any paths that contain custom static files (such as style sheets) here,
101106
# relative to this directory. They are copied after the builtin static files,
102107
# so a file named "default.css" will overwrite the builtin "default.css".
103-
html_static_path = ['_static']
108+
html_static_path = ["_static"]
104109

105110
# The name of an image file (relative to this directory) to use as a favicon of
106111
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107112
# pixels large.
108113
#
109-
html_favicon = '_static/favicon.ico'
114+
html_favicon = "_static/favicon.ico"
110115

111116
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'AdafruitDisplay_textLibrarydoc'
117+
htmlhelp_basename = "AdafruitDisplay_textLibrarydoc"
113118

114119
# -- Options for LaTeX output ---------------------------------------------
115120

116121
latex_elements = {
117-
# The paper size ('letterpaper' or 'a4paper').
118-
#
119-
# 'papersize': 'letterpaper',
120-
121-
# The font size ('10pt', '11pt' or '12pt').
122-
#
123-
# 'pointsize': '10pt',
124-
125-
# Additional stuff for the LaTeX preamble.
126-
#
127-
# 'preamble': '',
128-
129-
# Latex figure (float) alignment
130-
#
131-
# 'figure_align': 'htbp',
122+
# The paper size ('letterpaper' or 'a4paper').
123+
#
124+
# 'papersize': 'letterpaper',
125+
# The font size ('10pt', '11pt' or '12pt').
126+
#
127+
# 'pointsize': '10pt',
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
# 'preamble': '',
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
132134
}
133135

134136
# Grouping the document tree into LaTeX files. List of tuples
135137
# (source start file, target name, title,
136138
# author, documentclass [howto, manual, or own class]).
137139
latex_documents = [
138-
(master_doc, 'AdafruitDisplay_TextLibrary.tex', u'AdafruitDisplay_Text Library Documentation',
139-
author, 'manual'),
140+
(
141+
master_doc,
142+
"AdafruitDisplay_TextLibrary.tex",
143+
u"AdafruitDisplay_Text Library Documentation",
144+
author,
145+
"manual",
146+
),
140147
]
141148

142149
# -- Options for manual page output ---------------------------------------
143150

144151
# One entry per manual page. List of tuples
145152
# (source start file, name, description, authors, manual section).
146153
man_pages = [
147-
(master_doc, 'AdafruitDisplay_Textlibrary', u'Adafruit Display_Text Library Documentation',
148-
[author], 1)
154+
(
155+
master_doc,
156+
"AdafruitDisplay_Textlibrary",
157+
u"Adafruit Display_Text Library Documentation",
158+
[author],
159+
1,
160+
)
149161
]
150162

151163
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +166,13 @@
154166
# (source start file, target name, title, author,
155167
# dir menu entry, description, category)
156168
texinfo_documents = [
157-
(master_doc, 'AdafruitDisplay_TextLibrary', u'Adafruit Display_Text Library Documentation',
158-
author, 'AdafruitDisplay_TextLibrary', 'One line description of project.',
159-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"AdafruitDisplay_TextLibrary",
172+
u"Adafruit Display_Text Library Documentation",
173+
author,
174+
"AdafruitDisplay_TextLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
160178
]

0 commit comments

Comments
 (0)