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

It looks like on_hide is not called when a widget is hidden in some way #2574

Closed
davep opened this issue May 16, 2023 · 3 comments · Fixed by #2687
Closed

It looks like on_hide is not called when a widget is hidden in some way #2574

davep opened this issue May 16, 2023 · 3 comments · Fixed by #2687
Labels
bug Something isn't working Task

Comments

@davep
Copy link
Contributor

davep commented May 16, 2023

I would expect the following application to crash when the button is pressed:

from textual.app        import App, ComposeResult
from textual.containers import Vertical
from textual.widgets    import Button, Label

class ShouldCrash( Label ):

    def on_hide( self ) -> None:
        _ = 1/0

class NoHideApp( App[ None ] ):

    CSS = """
    Vertical {
        align: center middle;
    }
    """

    def compose( self ) -> ComposeResult:
        with Vertical():
            yield Button( "Press to hide the label below" )
            yield ShouldCrash( "Press the button above me to hide me" )

    def on_button_pressed( self ):
        self.query_one( ShouldCrash ).display = False

if __name__ == "__main__":
    NoHideApp().run()

However, when the button is pressed; it doesn't. It would appear that the Hide message isn't being sent. Looking in the debug console I don't see the event.

The same is true if I attempt to hide the widget using any of:

self.query_one( ShouldCrash ).display = "none"
self.query_one( ShouldCrash ).visible = False
self.query_one( ShouldCrash ).set_class( True, "hidden" ) # With appropriate CSS to back it up.
@aaronst
Copy link
Contributor

aaronst commented May 30, 2023

I may have this wrong, but I think the issue might be in _compositor.reflow().

It looks like self.widgets = widgets and then hidden_widgets = self.widgets - widgets would mean hidden_widgets is always empty?

Should it maybe be hidden_widgets = old_widgets - new_widgets instead?

@aaronst
Copy link
Contributor

aaronst commented May 30, 2023

It looks like this was introduced here, where hidden_widgets was set before self.widgets = widgets.

@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants