Skip to content
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

text_wrap passed to wrap_text_to_lines instead of text_maxlen #119

Open
dgriswo opened this issue Jan 12, 2022 · 1 comment
Open

text_wrap passed to wrap_text_to_lines instead of text_maxlen #119

dgriswo opened this issue Jan 12, 2022 · 1 comment

Comments

@dgriswo
Copy link

dgriswo commented Jan 12, 2022

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
)
@makermelissa
Copy link
Collaborator

Yeah, I think this was an attempt to maintain backwards compatibility with existing code, but it's totally possibly it wasn't quite done correctly.

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

No branches or pull requests

2 participants