Exemple #1
0
def parse_metadata(metadata):
    # print(metadata)
    line1_max_width = 35
    line1 = metadata['title']
    line1_formatted = "\n".join(wrap_text_to_lines(line1, line1_max_width))

    line2_max_width = 30
    line2 = metadata['album']
    line2_formatted = "\n".join(wrap_text_to_lines(line2, line2_max_width))
    line1_line_count = line1_formatted.count("\n") + 1
    if line1_line_count > 1:
        line2_formatted = "\n" + line2_formatted

    line3_max_width = 25
    line3 = metadata['artist']
    line3_formatted = "\n".join(wrap_text_to_lines(line3, line3_max_width))

    if line3 == line1 or line3 == line2:
        line3_formatted = ""

    display_data = {
        'line1': line1_formatted,
        'line2': line2_formatted,
        'line3': line3_formatted
    }

    return display_data
Exemple #2
0
    def wrap_nicely(string, max_chars):
        """A helper that will return a list of lines with word-break wrapping.

        :param str string: The text to be wrapped.
        :param int max_chars: The maximum number of characters on a line before wrapping.

        """
        return wrap_text_to_lines(string, max_chars)
"""
This example illustrates how to use the wrap_text_to_lines
helper function.
"""
import board
import terminalio
from adafruit_display_text import label, wrap_text_to_lines

# 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

text = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
        "sed do eiusmod tempor incididunt ut labore et dolore magna "
        "aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
        "ullamco laboris nisi ut aliquip ex ea commodo consequat.")
text = "\n".join(wrap_text_to_lines(text, 28))
text_area = label.Label(terminalio.FONT, text=text)
text_area.x = 10
text_area.y = 10
display.show(text_area)
while True:
    pass