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

Background refresh of a screen #3055

Closed
davep opened this issue Aug 3, 2023 · 1 comment · Fixed by #3061
Closed

Background refresh of a screen #3055

davep opened this issue Aug 3, 2023 · 1 comment · Fixed by #3061
Labels
question Further information is requested Task

Comments

@davep
Copy link
Contributor

davep commented Aug 3, 2023

Writing this up as record of a conversation had with @willmcgugan yesterday, regarding if a screen that is "visible" in the ground of another screen (in other words when the foreground screen is transparent in areas) should be seen to update. So, given this code:

from datetime import datetime

from textual.app import App, ComposeResult, RenderResult
from textual.containers import Grid, Vertical
from textual.screen import ModalScreen
from textual.widgets import Label, Button

class PopUp(ModalScreen[None]):

    DEFAULT_CSS = """
    PopUp {
        align: center middle;
    }

    PopUp Vertical {
        align: center middle;
        background: $panel 50%;
        width: 30%;
        height: 30%;
        border: thick red;
    }
    """

    def compose(self) -> ComposeResult:
        with Vertical():
            yield Button("Press me to close me")

    def on_button_pressed(self) -> None:
        self.dismiss()

class Time(Label):

    DEFAULT_CSS = """
    Time {
        width: 1fr;
        height: 1fr;
        content-align: center middle;
        background: darkred;
        border: round red;
    }
    """

    def on_mount(self) -> None:
        self.auto_refresh = 0.2

    def render(self) -> RenderResult:
        return str(datetime.now())

class BackgroundRefreshApp(App[None]):

    CSS = """
    Grid {
        grid-size: 6;
    }
    """

    BINDINGS = [
        ("enter", "popup"),
    ]

    def compose(self) -> ComposeResult:
        with Grid():
            for _ in range(36):
                yield Time()

    def action_popup(self) -> None:
        self.push_screen(PopUp())

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

when you press Enter a modal popup will appear, and while it's visible none of the timers in the background will update. When hit again to dismiss the modal they'll start updating again.

It was suggested that they possibly should. It was my expectation that they wouldn't but I'm recording it here just in case.

Screen.Recording.2023-08-03.at.15.02.11.mov
@davep davep added question Further information is requested Task labels Aug 3, 2023
davep added a commit to davep/textual-sandbox that referenced this issue Aug 3, 2023
@github-actions
Copy link

github-actions bot commented Aug 5, 2023

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
question Further information is requested Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant