Skip to content

Commit 0c19bd0

Browse files
committed
pylint compliance
1 parent 0d9c258 commit 0c19bd0

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

adafruit_turtle.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def __repr__(self):
139139

140140
class turtle(object):
141141
"""A Turtle that can be given commands to draw."""
142-
142+
# pylint:disable=too-many-statements
143143
def __init__(self, display=None, scale=1):
144144

145145
if display:
@@ -224,6 +224,7 @@ def __init__(self, display=None, scale=1):
224224
self._splash.append(self._turtle_group)
225225
self._penstate = False
226226
self._pensize = 1
227+
self._pencolor = 1
227228
self.pencolor(Color.WHITE)
228229
self._bg_pic = None
229230
self._turtle_pic = None
@@ -233,8 +234,10 @@ def __init__(self, display=None, scale=1):
233234
self._stamps = {}
234235
self._turtle_odb_use = 0
235236
self._turtle_odb_file = None
237+
self._odb_tilegrid = None
236238
gc.collect()
237239
self._display.show(self._splash)
240+
# pylint:enable=too-many-statements
238241

239242
def _drawturtle(self):
240243
if self._turtle_pic is None:
@@ -257,8 +260,6 @@ def forward(self, distance):
257260
:param distance: how far to move (integer or float)
258261
"""
259262
p = self.pos()
260-
# works only for degrees.
261-
# TODO implement for radians
262263
x1 = p[0] + math.sin(math.radians((self._angleOffset + self._angleOrient*self._heading) % self._fullcircle)) * distance
263264
y1 = p[1] + math.cos(math.radians((self._angleOffset + self._angleOrient*self._heading) % self._fullcircle)) * distance
264265
self.goto(x1, y1)
@@ -301,7 +302,7 @@ def left(self, angle):
301302
self._turn(angle)
302303
lt = left
303304

304-
#pylint:disable=too-many-branches,too-many-statements
305+
# pylint:disable=too-many-branches,too-many-statements
305306
def goto(self, x1, y1=None):
306307
"""If y1 is None, x1 must be a pair of coordinates or an (x, y) tuple
307308
@@ -363,7 +364,7 @@ def goto(self, x1, y1=None):
363364
self._x = x0
364365
self._y = y0
365366
if self._speed > 0:
366-
if step >= self._speed :
367+
if step >= self._speed:
367368
# mark the step
368369
step = 1
369370
self._drawturtle()
@@ -381,6 +382,7 @@ def goto(self, x1, y1=None):
381382
self._drawturtle()
382383
setpos = goto
383384
setposition = goto
385+
# pylint:enable=too-many-branches,too-many-statements
384386

385387
def setx(self, x):
386388
"""Set the turtle's first coordinate to x, leave second coordinate
@@ -424,6 +426,7 @@ def home(self):
424426
self.setheading(90)
425427
self.goto(0, 0)
426428

429+
# pylint:disable=too-many-locals
427430
def _plot(self, x, y, c):
428431
if self._pensize == 1:
429432
try:
@@ -498,6 +501,7 @@ def _plot(self, x, y, c):
498501
x0 -= 1
499502
else:
500503
x0 += 1
504+
# pylint:enable=too-many-locals
501505

502506
def circle(self, radius, extent=None, steps=None):
503507
"""Draw a circle with given radius. The center is radius units left of
@@ -542,6 +546,7 @@ def circle(self, radius, extent=None, steps=None):
542546
self.goto(pos)
543547
self.setheading(h)
544548

549+
# pylint:disable=inconsistent-return-statements
545550
def speed(self, speed=None):
546551
"""
547552
@@ -571,6 +576,7 @@ def speed(self, speed=None):
571576
self._speed = 0
572577
else:
573578
self._speed = speed
579+
# pylint:enable=inconsistent-return-statements
574580

575581
def dot(self, size=None, color=None):
576582
"""Draw a circular dot with diameter size, using color.
@@ -605,6 +611,7 @@ def dot(self, size=None, color=None):
605611
self._plot(self._x, self._y, color)
606612
self._pensize = pensize
607613

614+
608615
def stamp(self, bitmap=None, palette=None):
609616
"""
610617
Stamp a copy of the turtle shape onto the canvas at the current
@@ -613,7 +620,7 @@ def stamp(self, bitmap=None, palette=None):
613620
"""
614621
if len(self._fg_addon_group) >= 6:
615622
print("Addon group full")
616-
return
623+
return -1
617624
s_id = len(self._stamps)
618625
if self._turtle_pic is None:
619626
# easy.
@@ -629,9 +636,9 @@ def stamp(self, bitmap=None, palette=None):
629636
y=int(self._y - self._turtle_odb.height // 2))
630637
self._turtle_odb_use += 1
631638
else:
632-
if bitmap == None:
639+
if bitmap is None:
633640
raise RuntimeError("a bitmap must be provided")
634-
if palette == None:
641+
if palette is None:
635642
raise RuntimeError("a palette must be provided")
636643
new_stamp = displayio.TileGrid(bitmap, pixel_shader=palette,
637644
x=int(self._x-bitmap.width//2),
@@ -711,13 +718,9 @@ def towards(self, x1, y1=None):
711718
result = math.degrees(math.atan2(x1-x0, y1-y0))
712719
result /= self._degreesPerAU
713720
return (self._angleOffset + self._angleOrient*result) % self._fullcircle
714-
if self._logomode :
715-
print("logo mode")
721+
if self._logomode:
716722
return(math.degrees(math.atan2(x0-x1, y0-y1)))
717-
else:
718-
# not used yet
719-
print("standard mode")
720-
return(math.degrees(math.atan2(y0-y1, x0-x1)))
723+
return(math.degrees(math.atan2(y0-y1, x0-x1)))
721724

722725
def xcor(self):
723726
"""Return the turtle's x coordinate."""
@@ -755,7 +758,7 @@ def _setDegreesPerAU(self, fullcircle):
755758
"""Helper function for degrees() and radians()"""
756759
self._fullcircle = fullcircle
757760
self._degreesPerAU = 360/fullcircle
758-
if self._mode == "logo":
761+
if self._logomode:
759762
self._angleOffset = 0
760763
else:
761764
self._angleOffset = -fullcircle/4
@@ -846,10 +849,11 @@ def pensize(self, width=None):
846849
###########################################################################
847850
# Color control
848851

849-
#pylint:disable=no-self-use
852+
# pylint:disable=no-self-use
850853

851854
def _color_to_pencolor(self, c):
852855
return Color.colors.index(c)
856+
# pylint:enable=no-self-use
853857

854858
def pencolor(self, c=None):
855859
"""
@@ -908,8 +912,9 @@ def bgcolor(self, c=None):
908912
self._turtle_palette.make_opaque(1)
909913
for h in range(self._h):
910914
for w in range(self._w):
911-
if self._fg_bitmap[w, h] == old_color :
915+
if self._fg_bitmap[w, h] == old_color:
912916
self._fg_bitmap[w, h] = self._bg_color
917+
return Color.colors[self._bg_color]
913918

914919
def set_bgpic(self, file):
915920
"""
@@ -976,33 +981,28 @@ def clear(self):
976981
def showturtle(self):
977982
"""
978983
Make the turtle visible."""
979-
if len(self._turtle_group) == 1:
984+
if self._turtle_group:
980985
return
986+
if self._turtle_pic is None:
987+
self._turtle_group.append(self._turtle_sprite)
981988
else:
982-
if self._turtle_pic is None:
983-
self._turtle_group.append(self._turtle_sprite)
984-
else:
985-
self._turtle_group.append(self._turtle_alt_sprite)
986-
return
989+
self._turtle_group.append(self._turtle_alt_sprite)
987990
st = showturtle
988991

989992
def hideturtle(self):
990993
"""
991994
Make the turtle invisible."""
992-
if len(self._turtle_group) == 0:
993-
return
994-
else:
995-
self._turtle_group.pop()
995+
if not self._turtle_group:
996996
return
997+
self._turtle_group.pop()
997998
ht = hideturtle
998999

9991000
def isvisible(self):
10001001
"""
10011002
Return True if the Turtle is shown, False if it's hidden."""
1002-
if len(self._turtle_group) == 0:
1003-
return False
1004-
else:
1003+
if self._turtle_group:
10051004
return True
1005+
return False
10061006

10071007
def changeturtle(self, source=None, dimensions=(12, 12)):
10081008
"""
@@ -1015,14 +1015,14 @@ def changeturtle(self, source=None, dimensions=(12, 12)):
10151015
if self._turtle_pic is None:
10161016
return
10171017
else:
1018-
if len(self._turtle_group) == 1:
1018+
if self._turtle_group:
10191019
self._turtle_group.remove(self._turtle_alt_sprite)
10201020
self._turtle_group.append(self._turtle_sprite)
10211021
self._turtle_alt_sprite = None
10221022
if self._turtle_odb is not None:
10231023
self._turtle_odb_use -= 1
10241024
self._turtle_odb = None
1025-
if self._turtle_odb_file is not None :
1025+
if self._turtle_odb_file is not None:
10261026
if self._turtle_odb_use == 0:
10271027
self._turtle_odb_file.close()
10281028
self._turtle_odb_file = None
@@ -1032,7 +1032,7 @@ def changeturtle(self, source=None, dimensions=(12, 12)):
10321032
elif isinstance(source, str):
10331033
visible = self.isvisible()
10341034
if self._turtle_pic is not None:
1035-
if len(self._turtle_group) == 1:
1035+
if self._turtle_group:
10361036
self._turtle_group.remove(self._turtle_alt_sprite)
10371037
self._turtle_alt_sprite = None
10381038
self._turtle_odb = None
@@ -1055,7 +1055,7 @@ def changeturtle(self, source=None, dimensions=(12, 12)):
10551055
self._turtle_pic = True
10561056
self._turtle_alt_sprite = displayio.TileGrid(self._turtle_odb, pixel_shader=displayio.ColorConverter())
10571057

1058-
if len(self._turtle_group) == 1:
1058+
if self._turtle_group:
10591059
self._turtle_group.pop()
10601060
if visible:
10611061
self._turtle_group.append(self._turtle_alt_sprite)
@@ -1068,7 +1068,7 @@ def changeturtle(self, source=None, dimensions=(12, 12)):
10681068
self._turtle_odb_file.close()
10691069
self._turtle_pic = dimensions
10701070
self._turtle_alt_sprite = source
1071-
if len(self._turtle_group) == 1:
1071+
if self._turtle_group:
10721072
self._turtle_group.pop()
10731073
self._turtle_group.append(self._turtle_alt_sprite)
10741074
self._drawturtle()
@@ -1110,13 +1110,13 @@ def _turn(self, angle):
11101110
steps += abs(angle-steps*d_angle) // abs(d_angle)
11111111

11121112
self._plot(self._x, self._y, self._pencolor)
1113-
for i in range(steps):
1113+
for _ in range(steps):
11141114
self._heading += d_angle
11151115
self._heading %= self._fullcircle # wrap
11161116
self._plot(self._x, self._y, self._pencolor)
11171117

11181118
# error correction
1119-
if self._heading != (start_angle + angle) % self._fullcircle :
1119+
if self._heading != (start_angle + angle) % self._fullcircle:
11201120
self._heading = start_angle + angle
11211121
self._heading %= self._fullcircle
11221122
self._plot(self._x, self._y, self._pencolor)
@@ -1129,4 +1129,3 @@ def _GCD(self, a, b):
11291129
else:
11301130
r = a % b
11311131
return self._GCD(b, r)
1132-

0 commit comments

Comments
 (0)