43
43
import time
44
44
import os
45
45
import random
46
- import displayio
47
46
import json
47
+ import displayio
48
+
49
+
48
50
try :
49
51
from adafruit_display_text import bitmap_label
50
52
import terminalio
53
+
51
54
TEXT_SLIDES_ENABLED = True
52
55
except ImportError :
53
56
TEXT_SLIDES_ENABLED = False
@@ -199,14 +202,15 @@ def __init__(
199
202
):
200
203
def _check_json_file (file ):
201
204
if TEXT_SLIDES_ENABLED :
202
- with open (file ) as f :
205
+ with open (file ) as _file_obj :
203
206
try :
204
- json_data = json .loads (f .read ())
207
+ json_data = json .loads (_file_obj .read ())
205
208
if "text" in json_data :
206
209
return True
207
210
except ValueError :
208
211
return False
209
212
return False
213
+
210
214
self .loop = loop
211
215
"""Specifies whether to loop through the slides continuously or play through the list once.
212
216
``True`` will continue to loop, ``False`` will play only once."""
@@ -231,7 +235,10 @@ def _check_json_file(file):
231
235
self ._file_list = [
232
236
folder + "/" + f
233
237
for f in os .listdir (folder )
234
- if ((f .endswith (".bmp" ) or _check_json_file (folder + "/" + f )) and not f .startswith ("." ))
238
+ if (
239
+ (f .endswith (".bmp" ) or _check_json_file (folder + "/" + f ))
240
+ and not f .startswith ("." )
241
+ )
235
242
]
236
243
237
244
self ._order = None
@@ -336,7 +343,9 @@ def _create_label(self, file):
336
343
if "scale" in json_data :
337
344
_scale = int (json_data ["scale" ])
338
345
339
- label = bitmap_label .Label (terminalio .FONT , text = json_data ['text' ], scale = _scale )
346
+ label = bitmap_label .Label (
347
+ terminalio .FONT , text = json_data ["text" ], scale = _scale
348
+ )
340
349
if "h_align" not in json_data or json_data ["h_align" ] == "LEFT" :
341
350
x_anchor_point = 0.0
342
351
x_anchored_position = 0
@@ -375,15 +384,14 @@ def _create_label(self, file):
375
384
label .anchored_position = (x_anchored_position , y_anchored_position )
376
385
return label
377
386
378
-
379
387
def update (self ):
380
388
"""Updates the slideshow to the next image."""
381
389
now = time .monotonic ()
382
390
if not self .auto_advance or now - self ._img_start < self .dwell :
383
391
return True
384
392
return self .advance ()
385
393
386
- # pylint: disable=too-many-branches
394
+ # pylint: disable=too-many-branches, too-many-statements
387
395
def advance (self ):
388
396
"""Displays the next image. Returns True when a new image was displayed, False otherwise."""
389
397
if self ._slide_file :
@@ -441,7 +449,9 @@ def advance(self):
441
449
else :
442
450
self ._group .y = 0
443
451
444
- image_tilegrid = displayio .TileGrid (odb , pixel_shader = displayio .ColorConverter ())
452
+ image_tilegrid = displayio .TileGrid (
453
+ odb , pixel_shader = displayio .ColorConverter ()
454
+ )
445
455
446
456
self ._group .append (image_tilegrid )
447
457
if lbl :
0 commit comments