Skip to content

displayio.Group .hidden flag is not honored if set to True before content is appended to group. #4193

@kmatch98

Description

@kmatch98

I observed a strange behavior when using the .hidden flag of the displayio.Group where the group is actually visible, even when group.hidden is set to True.

If the group.hidden is set to True before content is appended into it, the .hidden flag is ignored.
The group.hidden flag's proper behavior can only be recovered if it set to False and then back to True again.

Here's the example code to replicate the issue. This was tested on the PyPortal.

CircuitPython version info: Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit PyPortal with samd51j20

# Demo of strange group behavior group.hidden is set True before content is appended
#
import time
import board
import displayio

# start display for example with PyPortal
display = board.DISPLAY

bitmap = displayio.Bitmap(50,50, 2)
palette = displayio.Palette(2)
palette[0] = 0xAA0000
tilegrid = displayio.TileGrid(bitmap, pixel_shader=palette)

group = displayio.Group(x=(320-bitmap.width)//2, y=(240-bitmap.height)//2, max_size=1)
group.hidden=True  ##### If this statement is included before the tilegrid is appended
                   ##### onto the group, the group is incorrectly visible until
                   ##### the `group.hidden` is set False and then back to True
                   #####
                   ##### If this line is commented out, it works as expected.

print("1 group.hidden: {}".format(group.hidden))

group.append(tilegrid)
print("2 group.hidden: {}".format(group.hidden))
group.hidden = True
print("3 group.hidden: {}".format(group.hidden))

display.show(group)
display.refresh()

print("Red square should be hidden.") # Red square is visible with current code
time.sleep(5)

group.hidden=True
print("Set /`group.hidden = True/` again.  Red square should be hidden.")
print("4 group.hidden: {}".format(group.hidden))
time.sleep(5)  # Red square is visible with current code

group.hidden=False
print("Set /`group.hidden = False/`, Red square should be visible.")
print("5 group.hidden: {}".format(group.hidden))
time.sleep(5)

group.hidden=True
print("Set /`group.hidden = True/` another time.  Red square should be hidden.")
print("6 group.hidden: {}".format(group.hidden))
time.sleep(5)

group.hidden=False
print("Set /`group.hidden = False/`, Red square should be visible.")
print("7 group.hidden: {}".format(group.hidden))

while True:
    pass

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions