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

Button Action Parameter Not Detecting In Correct Namespace #5394

Open
ddkasa opened this issue Dec 14, 2024 · 4 comments
Open

Button Action Parameter Not Detecting In Correct Namespace #5394

ddkasa opened this issue Dec 14, 2024 · 4 comments

Comments

@ddkasa
Copy link
Contributor

ddkasa commented Dec 14, 2024

So it says this here

Textual will look for action methods in the class where they are defined (App, Screen, or Widget). If we were to create a custom widget it can have its own set of actions.

But after running the provided MRE no action gets detected for the buttons. Although if I set the namespace explicitly the action still works.

self.call_later(
self.app.run_action, self.action, default_namespace=self._parent
)

My suspicion is that the above default_namespace parameter is the culprit, as its pointing to the incorrect parent Screen(id="_default"), which doesn't contain the method. For example when I change it to self.app, as a band aid fix it works correctly. In my opinion it should search up the DOM to the active screen, until an action actually matches or if no explicit screen is set it should check the main app class last instead of a screen.

MRE

from textual.app import App
from textual.widgets import Button


class BugReportApp(App):
    BINDINGS = [("n", "notify_test")]

    def compose(self):
        yield Button("Broken", action="notify_test")
        yield Button("Works", action="app.notify_test")

    def _action_notify_test(self):
        self.notify("It works")


if __name__ == "__main__":
    BugReportApp().run()

Textual Diagnostics

Versions

Name Value
Textual 1.0.0
Rich 13.9.4

Python

Name Value
Version 3.12.3
Implementation CPython
Compiler GCC 13.2.1 20240316 (Red Hat 13.2.1-7)
Executable /home/dk/dev/tmp/t-button-action/.venv/bin/python

Operating System

Name Value
System Linux
Release 6.11.11-200.fc40.x86_64
Version #1 SMP PREEMPT_DYNAMIC Thu Dec 5 18:38:39 UTC 2024

Terminal

Name Value
Terminal Application Kitty
TERM xterm-kitty
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=137, height=54
legacy_windows False
min_width 1
max_width 137
is_terminal True
encoding utf-8
max_height 54
justify None
overflow None
no_wrap False
highlight None
markup None
height None
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

@darrenburns
Copy link
Member

darrenburns commented Dec 16, 2024

This was changed way back in https://github.com/Textualize/textual/releases/tag/v0.61.0 to make it a requirement that the namespace is specified. I think that's just some outdated documentation.

Changed in PR: #4516

@ddkasa
Copy link
Contributor Author

ddkasa commented Dec 16, 2024

I can create a PR adding a sentence specifying that a namespace is required if using the action parameter.

@anschweitzer
Copy link

The MRE for this example doesn't seem quite (See #5422). I wonder if that is relevant to this issue.

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

3 participants