From 0907d10e39122dee0af7ef122c8282aef5cc6385 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Nov 2020 19:14:00 -0600 Subject: [PATCH 01/12] check for text slide json files in the folder. add sample text slide --- adafruit_slideshow.py | 12 +++++++++++- examples/images/sample_text_slide.json | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 examples/images/sample_text_slide.json diff --git a/adafruit_slideshow.py b/adafruit_slideshow.py index d7fcdb8..2967d32 100755 --- a/adafruit_slideshow.py +++ b/adafruit_slideshow.py @@ -44,6 +44,7 @@ import os import random import displayio +import json __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Slideshow.git" @@ -190,6 +191,15 @@ def __init__( h_align=HorizontalAlignment.LEFT, v_align=VerticalAlignment.TOP, ): + def _check_json_file(file): + with open(file) as f: + try: + json_data = json.loads(f.read()) + if "text" in json_data: + return True + except ValueError: + return False + return False self.loop = loop """Specifies whether to loop through the images continuously or play through the list once. ``True`` will continue to loop, ``False`` will play only once.""" @@ -214,7 +224,7 @@ def __init__( self._file_list = [ folder + "/" + f for f in os.listdir(folder) - if (f.endswith(".bmp") and not f.startswith(".")) + if ((f.endswith(".bmp") or _check_json_file(folder + "/" + f)) and not f.startswith(".")) ] self._order = None diff --git a/examples/images/sample_text_slide.json b/examples/images/sample_text_slide.json new file mode 100644 index 0000000..1577494 --- /dev/null +++ b/examples/images/sample_text_slide.json @@ -0,0 +1,7 @@ +{ + "text": "Sample Text\nSlideshow", + "h_alignment": "CENTER", + "v_alignment": "CENTER", + "color": "0x0000FF", + "background_color": "0xFF00FF" +} \ No newline at end of file From 45d532940fd0ce2e2c0528bc4298f3dfeb575866 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Nov 2020 20:21:18 -0600 Subject: [PATCH 02/12] reword instances of 'image' to 'slide'. Remove backwards compatibility for Sprite --- adafruit_slideshow.py | 72 +++++++++++++--------------- examples/slideshow_alignment_test.py | 4 +- 2 files changed, 35 insertions(+), 41 deletions(-) diff --git a/adafruit_slideshow.py b/adafruit_slideshow.py index 2967d32..eb34b72 100755 --- a/adafruit_slideshow.py +++ b/adafruit_slideshow.py @@ -201,11 +201,11 @@ def _check_json_file(file): return False return False self.loop = loop - """Specifies whether to loop through the images continuously or play through the list once. + """Specifies whether to loop through the slides continuously or play through the list once. ``True`` will continue to loop, ``False`` will play only once.""" self.dwell = dwell - """The number of seconds each image displays, in seconds.""" + """The number of seconds each slide displays, in seconds.""" self.direction = direction """Specify the playback direction. Default is ``PlayBackDirection.FORWARD``. Can also be @@ -215,9 +215,9 @@ def _check_json_file(file): """Enable auto-advance based on dwell time. Set to ``False`` to manually control.""" self.fade_effect = fade_effect - """Whether to include the fade effect between images. ``True`` tells the code to fade the - backlight up and down between image display transitions. ``False`` maintains max - brightness on the backlight between image transitions.""" + """Whether to include the fade effect between slides. ``True`` tells the code to fade the + backlight up and down between slide display transitions. ``False`` maintains max + brightness on the backlight between slide transitions.""" # Load the image names before setting order so they can be reordered. self._img_start = None @@ -236,11 +236,9 @@ def _check_json_file(file): self._h_align = h_align self._v_align = v_align - self._current_image = -1 - self._image_file = None + self._current_slide_index = -1 + self._slide_file = None self._brightness = 0.5 - # 4.0.0 Beta 2 replaces Sprite with TileGrid so use either. - self._sprite_class = getattr(displayio, "Sprite", displayio.TileGrid) # Setup the display self._group = displayio.Group() @@ -259,9 +257,9 @@ def _check_json_file(file): self.advance() @property - def current_image_name(self): + def current_slide_name(self): """Returns the current image name.""" - return self._file_list[self._current_image] + return self._file_list[self._current_slide_index] @property def order(self): @@ -275,9 +273,9 @@ def order(self, order): raise ValueError("Order must be either 'RANDOM' or 'ALPHABETICAL'") self._order = order - self._reorder_images() + self._reorder_slides() - def _reorder_images(self): + def _reorder_slides(self): if self.order == PlayBackOrder.ALPHABETICAL: self._file_list = sorted(self._file_list) elif self.order == PlayBackOrder.RANDOM: @@ -335,38 +333,38 @@ def update(self): # pylint: disable=too-many-branches def advance(self): """Displays the next image. Returns True when a new image was displayed, False otherwise.""" - if self._image_file: + if self._slide_file: self._fade_down() self._group.pop() - self._image_file.close() - self._image_file = None + self._slide_file.close() + self._slide_file = None - self._current_image += self.direction + self._current_slide_index += self.direction - # Try and load an OnDiskBitmap until a valid file is found or we run out of options. This + # Try to load slides until a valid file is found or we run out of options. This # loop stops because we either set odb or reduce the length of _file_list. odb = None while not odb and self._file_list: - if 0 <= self._current_image < len(self._file_list): + if 0 <= self._current_slide_index < len(self._file_list): pass elif not self.loop: return False else: - image_count = len(self._file_list) - if self._current_image < 0: - self._current_image += image_count - elif self._current_image >= image_count: - self._current_image -= image_count - self._reorder_images() - - image_name = self._file_list[self._current_image] - self._image_file = open(image_name, "rb") + slide_count = len(self._file_list) + if self._current_slide_index < 0: + self._current_slide_index += slide_count + elif self._current_slide_index >= slide_count: + self._current_slide_index -= slide_count + self._reorder_slides() + + image_name = self._file_list[self._current_slide_index] + self._slide_file = open(image_name, "rb") try: - odb = displayio.OnDiskBitmap(self._image_file) + odb = displayio.OnDiskBitmap(self._slide_file) except ValueError: - self._image_file.close() - self._image_file = None - del self._file_list[self._current_image] + self._slide_file.close() + self._slide_file = None + del self._file_list[self._current_slide_index] if not odb: raise RuntimeError("No valid images") @@ -385,13 +383,9 @@ def advance(self): else: self._group.y = 0 - try: - sprite = self._sprite_class(odb, pixel_shader=displayio.ColorConverter()) - except TypeError: - sprite = self._sprite_class( - odb, pixel_shader=displayio.ColorConverter(), position=(0, 0) - ) - self._group.append(sprite) + image_tilegrid = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter()) + + self._group.append(image_tilegrid) if hasattr(self._display, "refresh"): self._display.refresh() diff --git a/examples/slideshow_alignment_test.py b/examples/slideshow_alignment_test.py index 387d77f..5a4efe0 100644 --- a/examples/slideshow_alignment_test.py +++ b/examples/slideshow_alignment_test.py @@ -39,9 +39,9 @@ slideshow.v_align = aligns[i][0] i += 1 -prev_img = slideshow.current_image_name +prev_img = slideshow.current_slide_name while slideshow.update(): - cur_img = slideshow.current_image_name + cur_img = slideshow.current_slide_name if prev_img != cur_img: slideshow.h_align = aligns[i][1] slideshow.v_align = aligns[i][0] From dd7617b77a8bc212d97fba22bf0eff84159d73e7 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Nov 2020 21:18:23 -0600 Subject: [PATCH 03/12] \o/ basics of the text slide working --- adafruit_slideshow.py | 118 ++++++++++++++++++++++++++++++------------ 1 file changed, 84 insertions(+), 34 deletions(-) diff --git a/adafruit_slideshow.py b/adafruit_slideshow.py index eb34b72..05cc4d5 100755 --- a/adafruit_slideshow.py +++ b/adafruit_slideshow.py @@ -45,6 +45,12 @@ import random import displayio import json +try: + from adafruit_display_text import bitmap_label + import terminalio + TEXT_SLIDES_ENABLED = True +except ImportError: + TEXT_SLIDES_ENABLED = False __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Slideshow.git" @@ -192,13 +198,14 @@ def __init__( v_align=VerticalAlignment.TOP, ): def _check_json_file(file): - with open(file) as f: - try: - json_data = json.loads(f.read()) - if "text" in json_data: - return True - except ValueError: - return False + if TEXT_SLIDES_ENABLED: + with open(file) as f: + try: + json_data = json.loads(f.read()) + if "text" in json_data: + return True + except ValueError: + return False return False self.loop = loop """Specifies whether to loop through the slides continuously or play through the list once. @@ -323,6 +330,42 @@ def _fade_down(self): self._set_backlight(self.brightness * i / steps) time.sleep(0.01) + def _create_label(self, file): + json_data = json.loads(file.read()) + label = bitmap_label.Label(terminalio.FONT, text=json_data['text']) + if "h_align" not in json_data or json_data["h_align"] == "LEFT": + x_anchor_point = 0.0 + x_anchored_position = 0 + elif json_data["h_align"] == "CENTER": + x_anchor_point = 0.5 + x_anchored_position = self._display.width // 2 + elif json_data["h_align"] == "RIGHT": + x_anchor_point = 1.0 + x_anchored_position = self._display.width - 1 + else: + # wrong value for align + x_anchor_point = 0.0 + x_anchored_position = 0 + + if "v_align" not in json_data or json_data["v_align"] == "TOP": + y_anchor_point = 0.0 + y_anchored_position = 0 + elif json_data["v_align"] == "CENTER": + y_anchor_point = 0.5 + y_anchored_position = self._display.height // 2 + elif json_data["v_align"] == "BOTTOM": + y_anchor_point = 1.0 + y_anchored_position = self._display.height - 1 + else: + # wrong value for align + y_anchor_point = 0.0 + y_anchored_position = 0 + + label.anchor_point = (x_anchor_point, y_anchor_point) + label.anchored_position = (x_anchored_position, y_anchored_position) + return label + + def update(self): """Updates the slideshow to the next image.""" now = time.monotonic() @@ -344,7 +387,8 @@ def advance(self): # Try to load slides until a valid file is found or we run out of options. This # loop stops because we either set odb or reduce the length of _file_list. odb = None - while not odb and self._file_list: + lbl = None + while not odb and not lbl and self._file_list: if 0 <= self._current_slide_index < len(self._file_list): pass elif not self.loop: @@ -357,35 +401,41 @@ def advance(self): self._current_slide_index -= slide_count self._reorder_slides() - image_name = self._file_list[self._current_slide_index] - self._slide_file = open(image_name, "rb") - try: - odb = displayio.OnDiskBitmap(self._slide_file) - except ValueError: - self._slide_file.close() - self._slide_file = None - del self._file_list[self._current_slide_index] - - if not odb: - raise RuntimeError("No valid images") - - if self._h_align == HorizontalAlignment.RIGHT: - self._group.x = self._display.width - odb.width - elif self._h_align == HorizontalAlignment.CENTER: - self._group.x = round(self._display.width / 2 - odb.width / 2) - else: - self._group.x = 0 + file_name = self._file_list[self._current_slide_index] + self._slide_file = open(file_name, "rb") + if file_name.endswith(".bmp"): + try: + odb = displayio.OnDiskBitmap(self._slide_file) + except ValueError: + self._slide_file.close() + self._slide_file = None + del self._file_list[self._current_slide_index] + elif file_name.endswith(".json"): + lbl = self._create_label(self._slide_file) + + if not odb and not lbl: + raise RuntimeError("No valid images or text json files") + + if odb: + if self._h_align == HorizontalAlignment.RIGHT: + self._group.x = self._display.width - odb.width + elif self._h_align == HorizontalAlignment.CENTER: + self._group.x = round(self._display.width / 2 - odb.width / 2) + else: + self._group.x = 0 - if self._v_align == VerticalAlignment.BOTTOM: - self._group.y = self._display.height - odb.height - elif self._v_align == VerticalAlignment.CENTER: - self._group.y = round(self._display.height / 2 - odb.height / 2) - else: - self._group.y = 0 + if self._v_align == VerticalAlignment.BOTTOM: + self._group.y = self._display.height - odb.height + elif self._v_align == VerticalAlignment.CENTER: + self._group.y = round(self._display.height / 2 - odb.height / 2) + else: + self._group.y = 0 - image_tilegrid = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter()) + image_tilegrid = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter()) - self._group.append(image_tilegrid) + self._group.append(image_tilegrid) + if lbl: + self._group.append(lbl) if hasattr(self._display, "refresh"): self._display.refresh() From a47aec74450dce0dec3044f2543a662c55d289ad Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Nov 2020 21:30:29 -0600 Subject: [PATCH 04/12] add scale. fix algin property name in ex json. implement color and background_color --- adafruit_slideshow.py | 12 +++++++++++- examples/images/sample_text_slide.json | 7 ++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/adafruit_slideshow.py b/adafruit_slideshow.py index 05cc4d5..a0741c7 100755 --- a/adafruit_slideshow.py +++ b/adafruit_slideshow.py @@ -332,7 +332,11 @@ def _fade_down(self): def _create_label(self, file): json_data = json.loads(file.read()) - label = bitmap_label.Label(terminalio.FONT, text=json_data['text']) + _scale = 1 + if "scale" in json_data: + _scale = int(json_data["scale"]) + + label = bitmap_label.Label(terminalio.FONT, text=json_data['text'], scale=_scale) if "h_align" not in json_data or json_data["h_align"] == "LEFT": x_anchor_point = 0.0 x_anchored_position = 0 @@ -361,6 +365,12 @@ def _create_label(self, file): y_anchor_point = 0.0 y_anchored_position = 0 + if "background_color" in json_data: + label.background_color = int(json_data["background_color"], 16) + + if "color" in json_data: + label.color = int(json_data["color"], 16) + label.anchor_point = (x_anchor_point, y_anchor_point) label.anchored_position = (x_anchored_position, y_anchored_position) return label diff --git a/examples/images/sample_text_slide.json b/examples/images/sample_text_slide.json index 1577494..618c203 100644 --- a/examples/images/sample_text_slide.json +++ b/examples/images/sample_text_slide.json @@ -1,7 +1,8 @@ { "text": "Sample Text\nSlideshow", - "h_alignment": "CENTER", - "v_alignment": "CENTER", + "h_align": "CENTER", + "v_align": "CENTER", "color": "0x0000FF", - "background_color": "0xFF00FF" + "background_color": "0xFF00FF", + "scale": 2 } \ No newline at end of file From 6d825bfe402cf019d85e72ebd0329c19f1e61d3a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Nov 2020 21:33:15 -0600 Subject: [PATCH 05/12] black and pylint --- adafruit_slideshow.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/adafruit_slideshow.py b/adafruit_slideshow.py index a0741c7..6e88625 100755 --- a/adafruit_slideshow.py +++ b/adafruit_slideshow.py @@ -43,11 +43,14 @@ import time import os import random -import displayio import json +import displayio + + try: from adafruit_display_text import bitmap_label import terminalio + TEXT_SLIDES_ENABLED = True except ImportError: TEXT_SLIDES_ENABLED = False @@ -199,14 +202,15 @@ def __init__( ): def _check_json_file(file): if TEXT_SLIDES_ENABLED: - with open(file) as f: + with open(file) as _file_obj: try: - json_data = json.loads(f.read()) + json_data = json.loads(_file_obj.read()) if "text" in json_data: return True except ValueError: return False return False + self.loop = loop """Specifies whether to loop through the slides continuously or play through the list once. ``True`` will continue to loop, ``False`` will play only once.""" @@ -231,7 +235,10 @@ def _check_json_file(file): self._file_list = [ folder + "/" + f for f in os.listdir(folder) - if ((f.endswith(".bmp") or _check_json_file(folder + "/" + f)) and not f.startswith(".")) + if ( + (f.endswith(".bmp") or _check_json_file(folder + "/" + f)) + and not f.startswith(".") + ) ] self._order = None @@ -336,7 +343,9 @@ def _create_label(self, file): if "scale" in json_data: _scale = int(json_data["scale"]) - label = bitmap_label.Label(terminalio.FONT, text=json_data['text'], scale=_scale) + label = bitmap_label.Label( + terminalio.FONT, text=json_data["text"], scale=_scale + ) if "h_align" not in json_data or json_data["h_align"] == "LEFT": x_anchor_point = 0.0 x_anchored_position = 0 @@ -375,7 +384,6 @@ def _create_label(self, file): label.anchored_position = (x_anchored_position, y_anchored_position) return label - def update(self): """Updates the slideshow to the next image.""" now = time.monotonic() @@ -383,7 +391,7 @@ def update(self): return True return self.advance() - # pylint: disable=too-many-branches + # pylint: disable=too-many-branches, too-many-statements def advance(self): """Displays the next image. Returns True when a new image was displayed, False otherwise.""" if self._slide_file: @@ -441,7 +449,9 @@ def advance(self): else: self._group.y = 0 - image_tilegrid = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter()) + image_tilegrid = displayio.TileGrid( + odb, pixel_shader=displayio.ColorConverter() + ) self._group.append(image_tilegrid) if lbl: From 99cb7708b68722ceddc0b1606523a73ca62ae848 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Nov 2020 21:35:21 -0600 Subject: [PATCH 06/12] adding comment for create label function --- adafruit_slideshow.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adafruit_slideshow.py b/adafruit_slideshow.py index 6e88625..7392746 100755 --- a/adafruit_slideshow.py +++ b/adafruit_slideshow.py @@ -338,6 +338,10 @@ def _fade_down(self): time.sleep(0.01) def _create_label(self, file): + """Creates and returns a label from a file object that contains + valid valid json describing the text to use. + See: examples/sample_text_slide.json + """ json_data = json.loads(file.read()) _scale = 1 if "scale" in json_data: From ee236f33f3b0d008e2bd81c2197faabc8bfc9670 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 18 Nov 2020 17:57:34 -0600 Subject: [PATCH 07/12] ignore hidden files first. ignore non .json files. remove extra slash in _file_list items. Update simpletest --- adafruit_slideshow.py | 22 +++++++++++----------- examples/slideshow_simpletest.py | 13 +++++++++---- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/adafruit_slideshow.py b/adafruit_slideshow.py index 7392746..31f62a9 100755 --- a/adafruit_slideshow.py +++ b/adafruit_slideshow.py @@ -46,7 +46,6 @@ import json import displayio - try: from adafruit_display_text import bitmap_label import terminalio @@ -202,13 +201,14 @@ def __init__( ): def _check_json_file(file): if TEXT_SLIDES_ENABLED: - with open(file) as _file_obj: - try: - json_data = json.loads(_file_obj.read()) - if "text" in json_data: - return True - except ValueError: - return False + if file.endswith(".json"): + with open(file) as _file_obj: + try: + json_data = json.loads(_file_obj.read()) + if "text" in json_data: + return True + except ValueError: + return False return False self.loop = loop @@ -233,11 +233,11 @@ def _check_json_file(file): # Load the image names before setting order so they can be reordered. self._img_start = None self._file_list = [ - folder + "/" + f + folder + f for f in os.listdir(folder) if ( - (f.endswith(".bmp") or _check_json_file(folder + "/" + f)) - and not f.startswith(".") + not f.startswith(".") + and (f.endswith(".bmp") or _check_json_file(folder + f)) ) ] diff --git a/examples/slideshow_simpletest.py b/examples/slideshow_simpletest.py index 68798a1..068d0a5 100644 --- a/examples/slideshow_simpletest.py +++ b/examples/slideshow_simpletest.py @@ -1,14 +1,19 @@ +"""Basic demonstration script will create a slideshow +object that plays through once alphabetically.""" import board -import pulseio from adafruit_slideshow import PlayBackOrder, SlideShow +# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.) +# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.) +# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus +display = board.DISPLAY + # pylint: disable=no-member -# Create the slideshow object that plays through once alphabetically. slideshow = SlideShow( board.DISPLAY, - pulseio.PWMOut(board.TFT_BACKLIGHT), - folder="/", + None, + folder="/images/", loop=False, order=PlayBackOrder.ALPHABETICAL, ) From 43a604626fffbdf7e16f7d68352dd66fd1bd851c Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 18 Nov 2020 18:28:08 -0600 Subject: [PATCH 08/12] add warning about display_text optional text support --- adafruit_slideshow.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_slideshow.py b/adafruit_slideshow.py index 31f62a9..108393f 100755 --- a/adafruit_slideshow.py +++ b/adafruit_slideshow.py @@ -47,11 +47,14 @@ import displayio try: + # text slides are an optional feature and require + # adafruit_display_text from adafruit_display_text import bitmap_label import terminalio TEXT_SLIDES_ENABLED = True except ImportError: + print("Warning: adafruit_display_text not found. No support for text slides.") TEXT_SLIDES_ENABLED = False __version__ = "0.0.0-auto.0" From f989c6a813c094715d588dd74705ba39bdf6ddc8 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 18 Nov 2020 18:44:40 -0600 Subject: [PATCH 09/12] change example text color to black and white for MagTag --- examples/images/sample_text_slide.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/images/sample_text_slide.json b/examples/images/sample_text_slide.json index 618c203..5454a46 100644 --- a/examples/images/sample_text_slide.json +++ b/examples/images/sample_text_slide.json @@ -2,7 +2,7 @@ "text": "Sample Text\nSlideshow", "h_align": "CENTER", "v_align": "CENTER", - "color": "0x0000FF", - "background_color": "0xFF00FF", + "color": "0x000000", + "background_color": "0xFFFFFF", "scale": 2 } \ No newline at end of file From e9d4c675b90659bec3eee688f39d890abb644574 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 18 Nov 2020 18:56:54 -0600 Subject: [PATCH 10/12] longer dwell in the simpletest. better for MagTag --- examples/slideshow_simpletest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/slideshow_simpletest.py b/examples/slideshow_simpletest.py index 068d0a5..d150399 100644 --- a/examples/slideshow_simpletest.py +++ b/examples/slideshow_simpletest.py @@ -16,6 +16,7 @@ folder="/images/", loop=False, order=PlayBackOrder.ALPHABETICAL, + dwell=10, ) while slideshow.update(): From 188b23931494e8c9365b02f52eb72951185de332 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 18 Nov 2020 19:38:10 -0600 Subject: [PATCH 11/12] adding support for custom fonts --- adafruit_slideshow.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/adafruit_slideshow.py b/adafruit_slideshow.py index 108393f..107559f 100755 --- a/adafruit_slideshow.py +++ b/adafruit_slideshow.py @@ -47,8 +47,7 @@ import displayio try: - # text slides are an optional feature and require - # adafruit_display_text + # text slides are an optional feature and require adafruit_display_text from adafruit_display_text import bitmap_label import terminalio @@ -57,6 +56,15 @@ print("Warning: adafruit_display_text not found. No support for text slides.") TEXT_SLIDES_ENABLED = False +try: + # custom fonts are an optional feature and require adafruit_bitmap_font + from adafruit_bitmap_font import bitmap_font + + CUSTOM_FONTS = True +except ImportError: + print("Warning: adafruit_bitmap_font not found. No support for custom fonts.") + CUSTOM_FONTS = False + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Slideshow.git" @@ -341,6 +349,7 @@ def _fade_down(self): time.sleep(0.01) def _create_label(self, file): + # pylint: disable=too-many-branches """Creates and returns a label from a file object that contains valid valid json describing the text to use. See: examples/sample_text_slide.json @@ -350,9 +359,15 @@ def _create_label(self, file): if "scale" in json_data: _scale = int(json_data["scale"]) - label = bitmap_label.Label( - terminalio.FONT, text=json_data["text"], scale=_scale - ) + if CUSTOM_FONTS: + if "font" in json_data: + _font = bitmap_font.load_font(json_data["font"]) + else: + _font = terminalio.FONT + else: + _font = terminalio.FONT + + label = bitmap_label.Label(_font, text=json_data["text"], scale=_scale) if "h_align" not in json_data or json_data["h_align"] == "LEFT": x_anchor_point = 0.0 x_anchored_position = 0 From 48c8e8a8a8e8cd4313a98c86f05a33a1b5b6551d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 21 Nov 2020 18:37:12 -0600 Subject: [PATCH 12/12] use some gray colors --- examples/images/sample_text_slide.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/images/sample_text_slide.json b/examples/images/sample_text_slide.json index 5454a46..40191f5 100644 --- a/examples/images/sample_text_slide.json +++ b/examples/images/sample_text_slide.json @@ -2,7 +2,7 @@ "text": "Sample Text\nSlideshow", "h_align": "CENTER", "v_align": "CENTER", - "color": "0x000000", - "background_color": "0xFFFFFF", + "color": "0xFFFFFF", + "background_color": "0x666666", "scale": 2 } \ No newline at end of file