Skip to content

Commit

Permalink
Merge pull request #92 from makermelissa/main
Browse files Browse the repository at this point in the history
Add remove_all_text func that accounts for auto-refresh
  • Loading branch information
makermelissa committed Mar 26, 2024
2 parents 87f48a7 + 411fec8 commit f7f534f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions adafruit_magtag/magtag.py
Expand Up @@ -208,3 +208,24 @@ def refresh(self) -> None:
return
except RuntimeError:
time.sleep(1)

def remove_all_text(self, auto_refresh=True, clear_font_cache=False):
"""Remove all added text and labels.
:param auto_refresh: Automatically refresh the display after setting the
text. Defaults to True.
:param bool clear_font_cache: Clear the font cache. Defaults to False.
"""

# Remove the labels
for i in range(
len(self._text) # pylint: disable=access-member-before-definition
):
self.set_text("", auto_refresh=False, index=i)
# Remove the data
self._text = [] # pylint: disable=attribute-defined-outside-init
if clear_font_cache:
self._fonts = {} # pylint: disable=attribute-defined-outside-init
if auto_refresh:
self.refresh()
gc.collect()

0 comments on commit f7f534f

Please sign in to comment.