Skip to content

Commit 0907d10

Browse files
committed
check for text slide json files in the folder. add sample text slide
1 parent 4f8eba6 commit 0907d10

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

adafruit_slideshow.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import os
4545
import random
4646
import displayio
47+
import json
4748

4849
__version__ = "0.0.0-auto.0"
4950
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Slideshow.git"
@@ -190,6 +191,15 @@ def __init__(
190191
h_align=HorizontalAlignment.LEFT,
191192
v_align=VerticalAlignment.TOP,
192193
):
194+
def _check_json_file(file):
195+
with open(file) as f:
196+
try:
197+
json_data = json.loads(f.read())
198+
if "text" in json_data:
199+
return True
200+
except ValueError:
201+
return False
202+
return False
193203
self.loop = loop
194204
"""Specifies whether to loop through the images continuously or play through the list once.
195205
``True`` will continue to loop, ``False`` will play only once."""
@@ -214,7 +224,7 @@ def __init__(
214224
self._file_list = [
215225
folder + "/" + f
216226
for f in os.listdir(folder)
217-
if (f.endswith(".bmp") and not f.startswith("."))
227+
if ((f.endswith(".bmp") or _check_json_file(folder + "/" + f)) and not f.startswith("."))
218228
]
219229

220230
self._order = None
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"text": "Sample Text\nSlideshow",
3+
"h_alignment": "CENTER",
4+
"v_alignment": "CENTER",
5+
"color": "0x0000FF",
6+
"background_color": "0xFF00FF"
7+
}

0 commit comments

Comments
 (0)