-
Notifications
You must be signed in to change notification settings - Fork 815
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
dynamic bindings #4516
dynamic bindings #4516
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few suggestions where I spotted some typos in the docs - hope you don't mind!
Co-authored-by: TomJGooding <[email protected]>
Co-authored-by: TomJGooding <[email protected]>
Sorry also just a quick question which I've seen asked before relating to dynamic bindings. What would be the most practical way with this new feature of hiding bindings when an from textual.app import App, ComposeResult
from textual.widgets import Input, Footer, Button
class ExampleApp(App):
CSS = """
Screen {
align: center middle;
}
Input {
width: 16;
}
"""
BINDINGS = [
("a", "notify_binding('a')", "A"),
("b", "notify_binding('b')", "B"),
("c", "notify_binding('c')", "C"),
("f1", "notify_binding('F1')", "F1"),
("f2", "notify_binding('F2')", "F2"),
("f3", "notify_binding('F3')", "F3"),
]
def compose(self) -> ComposeResult:
yield Button()
yield Input(placeholder="Input")
yield Footer()
def action_notify_binding(self, key: str) -> None:
self.notify(f"You pressed {key}")
if __name__ == "__main__":
app = ExampleApp()
app.run() |
I wonder if an exception should be added for Ctrl+c to quit the app, and maybe other default actions? If you wanted to hide all (custom) bindings when a particular widget was focussed for example, you could easily forget to add this check. |
😍 |
The issue there is that inputs capture most keys with the Key event, which bypasses bindings. You could do the following: def check_action(self, name, params):
if name == "notify_binding" and isinstance(self.focused, Input):
return False
return True But that does mean you would have to modify the app. Ideally there would be a mechanism for the widget itself to declare it will capture those keys. |
I can't see that being much of an issue. As long as you default to return |
Perhaps just worth a note in the docs explaining that this also applies to builtin actions? For example using the def check_action(self, name, params):
if isinstance(self.focused, Input):
return False
return True |
Glancing over this just now, I wonder if #3690 is at least partially satisfied by this PR. |
Stab at dynamic bindings
Wedding present for @darrenburns