Skip to content

Commit 4941e40

Browse files
authored
Merge pull request #19 from makermelissa/main
Fix memory issues with label reuse and use of bitmap label
2 parents 4f4069c + fb7c051 commit 4941e40

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

adafruit_portalbase/__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import time
2525
import terminalio
2626
from adafruit_bitmap_font import bitmap_font
27-
from adafruit_display_text.label import Label
27+
from adafruit_display_text.bitmap_label import Label
2828
from adafruit_display_text import wrap_text_to_lines
2929

3030
__version__ = "0.0.0-auto.0"
@@ -237,27 +237,29 @@ def set_text(self, val, index=0):
237237
index_in_splash = self.splash.index(self._text[index]["label"])
238238
elif self._debug:
239239
print("Creating text area with :", string)
240-
241240
if len(string) > 0:
242-
self._text[index]["label"] = Label(
243-
self._fonts[self._text[index]["font"]],
244-
text=string,
245-
scale=self._text[index]["scale"],
246-
)
241+
if self._text[index]["label"] is None:
242+
self._text[index]["label"] = Label(
243+
self._fonts[self._text[index]["font"]],
244+
text=string,
245+
scale=self._text[index]["scale"],
246+
)
247+
if index_in_splash is not None:
248+
self.splash[index_in_splash] = self._text[index]["label"]
249+
else:
250+
self.splash.append(self._text[index]["label"])
251+
else:
252+
self._text[index]["label"].text = string
247253
self._text[index]["label"].color = self._text[index]["color"]
248254
self._text[index]["label"].anchor_point = self._text[index]["anchor_point"]
249255
self._text[index]["label"].anchored_position = self._text[index]["position"]
250256
self._text[index]["label"].line_spacing = self._text[index]["line_spacing"]
251257
elif index_in_splash is not None:
252258
self._text[index]["label"] = None
253259

254-
if index_in_splash is not None:
255-
if self._text[index]["label"] is not None:
256-
self.splash[index_in_splash] = self._text[index]["label"]
257-
else:
258-
del self.splash[index_in_splash]
259-
elif self._text[index]["label"] is not None:
260-
self.splash.append(self._text[index]["label"])
260+
# Remove the label from splash
261+
if index_in_splash is not None and self._text[index]["label"] is None:
262+
del self.splash[index_in_splash]
261263

262264
def preload_font(self, glyphs=None, index=0):
263265
# pylint: disable=line-too-long

0 commit comments

Comments
 (0)