Skip to content

Change splash to root_group for more clarity #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions adafruit_portalbase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ def __init__( # noqa: PLR0912,PLR0913 Too many branches,Too many arguments in f
self.network = network
"""The :py:class:`~adafruit_portalbase.NetworkBase`-derived instance provided"""
self.graphics = graphics
"""The :py:class:`~adafruit_portalbase.GraphicsBase`-derived instance provided"""
self.splash = self.graphics.splash
"""The :py:meth:`displayio.Group()` object that acts as the splash screen
"""The :py:meth:`displayio.Group()` object that acts as the root group screen
for this device."""
self.display = self.graphics.display
"""The :py:class:`busdisplay.BusDisplay` object representing the screen for this device"""

# Font Cache
self._fonts = {}
Expand Down Expand Up @@ -267,7 +263,7 @@ def set_text(self, val, index=0): # noqa: PLR0912 Too many branches
string = string[: self._text[index]["maxlen"] - 3] + "..."
else:
string = string[: self._text[index]["maxlen"]]
index_in_splash = None
index_in_root_group = None

if len(string) > 0 and self._text[index]["wrap"]:
if self._debug:
Expand All @@ -278,7 +274,7 @@ def set_text(self, val, index=0): # noqa: PLR0912 Too many branches
if self._text[index]["label"] is not None:
if self._debug:
print("Replacing text area with :", string)
index_in_splash = self.splash.index(self._text[index]["label"])
index_in_root_group = self.root_group.index(self._text[index]["label"])
elif self._debug:
print("Creating text area with :", string)
if len(string) > 0:
Expand All @@ -288,22 +284,22 @@ def set_text(self, val, index=0): # noqa: PLR0912 Too many branches
text=string,
scale=self._text[index]["scale"],
)
if index_in_splash is not None:
self.splash[index_in_splash] = self._text[index]["label"]
if index_in_root_group is not None:
self.root_group[index_in_root_group] = self._text[index]["label"]
else:
self.splash.append(self._text[index]["label"])
self.root_group.append(self._text[index]["label"])
else:
self._text[index]["label"].text = string
self._text[index]["label"].color = self._text[index]["color"]
self._text[index]["label"].anchor_point = self._text[index]["anchor_point"]
self._text[index]["label"].anchored_position = self._text[index]["position"]
self._text[index]["label"].line_spacing = self._text[index]["line_spacing"]
elif index_in_splash is not None:
elif index_in_root_group is not None:
self._text[index]["label"] = None

# Remove the label from splash
if index_in_splash is not None and self._text[index]["label"] is None:
del self.splash[index_in_splash]
# Remove the label from root group
if index_in_root_group is not None and self._text[index]["label"] is None:
del self.root_group[index_in_root_group]
gc.collect()

def preload_font(self, glyphs=None, index=0):
Expand Down Expand Up @@ -552,3 +548,22 @@ def json_path(self, value):
self._json_path = (value,)
else:
self._json_path = None

@property
def root_group(self):
"""The root display group for this device."""
return self.graphics.root_group

@property
def splash(self):
"""The root display group for this device (for backwards compatibility)."""
print(
"WARNING: splash is deprecated, use root_group instead. "
"This will be removed in a future release."
)
return self.graphics.root_group

@property
def display(self):
"""The displayio.Display object for this device."""
return self.graphics.display
26 changes: 20 additions & 6 deletions adafruit_portalbase/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ def __init__(self, display, *, default_bg=0x000000, scale=1, debug=False): # no

if self._debug:
print("Init display")
self.splash = displayio.Group(scale=scale)
self._root_group = displayio.Group(scale=scale)
self._qr_group = None
if self._debug:
print("Init background")
self._bg_group = displayio.Group()
self.splash.append(self._bg_group)
self._root_group.append(self._bg_group)

# set the default background
if default_bg is not None:
self.display.root_group = self.splash
self.display.root_group = self._root_group
self.set_background(default_bg)

gc.collect()
Expand Down Expand Up @@ -110,8 +110,8 @@ def qrcode(self, qr_data, *, qr_size=1, x=0, y=0, qr_color=0x000000): # noqa: P

"""
if qr_data is None:
if self._qr_group and self._qr_group in self.splash:
self.splash.remove(self._qr_group)
if self._qr_group and self._qr_group in self._root_group:
self._root_group.remove(self._qr_group)
self._qr_group = None
gc.collect()
return
Expand Down Expand Up @@ -154,8 +154,22 @@ def qrcode(self, qr_data, *, qr_size=1, x=0, y=0, qr_color=0x000000): # noqa: P
pass
else:
self._qr_group = displayio.Group()
self.splash.append(self._qr_group)
self._root_group.append(self._qr_group)
self._qr_group.scale = qr_size
self._qr_group.x = x
self._qr_group.y = y
self._qr_group.append(qr_sprite)

@property
def root_group(self):
"""The display's root group."""
return self._root_group

@property
def splash(self):
"""The display's root group (for backwards compatibility)."""
print(
"WARNING: splash is deprecated, use root_group instead. "
"This will be removed in a future release."
)
return self.display._root_group