Skip to content

Remove cp 6 fallback #29

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 2 commits into from
Feb 19, 2022
Merged
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
42 changes: 8 additions & 34 deletions adafruit_turtle.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,6 @@ def stamp(self, bitmap=None, palette=None):
turtle position. Return a stamp_id for that stamp, which can be used to
delete it by calling clearstamp(stamp_id).
"""
# The restriction on max_size in displayio.Group has been removed.
# For now, leave this with a limit of 6 so as not to break any
# deployed code.
if len(self._fg_addon_group) >= 6:
print("Addon group full")
return -1
s_id = len(self._stamps)
if self._turtle_pic is None:
# easy.
Expand All @@ -660,11 +654,7 @@ def stamp(self, bitmap=None, palette=None):
# odb bitmap
new_stamp = displayio.TileGrid(
self._turtle_odb,
pixel_shader=getattr(
self._turtle_odb, "pixel_shader", displayio.ColorConverter()
),
# TODO: Once CP6 is no longer supported, replace the above line with below
# pixel_shader=self._turtle_odb.pixel_shader,
pixel_shader=self._turtle_odb.pixel_shader,
x=int(self._x - self._turtle_odb.width // 2),
y=int(self._y - self._turtle_odb.height // 2),
)
Expand Down Expand Up @@ -701,8 +691,7 @@ def clearstamp(self, stampid):
if isinstance(self._stamps[stampid], tuple):
self._fg_addon_group.remove(self._stamps[stampid][0])
self._turtle_odb_use -= 1
if self._turtle_odb_use == 0:
self._stamps[stampid][1].close()

else:
self._fg_addon_group.remove(self._stamps[stampid])
self._stamps[stampid] = None
Expand Down Expand Up @@ -970,17 +959,14 @@ def bgpic(self, picname=None):
if self._bg_pic is not None:
self._bg_addon_group.remove(self._odb_tilegrid)
self._odb_tilegrid = None
self._bg_pic.close()
self._bg_pic = None
self._bg_pic_filename = ""
else:
with open(picname, "rb") as self._bg_pic:
odb = displayio.OnDiskBitmap(self._bg_pic)
odb = displayio.OnDiskBitmap(picname)

self._odb_tilegrid = displayio.TileGrid(
odb,
pixel_shader=getattr(odb, "pixel_shader", displayio.ColorConverter()),
# TODO: Once CP6 is no longer supported, replace the above line with below
# pixel_shader=odb.pixel_shader,
pixel_shader=odb.pixel_shader,
)
self._bg_addon_group.append(self._odb_tilegrid)
self._bg_pic_filename = picname
Expand Down Expand Up @@ -1069,8 +1055,6 @@ def changeturtle(self, source=None, dimensions=(12, 12)):
self._turtle_odb_use -= 1
self._turtle_odb = None
if self._turtle_odb_file is not None:
if self._turtle_odb_use == 0:
self._turtle_odb_file.close()
self._turtle_odb_file = None
self._turtle_pic = None
self._drawturtle()
Expand All @@ -1083,17 +1067,13 @@ def changeturtle(self, source=None, dimensions=(12, 12)):
self._turtle_alt_sprite = None
self._turtle_odb = None
if not isinstance(self._turtle_pic, tuple):
self._turtle_odb_file.close()
self._turtle_odb_file = None
self._turtle_odb_use -= 1
self._turtle_pic = None
self._turtle_odb_file = open( # pylint: disable=consider-using-with
source, "rb"
)

try:
self._turtle_odb = displayio.OnDiskBitmap(self._turtle_odb_file)
self._turtle_odb = displayio.OnDiskBitmap(source)
except:
self._turtle_odb_file.close()
self._turtle_odb_file = None
self._turtle_pic = None
if visible:
Expand All @@ -1103,11 +1083,7 @@ def changeturtle(self, source=None, dimensions=(12, 12)):
self._turtle_pic = True
self._turtle_alt_sprite = displayio.TileGrid(
self._turtle_odb,
pixel_shader=getattr(
self._turtle_odb, "pixel_shader", displayio.ColorConverter()
),
# TODO: Once CP6 is no longer supported, replace the above line with below
# pixel_shader=self._turtle_odb.pixel_shader,
pixel_shader=self._turtle_odb.pixel_shader,
)

if self._turtle_group:
Expand All @@ -1119,8 +1095,6 @@ def changeturtle(self, source=None, dimensions=(12, 12)):
if self._turtle_pic is not None:
if self._turtle_odb_file is not None:
self._turtle_odb_use -= 1
if self._turtle_odb_use == 0:
self._turtle_odb_file.close()
self._turtle_pic = dimensions
self._turtle_alt_sprite = source
if self._turtle_group:
Expand Down