Skip to content

Allow text slides #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 23, 2020
Merged

Allow text slides #27

merged 13 commits into from
Nov 23, 2020

Conversation

FoamyGuy
Copy link
Contributor

With these changes we can now use a file json file containing data like:

{
  "text": "Sample Text\nSlideshow",
  "h_align": "CENTER",
  "v_align": "CENTER",
  "color": "0x0000FF",
  "background_color": "0xFF00FF",
  "scale": 2
}

It will create a label to show configured as specified by the json. text is the only required property. Any json files that do not contain text property are ignored. h_align and v_align properties from the json supersede the ones set on the SlideShow.

I have renamed many things that referred to "image" to now use "slide" instead since it can hold different types of things now.

The sample json above is included in examples/images/

@FoamyGuy
Copy link
Contributor Author

This probably closes #23 in my mind. This is a little more narrow than the issue mentions, but does fulfill the original goal of text and images mixed.

I have a few other things in mind I'd like to implement still:

  • bitmap_font bdf file selected from the json data
  • allow template variables to get filled in the text string

But I was interested to see if there is any feedback on the idea generally or what I have so far.

@tannewt tannewt requested a review from a team November 18, 2020 18:53
@ladyada
Copy link
Member

ladyada commented Nov 18, 2020

@kattni please test

@kattni
Copy link
Contributor

kattni commented Nov 18, 2020

@FoamyGuy Hey! Thanks for adding this. I tried testing it on a PyBadge, and it's not working. I had to modify the simpletest to not have the BACKLIGHT line in it to make it work, and copied your example file to /, but it's still returning:

Traceback (most recent call last):
  File "code.py", line 12, in <module>
  File "/lib/adafruit_slideshow.py", line 271, in __init__
  File "/lib/adafruit_slideshow.py", line 439, in advance
RuntimeError: No valid images or text json files

My example code is:

import board
from adafruit_slideshow import PlayBackOrder, SlideShow

# pylint: disable=no-member

# Create the slideshow object that plays through once alphabetically.
slideshow = SlideShow(
    board.DISPLAY,
    folder="/",
    loop=False,
    order=PlayBackOrder.ALPHABETICAL,
)

while slideshow.update():
    pass

My CIRCUITPY drive:
Screen Shot 2020-11-18 at 15 17 35

@kattni
Copy link
Contributor

kattni commented Nov 18, 2020

I was informed that it requires adafruit_display_text. There was no indicator of this in the above error - probably worth making it more obvious. I added that library and am now getting a new error.

Traceback (most recent call last):
  File "code.py", line 11, in <module>
  File "/lib/adafruit_slideshow.py", line 237, in __init__
  File "/lib/adafruit_slideshow.py", line 239, in <listcomp>
  File "/lib/adafruit_slideshow.py", line 205, in _check_json_file
OSError: [Errno 2] No such file/directory: '//.fseventsd'

@FoamyGuy
Copy link
Contributor Author

I think there may be some issue with the way it's trying to ignore hidden files whose name start with a dot.

I will be working on this some more later tonight. I should be able to resolve the above error. I will also test it out on some MagTag, PyBadge as well and make any tweaks needed to get it working, so far all of my testing was on PyPortal.

I'm also hoping I can get the last two features mentioned implemented tonight, but unsure if I'll make it. I will make a comment here with the new status after my commits tonight.

@FoamyGuy
Copy link
Contributor Author

The latest commits fix contain the following:

  • correctly ignore hidden files
  • correctly ignore non-json files
  • removed an extra slash in the filepaths
  • make the simpletest look in the images folder
  • change the example text color to black and white for MagTag
  • add warning to code and printout about optional support for text slides with adafruit_display_text requirement
  • longer dwell time in the simpletest, better for MagTag

I tested this version successfully on PyBadge and MagTag. Here is how the example text json looks on the MagTag

image

@FoamyGuy
Copy link
Contributor Author

The new commit adds support for custom fonts by declaring them in the json file like this one:

{
  "text": "Sample Text\nSlideshow",
  "h_align": "CENTER",
  "v_align": "CENTER",
  "color": "0x000000",
  "background_color": "0xFFFFFF",
  "scale": 2,
  "font": "Helvetica-Bold-16.bdf"
}

custom_font_slideshow

I did look into adding template variables but I think it's maybe something for the future. It needs some thought about how to pass the variables to the slideshow object.

I think this is ready to go now.

One thing to note for @kattni or whoever tests is the simpletest example is now looking in /images/ instead of the root /. Paste the text json and any images you want to use into /images/ on the device.

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented Nov 22, 2020

The new commit tweaks the colors in the example slide to make use of grayscale on the MagTag.
image

Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested successfully on MagTag. Thanks for adding this feature!

@kattni kattni merged commit 5f5836d into adafruit:master Nov 23, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 24, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_Fingerprint to 2.1.1 from 2.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Fingerprint#25 from jerryneedell/jerryn_r503_save

Updating https://github.com/adafruit/Adafruit_CircuitPython_LIS3DH to 5.1.6 from 5.1.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_LIS3DH#65 from caternuson/iss64

Updating https://github.com/adafruit/Adafruit_CircuitPython_RPLIDAR to 1.1.3 from 1.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_RPLIDAR#11 from kevin-balkoski-enview/typo-fixes

Updating https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO to 5.0.2 from 5.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_AdafruitIO#55 from DougBurke/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font to 1.2.3 from 1.2.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Bitmap_Font#30 from FoamyGuy/magtag_example

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes to 2.0.3 from 2.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Shapes#28 from FoamyGuy/add_magtag_example

Updating https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal to 1.9.5 from 1.9.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_MatrixPortal#52 from makermelissa/master
  > Merge pull request adafruit/Adafruit_CircuitPython_MatrixPortal#48 from slootsky/feature/get_local_time_ignores_location_parameter

Updating https://github.com/adafruit/Adafruit_CircuitPython_Slideshow to 1.5.0 from 1.4.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Slideshow#27 from FoamyGuy/text_slides
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants