Merge pull request #108 from makermelissa/main
Change splash to root_group for more clarity
This commit is contained in:
commit
7215d6f269
2 changed files with 49 additions and 20 deletions
|
|
@ -73,12 +73,8 @@ class PortalBase:
|
||||||
self.network = network
|
self.network = network
|
||||||
"""The :py:class:`~adafruit_portalbase.NetworkBase`-derived instance provided"""
|
"""The :py:class:`~adafruit_portalbase.NetworkBase`-derived instance provided"""
|
||||||
self.graphics = graphics
|
self.graphics = graphics
|
||||||
"""The :py:class:`~adafruit_portalbase.GraphicsBase`-derived instance provided"""
|
"""The :py:meth:`displayio.Group()` object that acts as the root group screen
|
||||||
self.splash = self.graphics.splash
|
|
||||||
"""The :py:meth:`displayio.Group()` object that acts as the splash screen
|
|
||||||
for this device."""
|
for this device."""
|
||||||
self.display = self.graphics.display
|
|
||||||
"""The :py:class:`busdisplay.BusDisplay` object representing the screen for this device"""
|
|
||||||
|
|
||||||
# Font Cache
|
# Font Cache
|
||||||
self._fonts = {}
|
self._fonts = {}
|
||||||
|
|
@ -267,7 +263,7 @@ class PortalBase:
|
||||||
string = string[: self._text[index]["maxlen"] - 3] + "..."
|
string = string[: self._text[index]["maxlen"] - 3] + "..."
|
||||||
else:
|
else:
|
||||||
string = string[: self._text[index]["maxlen"]]
|
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 len(string) > 0 and self._text[index]["wrap"]:
|
||||||
if self._debug:
|
if self._debug:
|
||||||
|
|
@ -278,7 +274,7 @@ class PortalBase:
|
||||||
if self._text[index]["label"] is not None:
|
if self._text[index]["label"] is not None:
|
||||||
if self._debug:
|
if self._debug:
|
||||||
print("Replacing text area with :", string)
|
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:
|
elif self._debug:
|
||||||
print("Creating text area with :", string)
|
print("Creating text area with :", string)
|
||||||
if len(string) > 0:
|
if len(string) > 0:
|
||||||
|
|
@ -288,22 +284,22 @@ class PortalBase:
|
||||||
text=string,
|
text=string,
|
||||||
scale=self._text[index]["scale"],
|
scale=self._text[index]["scale"],
|
||||||
)
|
)
|
||||||
if index_in_splash is not None:
|
if index_in_root_group is not None:
|
||||||
self.splash[index_in_splash] = self._text[index]["label"]
|
self.root_group[index_in_root_group] = self._text[index]["label"]
|
||||||
else:
|
else:
|
||||||
self.splash.append(self._text[index]["label"])
|
self.root_group.append(self._text[index]["label"])
|
||||||
else:
|
else:
|
||||||
self._text[index]["label"].text = string
|
self._text[index]["label"].text = string
|
||||||
self._text[index]["label"].color = self._text[index]["color"]
|
self._text[index]["label"].color = self._text[index]["color"]
|
||||||
self._text[index]["label"].anchor_point = self._text[index]["anchor_point"]
|
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"].anchored_position = self._text[index]["position"]
|
||||||
self._text[index]["label"].line_spacing = self._text[index]["line_spacing"]
|
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
|
self._text[index]["label"] = None
|
||||||
|
|
||||||
# Remove the label from splash
|
# Remove the label from root group
|
||||||
if index_in_splash is not None and self._text[index]["label"] is None:
|
if index_in_root_group is not None and self._text[index]["label"] is None:
|
||||||
del self.splash[index_in_splash]
|
del self.root_group[index_in_root_group]
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
def preload_font(self, glyphs=None, index=0):
|
def preload_font(self, glyphs=None, index=0):
|
||||||
|
|
@ -552,3 +548,22 @@ class PortalBase:
|
||||||
self._json_path = (value,)
|
self._json_path = (value,)
|
||||||
else:
|
else:
|
||||||
self._json_path = None
|
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
|
||||||
|
|
|
||||||
|
|
@ -47,16 +47,16 @@ class GraphicsBase:
|
||||||
|
|
||||||
if self._debug:
|
if self._debug:
|
||||||
print("Init display")
|
print("Init display")
|
||||||
self.splash = displayio.Group(scale=scale)
|
self._root_group = displayio.Group(scale=scale)
|
||||||
self._qr_group = None
|
self._qr_group = None
|
||||||
if self._debug:
|
if self._debug:
|
||||||
print("Init background")
|
print("Init background")
|
||||||
self._bg_group = displayio.Group()
|
self._bg_group = displayio.Group()
|
||||||
self.splash.append(self._bg_group)
|
self._root_group.append(self._bg_group)
|
||||||
|
|
||||||
# set the default background
|
# set the default background
|
||||||
if default_bg is not None:
|
if default_bg is not None:
|
||||||
self.display.root_group = self.splash
|
self.display.root_group = self._root_group
|
||||||
self.set_background(default_bg)
|
self.set_background(default_bg)
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
@ -110,8 +110,8 @@ class GraphicsBase:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if qr_data is None:
|
if qr_data is None:
|
||||||
if self._qr_group and self._qr_group in self.splash:
|
if self._qr_group and self._qr_group in self._root_group:
|
||||||
self.splash.remove(self._qr_group)
|
self._root_group.remove(self._qr_group)
|
||||||
self._qr_group = None
|
self._qr_group = None
|
||||||
gc.collect()
|
gc.collect()
|
||||||
return
|
return
|
||||||
|
|
@ -154,8 +154,22 @@ class GraphicsBase:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self._qr_group = displayio.Group()
|
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.scale = qr_size
|
||||||
self._qr_group.x = x
|
self._qr_group.x = x
|
||||||
self._qr_group.y = y
|
self._qr_group.y = y
|
||||||
self._qr_group.append(qr_sprite)
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue