Skip to content

Commit 7215d6f

Browse files
authored
Merge pull request #108 from makermelissa/main
Change splash to root_group for more clarity
2 parents e00bf2f + 6c4c3a9 commit 7215d6f

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

adafruit_portalbase/__init__.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,8 @@ def __init__( # noqa: PLR0912,PLR0913 Too many branches,Too many arguments in f
7373
self.network = network
7474
"""The :py:class:`~adafruit_portalbase.NetworkBase`-derived instance provided"""
7575
self.graphics = graphics
76-
"""The :py:class:`~adafruit_portalbase.GraphicsBase`-derived instance provided"""
77-
self.splash = self.graphics.splash
78-
"""The :py:meth:`displayio.Group()` object that acts as the splash screen
76+
"""The :py:meth:`displayio.Group()` object that acts as the root group screen
7977
for this device."""
80-
self.display = self.graphics.display
81-
"""The :py:class:`busdisplay.BusDisplay` object representing the screen for this device"""
8278

8379
# Font Cache
8480
self._fonts = {}
@@ -267,7 +263,7 @@ def set_text(self, val, index=0): # noqa: PLR0912 Too many branches
267263
string = string[: self._text[index]["maxlen"] - 3] + "..."
268264
else:
269265
string = string[: self._text[index]["maxlen"]]
270-
index_in_splash = None
266+
index_in_root_group = None
271267

272268
if len(string) > 0 and self._text[index]["wrap"]:
273269
if self._debug:
@@ -278,7 +274,7 @@ def set_text(self, val, index=0): # noqa: PLR0912 Too many branches
278274
if self._text[index]["label"] is not None:
279275
if self._debug:
280276
print("Replacing text area with :", string)
281-
index_in_splash = self.splash.index(self._text[index]["label"])
277+
index_in_root_group = self.root_group.index(self._text[index]["label"])
282278
elif self._debug:
283279
print("Creating text area with :", string)
284280
if len(string) > 0:
@@ -288,22 +284,22 @@ def set_text(self, val, index=0): # noqa: PLR0912 Too many branches
288284
text=string,
289285
scale=self._text[index]["scale"],
290286
)
291-
if index_in_splash is not None:
292-
self.splash[index_in_splash] = self._text[index]["label"]
287+
if index_in_root_group is not None:
288+
self.root_group[index_in_root_group] = self._text[index]["label"]
293289
else:
294-
self.splash.append(self._text[index]["label"])
290+
self.root_group.append(self._text[index]["label"])
295291
else:
296292
self._text[index]["label"].text = string
297293
self._text[index]["label"].color = self._text[index]["color"]
298294
self._text[index]["label"].anchor_point = self._text[index]["anchor_point"]
299295
self._text[index]["label"].anchored_position = self._text[index]["position"]
300296
self._text[index]["label"].line_spacing = self._text[index]["line_spacing"]
301-
elif index_in_splash is not None:
297+
elif index_in_root_group is not None:
302298
self._text[index]["label"] = None
303299

304-
# Remove the label from splash
305-
if index_in_splash is not None and self._text[index]["label"] is None:
306-
del self.splash[index_in_splash]
300+
# Remove the label from root group
301+
if index_in_root_group is not None and self._text[index]["label"] is None:
302+
del self.root_group[index_in_root_group]
307303
gc.collect()
308304

309305
def preload_font(self, glyphs=None, index=0):
@@ -552,3 +548,22 @@ def json_path(self, value):
552548
self._json_path = (value,)
553549
else:
554550
self._json_path = None
551+
552+
@property
553+
def root_group(self):
554+
"""The root display group for this device."""
555+
return self.graphics.root_group
556+
557+
@property
558+
def splash(self):
559+
"""The root display group for this device (for backwards compatibility)."""
560+
print(
561+
"WARNING: splash is deprecated, use root_group instead. "
562+
"This will be removed in a future release."
563+
)
564+
return self.graphics.root_group
565+
566+
@property
567+
def display(self):
568+
"""The displayio.Display object for this device."""
569+
return self.graphics.display

adafruit_portalbase/graphics.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ def __init__(self, display, *, default_bg=0x000000, scale=1, debug=False): # no
4747

4848
if self._debug:
4949
print("Init display")
50-
self.splash = displayio.Group(scale=scale)
50+
self._root_group = displayio.Group(scale=scale)
5151
self._qr_group = None
5252
if self._debug:
5353
print("Init background")
5454
self._bg_group = displayio.Group()
55-
self.splash.append(self._bg_group)
55+
self._root_group.append(self._bg_group)
5656

5757
# set the default background
5858
if default_bg is not None:
59-
self.display.root_group = self.splash
59+
self.display.root_group = self._root_group
6060
self.set_background(default_bg)
6161

6262
gc.collect()
@@ -110,8 +110,8 @@ def qrcode(self, qr_data, *, qr_size=1, x=0, y=0, qr_color=0x000000): # noqa: P
110110
111111
"""
112112
if qr_data is None:
113-
if self._qr_group and self._qr_group in self.splash:
114-
self.splash.remove(self._qr_group)
113+
if self._qr_group and self._qr_group in self._root_group:
114+
self._root_group.remove(self._qr_group)
115115
self._qr_group = None
116116
gc.collect()
117117
return
@@ -154,8 +154,22 @@ def qrcode(self, qr_data, *, qr_size=1, x=0, y=0, qr_color=0x000000): # noqa: P
154154
pass
155155
else:
156156
self._qr_group = displayio.Group()
157-
self.splash.append(self._qr_group)
157+
self._root_group.append(self._qr_group)
158158
self._qr_group.scale = qr_size
159159
self._qr_group.x = x
160160
self._qr_group.y = y
161161
self._qr_group.append(qr_sprite)
162+
163+
@property
164+
def root_group(self):
165+
"""The display's root group."""
166+
return self._root_group
167+
168+
@property
169+
def splash(self):
170+
"""The display's root group (for backwards compatibility)."""
171+
print(
172+
"WARNING: splash is deprecated, use root_group instead. "
173+
"This will be removed in a future release."
174+
)
175+
return self.display._root_group

0 commit comments

Comments
 (0)