Skip to content

Commit f7f534f

Browse files
authored
Merge pull request #92 from makermelissa/main
Add remove_all_text func that accounts for auto-refresh
2 parents 87f48a7 + 411fec8 commit f7f534f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

adafruit_magtag/magtag.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,24 @@ def refresh(self) -> None:
208208
return
209209
except RuntimeError:
210210
time.sleep(1)
211+
212+
def remove_all_text(self, auto_refresh=True, clear_font_cache=False):
213+
"""Remove all added text and labels.
214+
215+
:param auto_refresh: Automatically refresh the display after setting the
216+
text. Defaults to True.
217+
:param bool clear_font_cache: Clear the font cache. Defaults to False.
218+
"""
219+
220+
# Remove the labels
221+
for i in range(
222+
len(self._text) # pylint: disable=access-member-before-definition
223+
):
224+
self.set_text("", auto_refresh=False, index=i)
225+
# Remove the data
226+
self._text = [] # pylint: disable=attribute-defined-outside-init
227+
if clear_font_cache:
228+
self._fonts = {} # pylint: disable=attribute-defined-outside-init
229+
if auto_refresh:
230+
self.refresh()
231+
gc.collect()

0 commit comments

Comments
 (0)