-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67e9294
commit 0b07ab6
Showing
3 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.binding import Binding | ||
from textual.widget import Widget | ||
from textual.widgets import Button, Footer | ||
|
||
|
||
async def test_footer_bindings() -> None: | ||
app_binding_count = 0 | ||
|
||
class TestWidget(Widget, can_focus=True): | ||
BINDINGS = [ | ||
Binding("b", "widget_binding", "Overridden Binding"), | ||
] | ||
|
||
DEFAULT_CSS = """ | ||
TestWidget { | ||
border: tall $background; | ||
width: 50%; | ||
height: 50%; | ||
content-align: center middle; | ||
&:focus { | ||
border: tall $accent; | ||
} | ||
} | ||
""" | ||
|
||
def action_widget_binding(self) -> None: | ||
assert False, "should never be called since there is a priority binding" | ||
|
||
class PriorityBindingApp(App): | ||
BINDINGS = [ | ||
Binding("b", "app_binding", "Priority Binding", priority=True), | ||
] | ||
|
||
CSS = """ | ||
Screen { | ||
align: center middle; | ||
} | ||
""" | ||
|
||
def compose(self) -> ComposeResult: | ||
yield TestWidget() | ||
yield Button("Move Focus") | ||
yield Footer() | ||
|
||
def action_app_binding(self) -> None: | ||
nonlocal app_binding_count | ||
app_binding_count += 1 | ||
|
||
app = PriorityBindingApp() | ||
async with app.run_test() as pilot: | ||
await pilot.pause() | ||
assert app_binding_count == 0 | ||
await pilot.click("Footer", offset=(1, 0)) | ||
assert app_binding_count == 1 | ||
await pilot.click("Footer") | ||
assert app_binding_count == 2 |