Skip to content

Ran black, updated to pylint 2.x #12

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 23, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
5 changes: 4 additions & 1 deletion adafruit_display_shapes/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ class Circle(RoundRect):
``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)
super().__init__(
x0 - r, y0 - r, 2 * r + 1, 2 * r + 1, r, fill=fill, outline=outline
)
2 changes: 2 additions & 0 deletions adafruit_display_shapes/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes.git"


class Line(Polygon):
# pylint: disable=too-many-arguments,invalid-name
"""A line.
Expand All @@ -53,5 +54,6 @@ class Line(Polygon):
:param y1: The y-position of the second vertex.
:param color: The color of the line.
"""

def __init__(self, x0, y0, x1, y1, color):
super().__init__([(x0, y0), (x1, y1)], outline=color)
17 changes: 13 additions & 4 deletions adafruit_display_shapes/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Polygon(displayio.TileGrid):
:param outline: The outline of the polygon. Can be a hex value for a color or
``None`` for no outline.
"""

def __init__(self, points, *, outline=None):
xs = []
ys = []
Expand Down Expand Up @@ -82,10 +83,17 @@ def __init__(self, points, *, outline=None):
point_b = points[0]
else:
point_b = points[index + 1]
self._line(point_a[0] - x_offset, point_a[1] - y_offset,
point_b[0] - x_offset, point_b[1] - y_offset, 1)

super().__init__(self._bitmap, pixel_shader=self._palette, x=x_offset, y=y_offset)
self._line(
point_a[0] - x_offset,
point_a[1] - y_offset,
point_b[0] - x_offset,
point_b[1] - y_offset,
1,
)

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

# pylint: disable=invalid-name, too-many-locals, too-many-branches
def _line(self, x0, y0, x1, y1, color):
Expand Down Expand Up @@ -128,6 +136,7 @@ def _line(self, x0, y0, x1, y1, color):
if err < 0:
y0 += ystep
err += dx

# pylint: enable=invalid-name, too-many-locals, too-many-branches

@property
Expand Down
5 changes: 3 additions & 2 deletions adafruit_display_shapes/rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Rect(displayio.TileGrid):
``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 @@ -68,11 +69,11 @@ def __init__(self, x, y, width, height, *, fill=None, outline=None, stroke=1):
for w in range(width):
for line in range(stroke):
self._bitmap[w, line] = 1
self._bitmap[w, height-1-line] = 1
self._bitmap[w, height - 1 - line] = 1
for _h in range(height):
for line in range(stroke):
self._bitmap[line, _h] = 1
self._bitmap[width-1-line, _h] = 1
self._bitmap[width - 1 - line, _h] = 1

if fill is not None:
self._palette[0] = fill
Expand Down
79 changes: 53 additions & 26 deletions adafruit_display_shapes/roundrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,23 @@ class RoundRect(displayio.TileGrid):
``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)
for i in range(0, width): # draw the center chunk
for j in range(r, height - r): # draw the center chunk
for i in range(0, width): # 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)
self._helper(
r,
r,
r,
color=2,
fill=True,
x_offset=width - 2 * r - 1,
y_offset=height - 2 * r - 1,
)

if fill is not None:
self._palette[2] = fill
Expand All @@ -74,19 +82,37 @@ def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1)
for w in range(r, width - r):
for line in range(stroke):
self._bitmap[w, line] = 1
self._bitmap[w, height-line-1] = 1
self._bitmap[w, height - line - 1] = 1
for _h in range(r, height - r):
for line in range(stroke):
self._bitmap[line, _h] = 1
self._bitmap[width-line-1, _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)
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, x=x, y=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, corner_flags=0xF, fill=False):
def _helper(
self,
x0,
y0,
r,
*,
color,
x_offset=0,
y_offset=0,
stroke=1,
corner_flags=0xF,
fill=False
):
f = 1 - r
ddF_x = 1
ddF_y = -2 * r
Expand All @@ -103,32 +129,33 @@ def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0,
f += ddF_x
if corner_flags & 0x8:
if fill:
for w in range(x0-y, x0+y+x_offset):
self._bitmap[w, y0+x+y_offset] = color
for w in range(x0-x, x0+x+x_offset):
self._bitmap[w, y0+y+y_offset] = color
for w in range(x0 - y, x0 + y + x_offset):
self._bitmap[w, y0 + x + y_offset] = color
for w in range(x0 - x, x0 + x + x_offset):
self._bitmap[w, y0 + y + y_offset] = color
else:
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
self._bitmap[x0 - y + line, y0 + x + y_offset] = color
self._bitmap[x0 - x, y0 + y + y_offset - line] = color
if corner_flags & 0x1:
if fill:
for w in range(x0-y, x0+y+x_offset):
self._bitmap[w, y0-x] = color
for w in range(x0-x, x0+x+x_offset):
self._bitmap[w, y0-y] = color
for w in range(x0 - y, x0 + y + x_offset):
self._bitmap[w, y0 - x] = color
for w in range(x0 - x, x0 + x + x_offset):
self._bitmap[w, y0 - y] = color
else:
for line in range(stroke):
self._bitmap[x0-y+line, y0-x] = color
self._bitmap[x0-x, y0-y+line] = color
self._bitmap[x0 - y + line, y0 - x] = color
self._bitmap[x0 - x, y0 - y + line] = color
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
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 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
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
Expand Down
20 changes: 14 additions & 6 deletions adafruit_display_shapes/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def __init__(self, x0, y0, x1, y1, x2, y2, *, fill=None, outline=None):
super().__init__(points)

if fill is not None:
self._draw_filled(x0 - min(xs), 0, x1 - min(xs), y1 - y0, x2 - min(xs), y2 - y0)
self._draw_filled(
x0 - min(xs), 0, x1 - min(xs), y1 - y0, x2 - min(xs), y2 - y0
)
self.fill = fill
else:
self.fill = None
Expand All @@ -95,12 +97,17 @@ def __init__(self, x0, y0, x1, y1, x2, y2, *, fill=None, outline=None):
point_b = points[0]
else:
point_b = points[index + 1]
self._line(point_a[0] - min(xs), point_a[1] - y0,
point_b[0] - min(xs), point_b[1] - y0, 1)
self._line(
point_a[0] - min(xs),
point_a[1] - y0,
point_b[0] - min(xs),
point_b[1] - y0,
1,
)

# pylint: disable=invalid-name, too-many-branches
def _draw_filled(self, x0, y0, x1, y1, x2, y2):
if y0 == y2: # Handle awkward all-on-same-line case as its own thing
if y0 == y2: # Handle awkward all-on-same-line case as its own thing
a = x0
b = x0
if x1 < a:
Expand All @@ -116,9 +123,9 @@ def _draw_filled(self, x0, y0, x1, y1, x2, y2):
return

if y1 == y2:
last = y1 # Include y1 scanline
last = y1 # Include y1 scanline
else:
last = y1 - 1 # Skip it
last = y1 - 1 # Skip it

# Upper Triangle
for y in range(y0, last + 1):
Expand All @@ -135,6 +142,7 @@ def _draw_filled(self, x0, y0, x1, y1, x2, y2):
if a > b:
a, b = b, a
self._line(a, y, b, y, 2)

# pylint: enable=invalid-name, too-many-locals, too-many-branches

@property
Expand Down
Loading