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

Callback calling from CommandPalette vs Button #5499

Open
BongoKnight opened this issue Jan 30, 2025 · 1 comment
Open

Callback calling from CommandPalette vs Button #5499

BongoKnight opened this issue Jan 30, 2025 · 1 comment

Comments

@BongoKnight
Copy link

BongoKnight commented Jan 30, 2025

When an app callback function is fired by a Butoon.Pressed event, it seems to be triggered correctly, but this is not the case when this callback is called by a Hit object. This broke in release 0.74.0. Previously this callback was fired by both events.

Version 0.73 :
Version 0.73

Version 0.74 :
Version 0.74

See bellow an MRE

from textual import on
from textual.app import App, ComposeResult
from textual.command import Hit, Hits, Provider
from textual.screen import Screen
from textual.widgets import Button, Footer

ACTIONS = ["Action"]


class ActionCommands(Provider):
    """A command provider to return all actions for the current text."""

    async def search(self, query: str) -> Hits:
        """Search for action."""
        matcher = self.matcher(query)

        app = self.app
        assert isinstance(app, ClipBrowser)

        for value in ACTIONS:
            score = matcher.match(value)
            if score > 0:
                yield Hit(
                    value,
                    matcher.highlight(value),
                    app.get_param,
                    help=f"Executing {value}",
                )


class ParamScreen(Screen):
    def compose(self) -> ComposeResult:
        yield Button("ParamScreenButton")

    def on_button_pressed(self) -> None:
        self.dismiss(result="worked")


class ClipBrowser(App):
    COMMANDS = {ActionCommands}

    def compose(self) -> ComposeResult:
        yield Button("First button", id="main_button")
        yield Footer()

    def get_param(self):
        param_screen = ParamScreen()
        self.push_screen(param_screen, self.handle_param)

    def handle_param(self, result):
        self.notify(f"It {result}")

    @on(Button.Pressed, "#main_button")
    def execute_option_action(self, event: Button.Pressed) -> None:
        self.get_param()


if __name__ == "__main__":
    cyberClip = ClipBrowser()
    cyberClip.run()
Copy link

We found the following entry 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

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

1 participant