Skip to content

Commit 45d5329

Browse files
committed
reword instances of 'image' to 'slide'. Remove backwards compatibility for Sprite
1 parent 0907d10 commit 45d5329

File tree

2 files changed

+35
-41
lines changed

2 files changed

+35
-41
lines changed

adafruit_slideshow.py

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ def _check_json_file(file):
201201
return False
202202
return False
203203
self.loop = loop
204-
"""Specifies whether to loop through the images continuously or play through the list once.
204+
"""Specifies whether to loop through the slides continuously or play through the list once.
205205
``True`` will continue to loop, ``False`` will play only once."""
206206

207207
self.dwell = dwell
208-
"""The number of seconds each image displays, in seconds."""
208+
"""The number of seconds each slide displays, in seconds."""
209209

210210
self.direction = direction
211211
"""Specify the playback direction. Default is ``PlayBackDirection.FORWARD``. Can also be
@@ -215,9 +215,9 @@ def _check_json_file(file):
215215
"""Enable auto-advance based on dwell time. Set to ``False`` to manually control."""
216216

217217
self.fade_effect = fade_effect
218-
"""Whether to include the fade effect between images. ``True`` tells the code to fade the
219-
backlight up and down between image display transitions. ``False`` maintains max
220-
brightness on the backlight between image transitions."""
218+
"""Whether to include the fade effect between slides. ``True`` tells the code to fade the
219+
backlight up and down between slide display transitions. ``False`` maintains max
220+
brightness on the backlight between slide transitions."""
221221

222222
# Load the image names before setting order so they can be reordered.
223223
self._img_start = None
@@ -236,11 +236,9 @@ def _check_json_file(file):
236236
self._h_align = h_align
237237
self._v_align = v_align
238238

239-
self._current_image = -1
240-
self._image_file = None
239+
self._current_slide_index = -1
240+
self._slide_file = None
241241
self._brightness = 0.5
242-
# 4.0.0 Beta 2 replaces Sprite with TileGrid so use either.
243-
self._sprite_class = getattr(displayio, "Sprite", displayio.TileGrid)
244242

245243
# Setup the display
246244
self._group = displayio.Group()
@@ -259,9 +257,9 @@ def _check_json_file(file):
259257
self.advance()
260258

261259
@property
262-
def current_image_name(self):
260+
def current_slide_name(self):
263261
"""Returns the current image name."""
264-
return self._file_list[self._current_image]
262+
return self._file_list[self._current_slide_index]
265263

266264
@property
267265
def order(self):
@@ -275,9 +273,9 @@ def order(self, order):
275273
raise ValueError("Order must be either 'RANDOM' or 'ALPHABETICAL'")
276274

277275
self._order = order
278-
self._reorder_images()
276+
self._reorder_slides()
279277

280-
def _reorder_images(self):
278+
def _reorder_slides(self):
281279
if self.order == PlayBackOrder.ALPHABETICAL:
282280
self._file_list = sorted(self._file_list)
283281
elif self.order == PlayBackOrder.RANDOM:
@@ -335,38 +333,38 @@ def update(self):
335333
# pylint: disable=too-many-branches
336334
def advance(self):
337335
"""Displays the next image. Returns True when a new image was displayed, False otherwise."""
338-
if self._image_file:
336+
if self._slide_file:
339337
self._fade_down()
340338
self._group.pop()
341-
self._image_file.close()
342-
self._image_file = None
339+
self._slide_file.close()
340+
self._slide_file = None
343341

344-
self._current_image += self.direction
342+
self._current_slide_index += self.direction
345343

346-
# Try and load an OnDiskBitmap until a valid file is found or we run out of options. This
344+
# Try to load slides until a valid file is found or we run out of options. This
347345
# loop stops because we either set odb or reduce the length of _file_list.
348346
odb = None
349347
while not odb and self._file_list:
350-
if 0 <= self._current_image < len(self._file_list):
348+
if 0 <= self._current_slide_index < len(self._file_list):
351349
pass
352350
elif not self.loop:
353351
return False
354352
else:
355-
image_count = len(self._file_list)
356-
if self._current_image < 0:
357-
self._current_image += image_count
358-
elif self._current_image >= image_count:
359-
self._current_image -= image_count
360-
self._reorder_images()
361-
362-
image_name = self._file_list[self._current_image]
363-
self._image_file = open(image_name, "rb")
353+
slide_count = len(self._file_list)
354+
if self._current_slide_index < 0:
355+
self._current_slide_index += slide_count
356+
elif self._current_slide_index >= slide_count:
357+
self._current_slide_index -= slide_count
358+
self._reorder_slides()
359+
360+
image_name = self._file_list[self._current_slide_index]
361+
self._slide_file = open(image_name, "rb")
364362
try:
365-
odb = displayio.OnDiskBitmap(self._image_file)
363+
odb = displayio.OnDiskBitmap(self._slide_file)
366364
except ValueError:
367-
self._image_file.close()
368-
self._image_file = None
369-
del self._file_list[self._current_image]
365+
self._slide_file.close()
366+
self._slide_file = None
367+
del self._file_list[self._current_slide_index]
370368

371369
if not odb:
372370
raise RuntimeError("No valid images")
@@ -385,13 +383,9 @@ def advance(self):
385383
else:
386384
self._group.y = 0
387385

388-
try:
389-
sprite = self._sprite_class(odb, pixel_shader=displayio.ColorConverter())
390-
except TypeError:
391-
sprite = self._sprite_class(
392-
odb, pixel_shader=displayio.ColorConverter(), position=(0, 0)
393-
)
394-
self._group.append(sprite)
386+
image_tilegrid = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter())
387+
388+
self._group.append(image_tilegrid)
395389

396390
if hasattr(self._display, "refresh"):
397391
self._display.refresh()

examples/slideshow_alignment_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
slideshow.v_align = aligns[i][0]
4040
i += 1
4141

42-
prev_img = slideshow.current_image_name
42+
prev_img = slideshow.current_slide_name
4343
while slideshow.update():
44-
cur_img = slideshow.current_image_name
44+
cur_img = slideshow.current_slide_name
4545
if prev_img != cur_img:
4646
slideshow.h_align = aligns[i][1]
4747
slideshow.v_align = aligns[i][0]

0 commit comments

Comments
 (0)