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

A screen that is pushed via a command palette callback does not receive the push_screen callback #5512

Open
gunslingerfry opened this issue Feb 11, 2025 · 2 comments

Comments

@gunslingerfry
Copy link

gunslingerfry commented Feb 11, 2025

Have you checked closed issues? Yes

Have you checked against the most recent version of Textual? Yes

Please give a brief but clear explanation of the issue. If you can, include a complete working example that demonstrates the bug. Check it can run without modifications.

A screen pushed inside a CommandPalette SystemCommand callback does not receive the dismiss result.

Here is a slightly tweaked version of the QuitScreen example where it also calls the same function from the command palette. You can see that the key binding still quits the app as normal. If you do it from the command palette it does not quit. Does not matter if it is Modal or not.

from textual.app import App, ComposeResult, SystemCommand
from textual.containers import Grid
from textual.screen import ModalScreen, Screen
from textual.widgets import Button, Footer, Header, Label

class QuitScreen(ModalScreen[bool]):  
    """Screen with a dialog to quit."""

    def compose(self) -> ComposeResult:
        yield Grid(
            Label("Are you sure you want to quit?", id="question"),
            Button("Quit", variant="error", id="quit"),
            Button("Cancel", variant="primary", id="cancel"),
            id="dialog",
        )

    def on_button_pressed(self, event: Button.Pressed) -> None:
        if event.button.id == "quit":
            self.dismiss(True)
        else:
            self.dismiss(False)


class ModalApp(App):
    """An app with a modal dialog."""

    # CSS_PATH = "modal01.tcss"
    BINDINGS = [("q", "request_quit", "Quit")]

    def compose(self) -> ComposeResult:
        yield Header()
        yield Footer()

    def get_system_commands(self, screen: Screen) -> Iterable[SystemCommand]:
        yield from super().get_system_commands(screen)
        yield SystemCommand("try a modal quit dialog", "this should work", self.action_request_quit)

    def action_request_quit(self) -> None:
        """Action to display the quit dialog."""

        def check_quit(quit: bool | None) -> None:
            """Called when QuitScreen is dismissed."""
            if quit:
                self.exit()

        self.push_screen(QuitScreen(), check_quit)


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

Textual Diagnostics

Versions

Name Value
Textual 1.0.0
Rich 13.9.4

Python

Name Value
Version 3.13.0
Implementation CPython
Compiler GCC 14.2.1 20240910
Executable /home/matthew/.pyenv/versions/3.13.0/bin/python3.13

Operating System

Name Value
System Linux
Release 6.13.1-arch1-1
Version #1 SMP PREEMPT_DYNAMIC Sun, 02 Feb 2025 01:02:29 +0000

Terminal

Name Value
Terminal Application Unknown
TERM xterm-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=263, height=48
legacy_windows False
min_width 1
max_width 263
is_terminal True
encoding utf-8
max_height 48
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

@TomJGooding
Copy link
Contributor

This sounds similar to another recent issue, where these callbacks stopped working after Textual v0.74.0:

For what it's worth, I found that reverting 5a99dee so the app calls the selected command seems to work, although I doubt this is the proper fix.

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