adafruit / Adafruit_CircuitPython_PyPortal

CircuitPython driver for Adafruit PyPortal.
MIT License
45 stars 56 forks source link

PyPortal.set_caption() always adds a new caption with no way to remove older ones? #121

Open e28eta opened 2 years ago

e28eta commented 2 years ago

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: https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/blob/de0b0082e3bca027aeab391d9d96bcb74068b7dd/adafruit_pyportal/__init__.py#L274-L296

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:

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.