-
I'm trying to have dynamic bindings based on current tab in TabbedContent. While there are ways to process existing global bindings taking into account the current tab, and there is a way to dynamically add binding there doesn't seem to be a way to unbind existing bindings dynamically. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
If you want specific bindings to only be available in a certain tab pane, or even the same key but bound in different ways in different tab panes, the usual way would be to make those bindings part of the pane. For example, here's 3 different tabs in a from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Footer, TabbedContent, TabPane, OptionList
class FooTab(TabPane):
BINDINGS = [
Binding("f1", "gndn", "Does a Foo"),
]
def compose(self) -> ComposeResult:
yield OptionList(*[f"Foo {n}" for n in range(100)])
class BarTab(TabPane):
BINDINGS = [
Binding("f1", "gndn", "Does a Bar"),
]
def compose(self) -> ComposeResult:
yield OptionList(*[f"Bar {n}" for n in range(100)])
class BazTab(TabPane):
BINDINGS = [
Binding("f1", "gndn", "Does a Baz"),
]
def compose(self) -> ComposeResult:
yield OptionList(*[f"Baz {n}" for n in range(100)])
class TabbedBindingsApp(App[None]):
CSS = """
OptionList {
height: 1fr;
}
"""
def compose(self) -> ComposeResult:
with TabbedContent():
yield FooTab("Foo")
yield BarTab("Bar")
yield BazTab("Baz")
yield Footer()
if __name__ == "__main__":
TabbedBindingsApp().run() |
Beta Was this translation helpful? Give feedback.
If you want specific bindings to only be available in a certain tab pane, or even the same key but bound in different ways in different tab panes, the usual way would be to make those bindings part of the pane. For example, here's 3 different tabs in a
TabbedContent
, each one has a binding for F1, but each one does different things: