This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Test code for Textualize/textual#2229
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""https://github.com/Textualize/textual/issues/2229""" | ||
|
||
from textual.app import App, ComposeResult | ||
from textual.binding import Binding | ||
from textual.containers import Vertical | ||
from textual.widgets import Header, Footer, TabbedContent, TabPane, Tabs, DirectoryTree | ||
|
||
class SelfFocusPane(TabPane): | ||
|
||
DEFAULT_CSS = """ | ||
SelfFocusPane { | ||
height: 100% !important; | ||
} | ||
DirectoryTree { | ||
width: 100%; | ||
height: 100% !important; | ||
} | ||
""" | ||
|
||
def compose( self ) -> ComposeResult: | ||
"""Compose the child widgets.""" | ||
yield DirectoryTree(".") | ||
|
||
def on_show( self ) -> None: | ||
self.query_one( DirectoryTree ).focus() | ||
|
||
class TabbedContentIssueApp( App[ None ] ): | ||
|
||
CSS = """ | ||
Screen { | ||
align: center middle; | ||
} | ||
Screen > Vertical { | ||
width: 42; | ||
} | ||
TabbedContent { | ||
border: round red; | ||
max-width: 40; | ||
height: 100%; | ||
} | ||
ContentSwitcher { | ||
height: 1fr !important; | ||
} | ||
""" | ||
|
||
BINDINGS = [ | ||
Binding( "shift+left", "previous", "Previous" ), | ||
Binding( "shift+right", "next", "Next" ), | ||
] | ||
|
||
def compose( self ) -> ComposeResult: | ||
yield Header() | ||
with Vertical(): | ||
with TabbedContent(): | ||
for n in range( 6 ): | ||
yield SelfFocusPane( f"Tab {n}") | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
self.query_one(Tabs).focus() | ||
|
||
def action_previous(self) -> None: | ||
self.query_one(Tabs).action_previous_tab() | ||
|
||
def action_next(self) -> None: | ||
self.query_one(Tabs).action_next_tab() | ||
|
||
if __name__ == "__main__": | ||
TabbedContentIssueApp().run() |