Skip to content

label does not wrap text when set_text rather than fetch()'d #9

Closed
@ladyada

Description

@ladyada

text should be wrapped in this example 👍

import time
import random
from adafruit_magtag.magtag import MagTag

# Set up where we'll be fetching data from
DATA_SOURCE = "https://www.reddit.com/r/Showerthoughts/top.json?limit=5"

magtag = MagTag()
magtag.network.connect()

# thought in bold text, with text wrapping
magtag.add_text(
    text_font="Arial-Bold-12.bdf",
    text_wrap=33,
    text_maxlen=160,
    text_position=(10, 10),
    text_anchor_point=(0, 0),
    line_spacing=0.75,
)


timestamp = None
while True:
    if not timestamp or (time.monotonic() - timestamp) > 5:  # once every 60 seconds...
        try:
            print("Reading data")
            response = magtag.network.requests.get(DATA_SOURCE)
            value = response.json()
            thoughts = value["data"]["dist"]
            print("Thoughts", thoughts)
            randthought = random.randint(0, thoughts-1)
            thought = value["data"]["children"][randthought]["data"]["title"]
            author = value["data"]["children"][randthought]["data"]["author"]
            print("Random thought from", author, ":", thought)
            magtag.set_text(thought)
        except (ValueError, RuntimeError) as e:
            print("Some error occured, retrying! -", e)
        timestamp = time.monotonic()

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions