Skip to content
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

Form's text inconsistently behind its background #41

Open
dumbasaroc opened this issue Aug 24, 2020 · 4 comments
Open

Form's text inconsistently behind its background #41

dumbasaroc opened this issue Aug 24, 2020 · 4 comments

Comments

@dumbasaroc
Copy link

So I noticed while playing around with Form that in some cases its text (its Label) was behind the background, resulting in text not being shown. I also noticed that its do_regroup_children function wasn't defined. Placing the following code in my custom Form class (that always has a Base and a Label) seemed to mitigate this problem, leading me to believe it was a bug:

def do_regroup_children(self):
    self._label._regroup(pyglet.graphics.OrderedGroup(2, self.group))
    self._bg._regroup(pyglet.graphics.OrderedGroup(1, self.group))

Perhaps the do_regroup_children function should be defined in the Form in the base module?

@kalekundert
Copy link
Contributor

Hmmm, that's bizarre. It shouldn't be necessary for Form to implement do_regroup_children(), because it uses a Stack to organize the its background and label widgets, and the stack should take care of setting up the ordered groups. But that doesn't explain why you're getting the label behind the background sometimes.

If you can create a minimal working example that exhibits the label intermittently appearing behind the background (admittedly, I know it can be hard to create MWEs of intermittent problems), I'd be interested in looking into that.

@dumbasaroc
Copy link
Author

dumbasaroc commented Aug 24, 2020

I haven't gotten a minimal example of it yet, however, I have gotten a video example of it happening in my original code, before adding in the do_regroup_children function. It occurred after about 3 or 4 resets of the program. All the points where the cursor is over a text input, I'm spam-clicking the input to show that it's selected, but behind the background.

Video

@dumbasaroc
Copy link
Author

Interesting development, but one of the times that I loaded the program up WITH the fix that I made, the text was behind the form again! So now we definitely know that it doesn't have to do with do_regroup_children... I have no idea what could be causing this odd bug.

@Rahuum
Copy link

Rahuum commented Jan 16, 2022

So I've run into this problem myself, and to help debug it, I wrote a quick tree printer. It may be unrelated, but it looks like it may have something to do with the discrepency between _children in containers, and _Widget__children in widgets.

If I use this tree printer:

    def tree_print(self, item=None, depth=0):
        if not item:
            item = self.gui
        print(f"{' '*(depth*4)}{self.printer(item)}")
        children = list(getattr(item, '_children', []))
        if not children:
            children = list(getattr(item, '_Widget__children', []))
        for child in children:
            self.tree_print(child, depth+1)

    def printer(self, item):
        order_type = getattr(item, '_Widget__group', 'NullGroup')
        return f"[{order_type}] {str(item)}"

Then the tree always prints appropriately as:

[OrderedGroup(1)] Gui(id=2220)
    [OrderedGroup(0)] Frame(id=2250)
        [OrderedGroup(2)] Box(id=2280)
            [OrderedGroup(2)] VBox(id=2d00)
                [OrderedGroup(2)] Label(id=05e0, "Server...")
                [OrderedGroup(2)] LoginForm(id=23d0)
                    [OrderedGroup(2)] Stack(id=1280)
                        [OrderedGroup(0)] Label(id=8e80, "localhost")
                        [OrderedGroup(-1)] Base(id=8df0)
                [OrderedGroup(2)] Label(id=8e20, "Server...")
                [OrderedGroup(2)] LoginForm(id=ec10)
                    [OrderedGroup(2)] Stack(id=7f40)
                        [OrderedGroup(0)] Label(id=c220, "9123")
                        [OrderedGroup(-1)] Base(id=ce50)
                [OrderedGroup(2)] Spacer(id=c820)
                [OrderedGroup(2)] Button(id=cdc0)
                    [OrderedGroup(1)] Rollover(id=c9a0)
                        [OrderedGroup(1)] Image(id=9610)
                        [OrderedGroup(1)] Image(id=58b0)
                        [OrderedGroup(1)] Image(id=56d0)
                        [OrderedGroup(1)] Image(id=9af0)
                    [OrderedGroup(2)] Label(id=c4c0, "Connect")
        [OrderedGroup(1)] Decoration(id=2b80)

even when 'Connect' does not show on the button, like so:
image

However, when I use THIS tree printer:

    def tree_print(self, item=None, depth=0):
        if not item:
            item = self.gui
        print(f"{' '*(depth*4)}{self.printer(item)}")
        children = list(getattr(item, '_Widget__children', []))
        for child in children:
            self.tree_print(child, depth+1)

Then something interesting happens: I get the same printed tree as the above when 'Connect' is shown.... but when it's not i get a different tree, specifically something like this:

[OrderedGroup(1)] Gui(id=2220)
    [OrderedGroup(0)] Frame(id=2250)
        [OrderedGroup(2)] Box(id=2280)
            [OrderedGroup(2)] VBox(id=2d00)
                [OrderedGroup(2)] Label(id=05e0, "Server...")
                [OrderedGroup(2)] Label(id=8e20, "Server...")
                [OrderedGroup(2)] Spacer(id=c820)
                [OrderedGroup(2)] LoginForm(id=23d0)
                    [OrderedGroup(2)] Stack(id=1280)
                        [OrderedGroup(0)] Label(id=8e80, "localhost")
                        [OrderedGroup(-1)] Base(id=8df0)
                [OrderedGroup(2)] Button(id=cdc0)
                    [OrderedGroup(1)] Rollover(id=c9a0)
                        [OrderedGroup(1)] Image(id=9610)
                        [OrderedGroup(1)] Image(id=58b0)
                        [OrderedGroup(1)] Image(id=56d0)
                        [OrderedGroup(1)] Image(id=9af0)
                    [OrderedGroup(2)] Label(id=c4c0, "Connect")
                [OrderedGroup(2)] LoginForm(id=ec10)
                    [OrderedGroup(2)] Stack(id=7f40)
                        [OrderedGroup(0)] Label(id=c220, "9123")
                        [OrderedGroup(-1)] Base(id=ce50)
        [OrderedGroup(1)] Decoration(id=2b80)

This may be a complete coincidence, but it's very, very consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants