adafruit_pyportal
¶
A port of the PyPortal library intended to run on Blinka in CPython.
Author(s): Melissa LeBlanc-Williams
Implementation Notes¶
Software and Dependencies:
Adafruit Blinka for supported boards: https://github.com/adafruit/Adafruit_Blinka/releases
- class adafruit_pyportal.PyPortal(*, url=None, headers=None, json_path=None, regexp_path=None, convert_image=True, default_bg=0, status_neopixel=None, text_font=<fontio.BuiltinFont object>, text_position=None, text_color=8421504, text_wrap=False, text_maxlen=0, text_transform=None, text_scale=1, json_transform=None, image_json_path=None, image_resize=None, image_position=None, image_dim_json_path=None, caption_text=None, caption_font=None, caption_position=None, caption_color=8421504, image_url_path=None, success_callback=None, esp=None, external_spi=None, debug=False, display=None, touchscreen=None, secrets=None)¶
Class representing the Adafruit PyPortal.
- Parameters
url – The URL of your data source. Defaults to
None
.headers – The headers for authentication, typically used by Azure API’s.
json_path – The list of json traversal to get data out of. Can be list of lists for multiple data points. Defaults to
None
to not use json.regexp_path – The list of regexp strings to get data out (use a single regexp group). Can be list of regexps for multiple data points. Defaults to
None
to not use regexp.convert_image – Determine whether or not to use the AdafruitIO image converter service. Set as False if your image is already resized. Defaults to True.
default_bg – The path to your default background image file or a hex color. Defaults to 0x000000.
status_neopixel – The pin for the status NeoPixel. Use
board.NEOPIXEL
for the on-board NeoPixel. Defaults toNone
, not the status LEDtext_font (str) – The path to your font file for your data text display.
text_position – The position of your extracted text on the display in an (x, y) tuple. Can be a list of tuples for when there’s a list of json_paths, for example
text_color – The color of the text, in 0xRRGGBB format. Can be a list of colors for when there’s multiple texts. Defaults to
None
.text_wrap – Whether or not to wrap text (for long text data chunks). Defaults to
False
, no wrapping.text_maxlen – The max length of the text for text wrapping. Defaults to 0.
text_transform – A function that will be called on the text before display
text_scale (int) – The factor to scale the default size of the text by
json_transform – A function or a list of functions to call with the parsed JSON. Changes and additions are permitted for the
dict
object.image_json_path – The JSON traversal path for a background image to display. Defaults to
None
.image_resize – What size to resize the image we got from the json_path, make this a tuple of the width and height you want. Defaults to
None
.image_position – The position of the image on the display as an (x, y) tuple. Defaults to
None
.image_dim_json_path – The JSON traversal path for the original dimensions of image tuple. Used with fetch(). Defaults to
None
.success_callback – A function we’ll call if you like, when we fetch data successfully. Defaults to
None
.caption_text (str) – The text of your caption, a fixed text not changed by the data we get. Defaults to
None
.caption_font (str) – The path to the font file for your caption. Defaults to
None
.caption_position – The position of your caption on the display as an (x, y) tuple. Defaults to
None
.caption_color – The color of your caption. Must be a hex value, e.g.
0x808000
.image_url_path – The HTTP traversal path for a background image to display. Defaults to
None
.esp – A passed ESP32 object, Can be used in cases where the ESP32 chip needs to be used before calling the pyportal class. Defaults to
None
.external_spi (busio.SPI) – A previously declared spi object. Defaults to
None
.debug – Turn on debug print outs. Defaults to False.
display – The displayio display object to use
touchscreen – The touchscreen object to use. Usually STMPE610 or FocalTouch.
secrets – The secrets object to use. If not supplied we will attempt to import.
- fetch(refresh_url=None, timeout=10)¶
Fetch data from the url we initialized with, perfom any parsing, and display text or graphics. This function does pretty much everything Optionally update the URL
A caption. Requires setting
caption_font
in init!- Parameters
caption_text – The text of the caption.
caption_position – The position of the caption text.
caption_color – The color of your caption text. Must be a hex value, e.g.
0x808000
.