Skip to content

text_wrap passed to wrap_text_to_lines instead of text_maxlen #119

Open
@dgriswo

Description

@dgriswo

It appears that the text_wrap value is being passed to the underlying library instead of the value of text_maxlen. When omitting text_maxlen and setting text_wrap as if it was maxlen, the library functions as expected.

I'm unsure if this is an undocumented change in behavior or a bug.

From the docs:

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.

sample code:

pyportal = PyPortal(
    url=DATA_SOURCE,
    json_path=(CARD_NAME, CARD_COST, CARD_TYPE, CARD_TEXT),
    status_neopixel=board.NEOPIXEL,
    text_position=((175, 10), (175, 20), (175, 30), (175, 60)),
    text_color=(0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF),
    text_maxlen=(24, 24, 24, 24),
    text_wrap=True,
    image_json_path=CARD_IMAGE,
    image_resize=(172, 240),
    image_position=(0, 0),
    debug=True
)

With text_maxlen as a list and text_wrap as boolean, a TypeError results

code.py output:
Init display
Init background
Init image path
Init SD Card
Init touchscreen
Init caption
Setting caption to None
Traceback (most recent call last):
  File "code.py", line 29, in <module>
  File "adafruit_pyportal/__init__.py", line 263, in __init__
TypeError: 'bool' object isn't subscriptable

Code done running.

setting text_wrap=(True, True, True, True), results in a ValueError:
Notice the "Wrapping text with length of True" before the trace.

code.py output:
Init display
Init background
Init image path
Init SD Card
Init touchscreen
Init caption
Setting caption to None
Init text area
Init text area
Init text area
Init text area
Connecting to AP <snip>
Retrieving data...Headers: <snip>
Reply is OK!
<snip>
original URL: <snip>
convert URL: https://io.adafruit.com/api/v2/<snip>/integrations/image-formatter?x-aio-key=<snip>
Fetching stream from https://io.adafruit.com/api/v2/<snip>/integrations/image-formatter?x-aio-key=<snip>
Reply is OK!
<snip>
Saving data to  /sd/cache.bmp
Read 41 bytes, 82657 remaining
<snip>
Created file of 82698 bytes in 6.7 seconds
Wrapping text with length of True
Traceback (most recent call last):
  File "code.py", line 38, in <module>
  File "adafruit_pyportal/__init__.py", line 355, in fetch
  File "adafruit_portalbase/__init__.py", line 442, in _fill_text_labels
  File "adafruit_portalbase/__init__.py", line 393, in _fetch_set_text
  File "adafruit_portalbase/__init__.py", line 238, in set_text
  File "adafruit_portalbase/__init__.py", line 137, in wrap_nicely
  File "adafruit_display_text/__init__.py", line 140, in wrap_text_to_lines
  File "adafruit_display_text/__init__.py", line 128, in chunks
ValueError: zero step

This code, although not matching the documentation, works as expected. text_maxlen is omitted and text_wrap is a list of integers, not boolean.

pyportal = PyPortal(
    url=DATA_SOURCE,
    json_path=(CARD_NAME, CARD_COST, CARD_TYPE, CARD_TEXT),
    status_neopixel=board.NEOPIXEL,
    text_position=((175, 10), (175, 20), (175, 30), (175, 60)),
    text_color=(0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF),
    text_wrap=(24, 24, 24, 24),
    image_json_path=CARD_IMAGE,
    image_resize=(172, 240),
    image_position=(0, 0),
    debug=True
)

Metadata

Metadata

Assignees

No one assigned

    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