adafruit / Adafruit_CircuitPython_MagTag

Helper library for the Adafruit MagTag
MIT License
28 stars 24 forks source link

Needs override for remove_all_text from parent portal base to avoid a refresh exception #86

Closed diego-wh closed 5 months ago

diego-wh commented 2 years ago

Portalbase has a function to remove all text (remove_all_text) this calls self.set_text to clear the labels. Since magtag overrides this call to add the option to do a refresh ( auto_refresh: bool = True ) it would be nice to have an override of this function that takes the auto_refresh parameter. If we have more than a couple of labels (text fields) it is likely we will get the Refresh too soon exception. The code change should be relatively simple (same as parent just passing the extra parameter to set_text). I am unsure if this is part of the scope for this library. I could not find an easy way to remove all objects from the display (maybe I am missing something), but that may be a suitable workaround. I have been using a work around for my code

def remove_all_text():
    for i in range(count_labels):
        magtag.set_text("", auto_refresh=False, index = i)

where count_labels is a simple counter that increments every time I call add_text. but in this case I don't get the benefit of deleting the _text list ( self._text = [] ).

ladyada commented 2 years ago

wanna submit a PR? @makermelissa can review when she returns in a couple weeks

diego-wh commented 2 years ago

I could try to take a look at it over the weekend.

makermelissa commented 2 years ago

I don't have a MagTag with me, but it should just be a matter of adding an override function to this library.