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

ModalScreen takes the size of the terminal window when it was first opened and not its current size #5118

Open
DrPleaseRespect opened this issue Oct 14, 2024 · 5 comments

Comments

@DrPleaseRespect
Copy link

ModalScreen takes the size of the terminal window when the program was first opened and not its current size.

2024-10-14.21-53-59.mp4

Textual Diagnostics

Versions

Name Value
Textual 0.83.0
Rich 13.8.0

Python

Name Value
Version 3.12.5
Implementation CPython
Compiler MSC v.1940 64 bit (AMD64)
Executable G:\Python\3.12\AudioPlayer\venv\Scripts\python.exe

Operating System

Name Value
System Windows
Release 11
Version 10.0.22631

Terminal

Name Value
Terminal Application Windows Terminal
TERM Not set
COLORTERM Not set
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=128, height=36
legacy_windows True
min_width 1
max_width 128
is_terminal False
encoding cp1252
max_height 36
justify None
overflow None
no_wrap False
highlight None
markup None
height None
Copy link

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@DrPleaseRespect
Copy link
Author

Code used in the video

from textual.app import App, ComposeResult
from textual.containers import (
    Grid,
)
from textual import work
from textual.widgets import Label, Button
from textual.screen import ModalScreen


class ErrorMessage(ModalScreen):
    DEFAULT_CSS = """
    ErrorMessage {
        align: center middle;
    }

    #ErrorPopup {
        align: center middle;
        grid-size: 1 3;
        width: 80;
        height: 20;
        padding: 2;
        grid-rows: 1 1fr 3;
    }

    .center {
        content-align: center middle;
    }

    .label {
        height: 1fr;
        width: 1fr;
    }

    .btn {
        width: 100%;
    }

"""

    def __init__(self, errormsg: str = "", *args, **kwargs):
        self.errormsg = errormsg
        super().__init__(*args, **kwargs)

    def compose(self) -> ComposeResult:
        with Grid(id="ErrorPopup"):
            yield Label("Error!", classes="center label")
            yield Label("ErrorMSG", id="ErrorMsg", classes="center label")
            yield Button("Okay", variant="error", id="Okay", classes="btn")

    def on_mount(self):
        self.query_one("#ErrorMsg", Label).update(self.errormsg)

    def on_button_pressed(self, event: Button.Pressed):
        self.dismiss()


class App(App):

    def compose(self) -> ComposeResult:
        """Create child widgets for the app."""
        yield Button("Open Modal", id="btn")

    @work(exclusive=True)
    async def on_button_pressed(self, event: Button.Pressed):
        if event.button.id == "btn":
            self.push_screen(ErrorMessage(errormsg="This is an error message."))


if __name__ == "__main__":
    app = App()
    app.run()

@willmcgugan
Copy link
Collaborator

I can't reproduce this on macOS or Windows.

Can you try with the latest Windows Terminal? https://apps.microsoft.com/detail/9n0dx20hk701?hl=en-gb&gl=US

Screen.Recording.2024-10-14.at.15.21.53.mov

@DrPleaseRespect
Copy link
Author

Can you try with the latest Windows Terminal? https://apps.microsoft.com/detail/9n0dx20hk701?hl=en-gb&gl=US

Initially Tested on Windows Terminal Version 1.20.11781.0

Updated to Windows Terminal Version 1.21.2701.0 (from GitHub): Bug Still Occurs
https://github.com/microsoft/terminal/releases/tag/v1.21.2701.0

2024-10-14.22-35-25.mp4

@DrPleaseRespect
Copy link
Author

DrPleaseRespect commented Oct 14, 2024

Clink (https://github.com/chrisant996/clink) conflicts with Textual. When Clink is disabled, the functionality works properly

2024-10-14.22-48-26.mp4

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

2 participants