adafruit / adafruit/Adafruit_CircuitPython_PyPortal

text_wrap passed to wrap_text_to_lines instead of text_maxlen

Open
#119 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
46
Forks
56
PR merge metrics
No merged PRs in 30d

Description

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
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
Retrieving data...Headers:
Reply is OK!

original URL:
convert URL: https://io.adafruit.com/api/v2//integrations/image-formatter?x-aio-key=
Fetching stream from https://io.adafruit.com/api/v2//integrations/image-formatter?x-aio-key=
Reply is OK!

Saving data to /sd/cache.bmp
Read 41 bytes, 82657 remaining

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
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
)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in adafruit_pyportal/__init__.py at the constructor and fetch paths shown in the traceback, then follow the calls into adafruit_portalbase and adafruit_display_text.wrap_text_to_lines. Compare how text_maxlen and text_wrap are passed for list and boolean inputs. Done means the documented text_maxlen list with text_wrap=True no longer produces the reported TypeError or zero-step ValueError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.