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 failing #4536

Closed
darrenburns opened this issue May 21, 2024 · 3 comments · Fixed by #4540
Closed

Action lookup failing #4536

darrenburns opened this issue May 21, 2024 · 3 comments · Fixed by #4540
Labels
bug Something isn't working

Comments

@darrenburns
Copy link
Member

darrenburns commented May 21, 2024

Since updating from 0.60.0 to 0.62.0, my screen namespaced action has broken despite no other changes.

The method names that are being looked up are no longer correctly accounting for namespaces in some circumstances:

<action> 'app.bell' has no target. Could not find methods '_action_app.bell' or
'action_app.bell'
<action> 'screen.foo' has no target. Could not find methods '_action_screen.foo' or
'action_screen.foo'

I think the namespace is not actually being used, and methods like action_app.bell are being looked up on the current widget/screen/app.

(Aside: It'd be nice if those logs told us where we're looking for the methods)

First issue

I expect the following app to ring the bell via App.action_bell, however nothing happens.

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=app.bell]Ring the bell![/]")

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

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

If I change app.bell to bell, it works, which is also surprising to me (I thought it would no longer look up the app namespace).

Second issue which may be the same issue

Why does the foo action defined on my App fire here, even though I'm using @click=foo and not @click=app.foo?

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]Ring the bell![/]")  # this fires the action on app?!

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

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

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

If I move the action_foo into my screen, and update the markup to use @click=screen.foo, it still doesn't fire.

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=screen.foo]Ring the bell![/]")

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

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

if __name__ == "__main__":
    app = ScreenNamespace()
    app.run()
@darrenburns darrenburns added the bug Something isn't working label May 21, 2024
@davep
Copy link
Contributor

davep commented May 21, 2024

Probably cross reference #4534 too.

@davep
Copy link
Contributor

davep commented May 21, 2024

Also #3690 is probably relevant here too (as a longer-term issue that seems to relate to part of this).

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.

2 participants