Module textual.cli.previews.borders
Expand source code
from textual.app import App, ComposeResult
from textual.constants import BORDERS
from textual.widgets import Button, Static
from textual.containers import Vertical
TEXT = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear.
I will permit it to pass over me and through me.
And when it has gone past, I will turn the inner eye to see its path.
Where the fear has gone there will be nothing. Only I will remain."""
class BorderButtons(Vertical):
DEFAULT_CSS = """
BorderButtons {
dock: left;
width: 24;
overflow-y: scroll;
}
BorderButtons > Button {
width: 100%;
}
"""
def compose(self) -> ComposeResult:
for border in BORDERS:
if border:
yield Button(border, id=border)
class BorderApp(App):
"""Demonstrates the border styles."""
CSS = """
#text {
margin: 2 4;
padding: 2 4;
border: solid $secondary;
height: auto;
background: $panel;
color: $text;
}
"""
def compose(self):
yield BorderButtons()
self.text = Static(TEXT, id="text")
yield self.text
def on_button_pressed(self, event: Button.Pressed) -> None:
self.text.styles.border = (
event.button.id,
self.stylesheet._variables["secondary"],
)
self.bell()
app = BorderApp()
if __name__ == "__main__":
app.run()
Classes
class BorderApp (driver_class: Type[Driver] | None = None, css_path: CSSPathType = None, watch_css: bool = False)
-
Demonstrates the border styles.
Expand source code
class BorderApp(App): """Demonstrates the border styles.""" CSS = """ #text { margin: 2 4; padding: 2 4; border: solid $secondary; height: auto; background: $panel; color: $text; } """ def compose(self): yield BorderButtons() self.text = Static(TEXT, id="text") yield self.text def on_button_pressed(self, event: Button.Pressed) -> None: self.text.styles.border = ( event.button.id, self.stylesheet._variables["secondary"], ) self.bell()
Ancestors
- App
- typing.Generic
- DOMNode
- MessagePump
Class variables
var CSS
var CSS_PATH : CSSPathType
var SCREENS : dict[str, Screen]
var SUB_TITLE : str | None
var TITLE : str | None
Methods
-
Expand source code
def on_button_pressed(self, event: Button.Pressed) -> None: self.text.styles.border = ( event.button.id, self.stylesheet._variables["secondary"], ) self.bell()
Inherited members
App
:action
action_bell
action_focus
action_pop_screen
action_push_screen
action_quit
action_screenshot
action_switch_screen
action_toggle_dark
add_class
ancestors
animate
app
background_colors
bell
bind
call_later
capture_mouse
check_bindings
check_idle
classes
colors
compose
css_identifier
css_identifier_styled
css_path_nodes
dark
debug
disable_messages
dispatch_key
display
displayed_children
emit
emit_no_wait
enable_messages
exit
export_screenshot
fatal_error
focused
get_child
get_component_styles
get_css_variables
get_default_css
get_driver_class
get_pseudo_classes
get_screen
get_widget_at
has_class
has_pseudo_class
id
install_screen
is_headless
is_mounted
is_screen_installed
log
mount
mount_all
namespace_bindings
on_event
panic
parent
pop_screen
post_message
post_message_no_wait
pseudo_classes
push_screen
query
query_one
refresh_css
remove_class
reset_styles
rich_style
run
save_screenshot
screen
screen_stack
set_class
set_focus
set_interval
set_styles
set_timer
size
sub_title
switch_screen
text_style
title
toggle_class
tree
uninstall_screen
update_styles
visible
walk_children
watch_dark
class BorderButtons (*children: Widget, name: str | None = None, id: str | None = None, classes: str | None = None)
-
A container widget which aligns children vertically.
Expand source code
class BorderButtons(Vertical): DEFAULT_CSS = """ BorderButtons { dock: left; width: 24; overflow-y: scroll; } BorderButtons > Button { width: 100%; } """ def compose(self) -> ComposeResult: for border in BORDERS: if border: yield Button(border, id=border)
Ancestors
Class variables
var COMPONENT_CLASSES : ClassVar[set[str]]
var DEFAULT_CSS
Inherited members
Vertical
:Vertical
:action
add_class
allow_horizontal_scroll
allow_vertical_scroll
ancestors
animate
app
auto_height
auto_links
auto_width
background_colors
call_later
capture_mouse
check_idle
classes
colors
container_size
container_viewport
content_offset
content_region
content_size
css_identifier
css_identifier_styled
css_path_nodes
disable_messages
dispatch_key
display
displayed_children
emit
emit_no_wait
enable_messages
expand
focus
focusable_children
get_child
get_component_rich_style
get_component_styles
get_content_height
get_content_width
get_default_css
get_pseudo_classes
get_style_at
gutter
has_class
has_focus
has_pseudo_class
horizontal_scrollbar
id
is_container
is_scrollable
is_transparent
layer
layers
link_hover_style
link_style
log
max_scroll_x
max_scroll_y
mount
mouse_over
offset
on_event
outer_size
parent
post_message
post_message_no_wait
post_render
pseudo_classes
query
query_one
refresh
region
release_mouse
remove
remove_class
render
render_line
render_lines
reset_focus
reset_styles
rich_style
screen
scroll_down
scroll_end
scroll_home
scroll_left
scroll_offset
scroll_page_down
scroll_page_left
scroll_page_right
scroll_page_up
scroll_relative
scroll_right
scroll_target_x
scroll_target_y
scroll_to
scroll_to_region
scroll_to_widget
scroll_up
scroll_visible
scroll_x
scroll_y
scrollbar_corner
scrollbar_gutter
scrollbar_size_horizontal
scrollbar_size_vertical
scrollbars_enabled
set_class
set_interval
set_styles
set_timer
show_horizontal_scrollbar
show_vertical_scrollbar
shrink
siblings
size
text_style
toggle_class
tree
vertical_scrollbar
virtual_region
virtual_region_with_margin
virtual_size
visible
visible_siblings
walk_children
watch_has_focus
watch_mouse_over
window_region
Widget
: