adafruit / adafruit/Adafruit_CircuitPython_PyPortal
PyPortal.set_caption() always adds a new caption with no way to remove older ones?
- Dominant language
- Python
- Stars
- 46
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to update an older PyPortal-based project, and running into a `set_caption` issue. It used to be that there was a single `label` for the caption, and its text was set during `PyPortal()` construction, and then could be updated later using `set_caption`.
Here is an example project [Daily UV Index PyPortal Display](https://learn.adafruit.com/pyportal-uv-index/code) that calls `pyportal.set_caption()` on every update, which is the same basic pattern that I've been using:
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/9f6d3ea8f8b16d12c6fd3b89cd7ce5bbf0c015ec/PyPortal_UV_Index/code.py#L100-L102
# Code with the bug
Today's implementation of `PyPortal.set_caption` *always* calls `PortalBase.add_text()`, and therefore it adds a new label every time:
https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/blob/de0b0082e3bca027aeab391d9d96bcb74068b7dd/adafruit_pyportal/__init__.py#L274-L296
Here's a link to the [add_text implementation](https://github.com/adafruit/Adafruit_CircuitPython_PortalBase/blob/b7252a4c2ed674396164a4aabac531b64a11f2eb/adafruit_portalbase/__init__.py#L155)
# Old Implementation
Looking into the source history, prior to #99, the caption label was created if needed, otherwise it was updated:
https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/blob/88358c0316fe0483b90f978ebcdf6836f82dd77d/adafruit_pyportal.py#L586-L618
This is the behavior I was used to, and is still how I'd expect it to work based on today's documentation
# Workaround
I think I can workaround this by ignoring the PyPortal caption, and just managing the label myself?
# Fix
I'm not sure how to approach fixing this. The interaction with PortalBase makes it a little complicated. I cloned the repo with the ambition of opening a PR, but I'm not especially familiar with how other folks are using PortalBase / PyPortal.
- could PyPortal simply remember the index of the caption? if so, how does it move the label / change the color if needed?
- should there be a way to remove labels in PortalBase, which PyPortal could use to remove / re-create the caption when needed?
- would remembering the caption label index be fragile - and prone to break if/when the fetched data needs more / fewer labels?
- should the Adafruit_Learning_System_Guides code be updated to use PyPortal class / `set_caption` differently?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with adafruit_pyportal/__init__.py and the current set_caption() implementation, then read PortalBase.add_text() and the older implementation linked in the issue. Compare the current behavior with the Daily UV Index example and determine how caption updates should behave without accumulating labels. Done means the agreed behavior is implemented and verified against the cited usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100