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 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:
Adafruit_CircuitPython_PyPortal/adafruit_pyportal/__init__.py
Lines 274 to 296 in de0b008
Here's a link to the add_text implementation
Old Implementation
Looking into the source history, prior to #99, the caption label was created if needed, otherwise it was updated:
Adafruit_CircuitPython_PyPortal/adafruit_pyportal.py
Lines 586 to 618 in 88358c0
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?