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 CSSvar CSS_PATH : CSSPathTypevar SCREENS : dict[str, Screen]var SUB_TITLE : str | Nonevar 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:actionaction_bellaction_focusaction_pop_screenaction_push_screenaction_quitaction_screenshotaction_switch_screenaction_toggle_darkadd_classancestorsanimateappbackground_colorsbellbindcall_latercapture_mousecheck_bindingscheck_idleclassescolorscomposecss_identifiercss_identifier_styledcss_path_nodesdarkdebugdisable_messagesdispatch_keydisplaydisplayed_childrenemitemit_no_waitenable_messagesexitexport_screenshotfatal_errorfocusedget_childget_component_stylesget_css_variablesget_default_cssget_driver_classget_pseudo_classesget_screenget_widget_athas_classhas_pseudo_classidinstall_screenis_headlessis_mountedis_screen_installedlogmountmount_allnamespace_bindingson_eventpanicparentpop_screenpost_messagepost_message_no_waitpseudo_classespush_screenqueryquery_onerefresh_cssremove_classreset_stylesrich_stylerunsave_screenshotscreenscreen_stackset_classset_focusset_intervalset_stylesset_timersizesub_titleswitch_screentext_styletitletoggle_classtreeuninstall_screenupdate_stylesvisiblewalk_childrenwatch_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:actionadd_classallow_horizontal_scrollallow_vertical_scrollancestorsanimateappauto_heightauto_linksauto_widthbackground_colorscall_latercapture_mousecheck_idleclassescolorscontainer_sizecontainer_viewportcontent_offsetcontent_regioncontent_sizecss_identifiercss_identifier_styledcss_path_nodesdisable_messagesdispatch_keydisplaydisplayed_childrenemitemit_no_waitenable_messagesexpandfocusfocusable_childrenget_childget_component_rich_styleget_component_stylesget_content_heightget_content_widthget_default_cssget_pseudo_classesget_style_atgutterhas_classhas_focushas_pseudo_classhorizontal_scrollbaridis_containeris_scrollableis_transparentlayerlayerslink_hover_stylelink_stylelogmax_scroll_xmax_scroll_ymountmouse_overoffseton_eventouter_sizeparentpost_messagepost_message_no_waitpost_renderpseudo_classesqueryquery_onerefreshregionrelease_mouseremoveremove_classrenderrender_linerender_linesreset_focusreset_stylesrich_stylescreenscroll_downscroll_endscroll_homescroll_leftscroll_offsetscroll_page_downscroll_page_leftscroll_page_rightscroll_page_upscroll_relativescroll_rightscroll_target_xscroll_target_yscroll_toscroll_to_regionscroll_to_widgetscroll_upscroll_visiblescroll_xscroll_yscrollbar_cornerscrollbar_gutterscrollbar_size_horizontalscrollbar_size_verticalscrollbars_enabledset_classset_intervalset_stylesset_timershow_horizontal_scrollbarshow_vertical_scrollbarshrinksiblingssizetext_styletoggle_classtreevertical_scrollbarvirtual_regionvirtual_region_with_marginvirtual_sizevisiblevisible_siblingswalk_childrenwatch_has_focuswatch_mouse_overwindow_region
Widget: