@@ -201,11 +201,11 @@ def _check_json_file(file):
201
201
return False
202
202
return False
203
203
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.
205
205
``True`` will continue to loop, ``False`` will play only once."""
206
206
207
207
self .dwell = dwell
208
- """The number of seconds each image displays, in seconds."""
208
+ """The number of seconds each slide displays, in seconds."""
209
209
210
210
self .direction = direction
211
211
"""Specify the playback direction. Default is ``PlayBackDirection.FORWARD``. Can also be
@@ -215,9 +215,9 @@ def _check_json_file(file):
215
215
"""Enable auto-advance based on dwell time. Set to ``False`` to manually control."""
216
216
217
217
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."""
221
221
222
222
# Load the image names before setting order so they can be reordered.
223
223
self ._img_start = None
@@ -236,11 +236,9 @@ def _check_json_file(file):
236
236
self ._h_align = h_align
237
237
self ._v_align = v_align
238
238
239
- self ._current_image = - 1
240
- self ._image_file = None
239
+ self ._current_slide_index = - 1
240
+ self ._slide_file = None
241
241
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 )
244
242
245
243
# Setup the display
246
244
self ._group = displayio .Group ()
@@ -259,9 +257,9 @@ def _check_json_file(file):
259
257
self .advance ()
260
258
261
259
@property
262
- def current_image_name (self ):
260
+ def current_slide_name (self ):
263
261
"""Returns the current image name."""
264
- return self ._file_list [self ._current_image ]
262
+ return self ._file_list [self ._current_slide_index ]
265
263
266
264
@property
267
265
def order (self ):
@@ -275,9 +273,9 @@ def order(self, order):
275
273
raise ValueError ("Order must be either 'RANDOM' or 'ALPHABETICAL'" )
276
274
277
275
self ._order = order
278
- self ._reorder_images ()
276
+ self ._reorder_slides ()
279
277
280
- def _reorder_images (self ):
278
+ def _reorder_slides (self ):
281
279
if self .order == PlayBackOrder .ALPHABETICAL :
282
280
self ._file_list = sorted (self ._file_list )
283
281
elif self .order == PlayBackOrder .RANDOM :
@@ -335,38 +333,38 @@ def update(self):
335
333
# pylint: disable=too-many-branches
336
334
def advance (self ):
337
335
"""Displays the next image. Returns True when a new image was displayed, False otherwise."""
338
- if self ._image_file :
336
+ if self ._slide_file :
339
337
self ._fade_down ()
340
338
self ._group .pop ()
341
- self ._image_file .close ()
342
- self ._image_file = None
339
+ self ._slide_file .close ()
340
+ self ._slide_file = None
343
341
344
- self ._current_image += self .direction
342
+ self ._current_slide_index += self .direction
345
343
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
347
345
# loop stops because we either set odb or reduce the length of _file_list.
348
346
odb = None
349
347
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 ):
351
349
pass
352
350
elif not self .loop :
353
351
return False
354
352
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" )
364
362
try :
365
- odb = displayio .OnDiskBitmap (self ._image_file )
363
+ odb = displayio .OnDiskBitmap (self ._slide_file )
366
364
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 ]
370
368
371
369
if not odb :
372
370
raise RuntimeError ("No valid images" )
@@ -385,13 +383,9 @@ def advance(self):
385
383
else :
386
384
self ._group .y = 0
387
385
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 )
395
389
396
390
if hasattr (self ._display , "refresh" ):
397
391
self ._display .refresh ()
0 commit comments