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.
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?
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 singlelabel
for the caption, and its text was set duringPyPortal()
construction, and then could be updated later usingset_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-L102Code with the bug
Today's implementation of
PyPortal.set_caption
always callsPortalBase.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-L296Here'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:
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.
set_caption
differently?