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

Action lookup problems on 0.63.1 #4544

Closed
darrenburns opened this issue May 22, 2024 · 1 comment · Fixed by #4546
Closed

Action lookup problems on 0.63.1 #4544

darrenburns opened this issue May 22, 2024 · 1 comment · Fixed by #4546
Labels
bug Something isn't working

Comments

@darrenburns
Copy link
Member

In Elia, I have a few places where you click a link and it fires an action.

My action methods are usually located at the screen level.

On the latest version (0.63.1), all of my links are broken and have lookup failures which look like this in the logs:

[21:30:52] SYSTEM                                                                  app.py:3146
<action> 'foo' has no target. Could not find methods '_action_foo' or 'action_foo'

In the latest version of Textual, I think actions are always being looked up on the App, regardless of the namespace used.

In the example app below, note that output is always The action fired on APP! - the action method on the screen never fires.

from textual import __version__
from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Label

class HomeScreen(Screen[None]):
    def compose(self) -> ComposeResult:
        yield Label(f"Textual version: {__version__}")
        yield Label("[@click=foo]Fire action (@click=foo)![/]")
        yield Label("[@click=app.foo]Fire action (@click=app.foo)![/]")
        yield Label("[@click=screen.foo]Fire action (@click=screen.foo)![/]")

    def action_foo(self) -> None:
        self.app.panic("The action fired on SCREEN!")

class ActionNamespaceBug(App[None]):
    def get_default_screen(self) -> HomeScreen:
        return HomeScreen()

    def action_foo(self) -> None:
        self.app.panic("The action fired on APP!")

if __name__ == "__main__":
    app = ActionNamespaceBug()
    app.run()
@darrenburns darrenburns added the bug Something isn't working label May 22, 2024
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant