buffalo_panel.app.tui.SimulationTree

class buffalo_panel.app.tui.SimulationTree(label, data=None, *, name=None, id=None, classes=None, disabled=False)[source]

Bases: Tree[SimulationNodeData]

Widget for navigating the simulation configuration hierarchy.

Methods

find_node_by_path(path)

Return the first tree node whose stored path matches path.

rebuild(manager[, cursor_path])

Re-populate the tree from the current simulation data.

Attributes

ALLOW_MAXIMIZE

Defines default logic to allow the widget to be maximized.

ALLOW_SELECT

Does this widget support automatic text selection? May be further refined with [Widget.allow_select][textual.widget.Widget.allow_select].

BINDING_GROUP_TITLE

Title of widget used where bindings are displayed (such as in the key panel).

BLANK

Is this widget blank (no border, no content)? Enable for very large scrolling containers.

BORDER_SUBTITLE

Initial value for border_subtitle attribute.

BORDER_TITLE

Initial value for border_title attribute.

COMPONENT_CLASSES

DEFAULT_CLASSES

Default classes argument if not supplied.

DEFAULT_CSS

Default TCSS.

FOCUS_ON_CLICK

Should focusable widgets be automatically focused on click? Default return value of [Widget.focus_on_click][textual.widget.Widget.focus_on_click].

HELP

Optional help text shown in help panel (Markdown format).

ICON_NODE

Unicode 'icon' to use for an expandable node.

ICON_NODE_EXPANDED

Unicode 'icon' to use for an expanded node.

LINES

SCOPED_CSS

Should default css be limited to the widget type?

allow_horizontal_scroll

Check if horizontal scroll is permitted.

allow_maximize

Check if the widget may be maximized.

allow_select

Check if this widget permits text selection.

allow_vertical_scroll

Check if vertical scroll is permitted.

ancestors

A list of ancestor nodes found by tracing a path all the way back to App.

ancestors_with_self

A list of ancestor nodes found by tracing a path all the way back to App.

app

Get the current app.

auto_refresh

Number of seconds between automatic refresh, or None for no automatic refresh.

background_colors

Background colors adjusted for opacity.

border_subtitle

A title to show in the bottom border (if there is one).

border_title

A title to show in the top border (if there is one).

can_focus

Widget may receive focus.

can_focus_children

Widget's children may receive focus.

children

A view on to the children.

colors

The widget's background and foreground colors, and the parent's background and foreground colors.

container_scroll_offset

The scroll offset the nearest container ancestor.

container_size

The size of the container (parent widget).

container_viewport

The viewport region (parent window).

content_offset

An offset from the Widget origin where the content begins.

content_region

Gets an absolute region containing the content (minus padding and border).

content_size

The size of the content area.

css_identifier

A CSS selector that identifies this DOM node.

css_identifier_styled

A syntax highlighted CSS identifier.

css_path_nodes

A list of nodes from the App to this node, forming a "path".

css_tree

A Rich tree to display the DOM, annotated with the node's CSS.

cursor_node

The currently selected node, or None if no selection.

display

Should the DOM node be displayed?

displayed_and_visible_children

The displayed children (where node.display==True and node.visible==True).

displayed_children

The displayed children (where node.display==True).

dock_gutter

Space allocated to docks in the parent.

first_child

Is this the first widget in its siblings?

first_of_type

Is this the first widget of its type in its siblings?

focusable

Can this widget currently be focused?

gutter

Spacing for padding / border / scrollbars.

has_focus_within

Are any descendants focused?

has_parent

Does this object have a parent?

horizontal_scrollbar

The horizontal scrollbar.

id

The ID of this node, or None if the node has no ID.

is_anchored

Is this widget anchored?

is_attached

Is this node linked to the app through the DOM?

is_container

Since a ScrollView should be a line-api widget, it won't have children, and therefore isn't a container.

is_disabled

Is the widget disabled either because disabled=True or an ancestor has disabled=True.

is_dom_root

Is this a root node (i.e. the App)?.

is_empty

Are there no displayed children?

is_even

Is this widget at an evenly numbered position within its siblings?

is_horizontal_scroll_end

Is the horizontal scroll position at the maximum?

is_horizontal_scrollbar_grabbed

Is the user dragging the vertical scrollbar?

is_in_maximized_view

Is this widget, or a parent maximized?

is_maximized

Is this widget maximized?

is_modal

Is the node a modal?

is_mounted

Check if this widget is mounted.

is_mouse_over

Is the mouse currently over this widget?

is_odd

Is this widget at an oddly numbered position within its siblings?

is_on_screen

Check if the node was displayed in the last screen update.

is_parent_active

Is the parent active?

is_running

Is the message pump running (potentially processing messages)?

is_scrollable

Always scrollable.

is_scrolling

Is this widget currently scrolling?

is_vertical_scroll_end

Is the vertical scroll position at the maximum?

is_vertical_scrollbar_grabbed

Is the user dragging the vertical scrollbar?

last_child

Is this the last widget in its siblings?

last_line

The index of the last line.

last_of_type

Is this the last widget of its type in its siblings?

layer

Get the name of this widgets layer.

layers

Layers of from parent.

layout

Get the layout object if set in styles, or a default layout.

link_style

Style of links.

link_style_hover

Style of links underneath the mouse cursor.

log

Get a logger for this object.

max_scroll_x

The maximum value of scroll_x.

max_scroll_y

The maximum value of scroll_y.

message_queue_size

The current size of the message queue.

name

The name of the node.

offset

Widget offset from origin.

opacity

Total opacity of widget.

outer_size

The size of the widget (including padding and border).

parent

The parent node.

pseudo_classes

A (frozen) set of all pseudo classes.

region

The region occupied by this widget, relative to the Screen.

rich_style

Get a Rich Style object for this DOMNode.

screen

The screen containing this node.

scroll_offset

Get the current scroll offset.

scrollable_content_region

Gets an absolute region containing the scrollable content (minus padding, border, and scrollbars).

scrollable_size

The size of the scrollable content.

scrollbar_corner

The scrollbar corner.

scrollbar_gutter

Spacing required to fit scrollbar(s).

scrollbar_size_horizontal

Get the height used by the horizontal scrollbar.

scrollbar_size_vertical

Get the width used by the vertical scrollbar.

scrollbars_enabled

A tuple of booleans that indicate if scrollbars are enabled.

scrollbars_space

The number of cells occupied by scrollbars for width and height

select_container

The widget's container used when selecting text..

selection_style

The style of selected text.

siblings

Get the widget's siblings (self is removed from the return list).

size

The size of the content area.

task

text_selection

Text selection information, or None if no text is selected in this widget.

text_style

Get the text style object.

tooltip

Tooltip for the widget, or None for no tooltip.

tree

A Rich tree to display the DOM.

vertical_scrollbar

The vertical scrollbar (create if necessary).

virtual_region

The widget region relative to its container (which may not be visible, depending on scroll offset).

virtual_region_with_margin

The widget region relative to its container (including margin), which may not be visible, depending on the scroll offset.

visible

Is this widget visible in the DOM?

visible_siblings

A list of siblings which will be shown.

visual_style

The widget's current style.

window_region

The region within the scrollable area that is currently visible.

workers

The app's worker manager.

root

The root node of the tree.

absolute_offset

Force an absolute offset for the widget (used by tooltips).

lock

asyncio lock to be used to synchronize the state of the widget.

classes

CSS class names for this node.

message_signal

Subscribe to this signal to be notified of all messages sent to this widget.

rebuild(manager, cursor_path=None)[source]

Re-populate the tree from the current simulation data.

find_node_by_path(path)[source]

Return the first tree node whose stored path matches path.

Return type:

TreeNode[SimulationNodeData] | None

ALLOW_MAXIMIZE: ClassVar[bool | None] = True

Defines default logic to allow the widget to be maximized.

  • None Use default behavior (Focusable widgets may be maximized)

  • False Do not allow widget to be maximized

  • True Allow widget to be maximized

ALLOW_SELECT: ClassVar[bool] = False

Does this widget support automatic text selection? May be further refined with [Widget.allow_select][textual.widget.Widget.allow_select].

BINDING_GROUP_TITLE: str | None = None

Title of widget used where bindings are displayed (such as in the key panel).

BLANK: ClassVar[bool] = False

Is this widget blank (no border, no content)? Enable for very large scrolling containers.

BORDER_SUBTITLE: ClassVar[str] = ''

Initial value for border_subtitle attribute.

BORDER_TITLE: ClassVar[str] = ''

Initial value for border_title attribute.

COMPONENT_CLASSES: ClassVar[set[str]] = {'tree--cursor', 'tree--guides', 'tree--guides-hover', 'tree--guides-selected', 'tree--highlight', 'tree--highlight-line', 'tree--label'}
Class | Description |
:- | :- |
tree–cursor | Targets the cursor. |
tree–guides | Targets the indentation guides. |
tree–guides-hover | Targets the indentation guides under the cursor. |
tree–guides-selected | Targets the indentation guides that are selected. |
tree–highlight | Targets the highlighted items. |
tree–highlight-line | Targets the lines under the cursor. |
tree–label | Targets the (text) labels of the items. |
DEFAULT_CLASSES: ClassVar[str] = ''

Default classes argument if not supplied.

DEFAULT_CSS: ClassVar[str] = '\n    Tree {\n        background: $surface;\n        color: $foreground;\n\n        & > .tree--label {}\n        & > .tree--guides {\n            color: $surface-lighten-2;\n        }\n        & > .tree--guides-hover {\n            color: $surface-lighten-2;\n        }\n        & > .tree--guides-selected {\n            color: $block-cursor-blurred-background;\n        }\n        & > .tree--cursor {\n            text-style: $block-cursor-blurred-text-style;\n            background: $block-cursor-blurred-background;\n        }\n        & > .tree--highlight {}\n        & > .tree--highlight-line {\n            background: $block-hover-background;\n        }\n\n        &:focus {\n            background-tint: $foreground 5%;\n            & > .tree--cursor {\n                color: $block-cursor-foreground;\n                background: $block-cursor-background;\n                text-style: $block-cursor-text-style;\n            }\n            & > .tree--guides {\n                color: $surface-lighten-3;\n            }\n            & > .tree--guides-hover {\n                color: $surface-lighten-3;\n            }\n            & > .tree--guides-selected {\n                color: $block-cursor-background;\n            }\n        }\n\n        &:light {\n            /* In light mode the guides are darker*/\n            & > .tree--guides {\n                color: $surface-darken-1;\n            }\n            & > .tree--guides-hover {\n                color: $block-cursor-background;\n            }\n            & > .tree--guides-selected {\n                color: $block-cursor-background;\n            }\n        }\n\n\n    }\n    Tree:ansi {\n        color: ansi_default;\n        & > .tree--guides {\n            color: $ansi-background;\n        }\n        &:nocolor > .tree--cursor{\n            text-style: reverse;\n        }        \n    }\n    \n    '

Default TCSS.

FOCUS_ON_CLICK: ClassVar[bool] = True

Should focusable widgets be automatically focused on click? Default return value of [Widget.focus_on_click][textual.widget.Widget.focus_on_click].

HELP: ClassVar[str | None] = None

Optional help text shown in help panel (Markdown format).

ICON_NODE = '▶ '

Unicode ‘icon’ to use for an expandable node.

ICON_NODE_EXPANDED = '▼ '

Unicode ‘icon’ to use for an expanded node.

SCOPED_CSS: ClassVar[bool] = True

Should default css be limited to the widget type?

property allow_horizontal_scroll: bool

Check if horizontal scroll is permitted.

May be overridden if you want different logic regarding allowing scrolling.

property allow_maximize: bool

Check if the widget may be maximized.

Returns:

True if the widget may be maximized, or False if it should not be maximized.

property allow_select: bool

Check if this widget permits text selection.

Returns:

True if the widget supports text selection, otherwise False.

property allow_vertical_scroll: bool

Check if vertical scroll is permitted.

May be overridden if you want different logic regarding allowing scrolling.

property ancestors: list[DOMNode]

A list of ancestor nodes found by tracing a path all the way back to App.

Returns:

A list of nodes.

property ancestors_with_self: list[DOMNode]

A list of ancestor nodes found by tracing a path all the way back to App.

Note:

This is inclusive of self.

Returns:

A list of nodes.

property app: App[object]

Get the current app.

Returns:

The current app.

Raises:

NoActiveAppError: if no active app could be found for the current asyncio context

property auto_refresh: float | None

Number of seconds between automatic refresh, or None for no automatic refresh.

property background_colors: tuple[Color, Color]

Background colors adjusted for opacity.

Returns:

(<background color>, <color>)

border_subtitle = None

A title to show in the bottom border (if there is one).

border_title = None

A title to show in the top border (if there is one).

can_focus: bool = True

Widget may receive focus.

can_focus_children: bool = True

Widget’s children may receive focus.

property children: Sequence['Widget']

A view on to the children.

Returns:

The node’s children.

property colors: tuple[Color, Color, Color, Color]

The widget’s background and foreground colors, and the parent’s background and foreground colors.

Returns:

(<parent background>, <parent color>, <background>, <color>)

property container_scroll_offset: Offset

The scroll offset the nearest container ancestor.

property container_size: Size

The size of the container (parent widget).

Returns:

Container size.

property container_viewport: Region

The viewport region (parent window).

Returns:

The region that contains this widget.

property content_offset: Offset

An offset from the Widget origin where the content begins.

Returns:

Offset from widget’s origin.

property content_region: Region

Gets an absolute region containing the content (minus padding and border).

Returns:

Screen region that contains a widget’s content.

property content_size: Size

The size of the content area.

Returns:

Content area size.

property css_identifier: str

A CSS selector that identifies this DOM node.

property css_identifier_styled: Text

A syntax highlighted CSS identifier.

Returns:

A Rich Text object.

property css_path_nodes: list[DOMNode]

A list of nodes from the App to this node, forming a “path”.

Returns:

A list of nodes, where the first item is the App, and the last is this node.

property css_tree: Tree

A Rich tree to display the DOM, annotated with the node’s CSS.

Log this to visualize your app in the textual console.

Example:

`python self.log(self.css_tree) `

Returns:

A Tree renderable.

property cursor_node: TreeNode[TreeDataType] | None

The currently selected node, or None if no selection.

property display: bool

Should the DOM node be displayed?

May be set to a boolean to show or hide the node, or to any valid value for the display rule.

Example:

`python my_widget.display = False  # Hide my_widget `

property displayed_and_visible_children: Sequence[Widget]

The displayed children (where node.display==True and node.visible==True).

Returns:

A sequence of widgets.

property displayed_children: Sequence[Widget]

The displayed children (where node.display==True).

Returns:

A sequence of widgets.

property dock_gutter: Spacing

Space allocated to docks in the parent.

Returns:

Space to be subtracted from scrollable area.

property first_child: bool

Is this the first widget in its siblings?

property first_of_type: bool

Is this the first widget of its type in its siblings?

property focusable: bool

Can this widget currently be focused?

property gutter: Spacing

Spacing for padding / border / scrollbars.

Returns:

Additional spacing around content area.

property has_focus_within: bool

Are any descendants focused?

property has_parent: bool

Does this object have a parent?

property horizontal_scrollbar: ScrollBar

The horizontal scrollbar.

Note:

This will create a scrollbar if one doesn’t exist.

Returns:

ScrollBar Widget.

property id: str | None

The ID of this node, or None if the node has no ID.

property is_anchored: bool

Is this widget anchored?

See [anchor()][textual.widget.Widget.anchor] for an explanation of anchoring.

property is_attached: bool

Is this node linked to the app through the DOM?

property is_container: bool

Since a ScrollView should be a line-api widget, it won’t have children, and therefore isn’t a container.

property is_disabled: bool

Is the widget disabled either because disabled=True or an ancestor has disabled=True.

property is_dom_root

Is this a root node (i.e. the App)?

property is_empty: bool

Are there no displayed children?

property is_even: bool

Is this widget at an evenly numbered position within its siblings?

property is_horizontal_scroll_end: bool

Is the horizontal scroll position at the maximum?

property is_horizontal_scrollbar_grabbed: bool

Is the user dragging the vertical scrollbar?

property is_in_maximized_view: bool

Is this widget, or a parent maximized?

property is_maximized: bool

Is this widget maximized?

property is_modal: bool

Is the node a modal?

property is_mounted: bool

Check if this widget is mounted.

property is_mouse_over: bool

Is the mouse currently over this widget?

Note this will be True if the mouse pointer is within the widget’s region, even if the mouse pointer is not directly over the widget (there could be another widget between the mouse pointer and self).

property is_odd: bool

Is this widget at an oddly numbered position within its siblings?

property is_on_screen: bool

Check if the node was displayed in the last screen update.

property is_parent_active: bool

Is the parent active?

property is_running: bool

Is the message pump running (potentially processing messages)?

property is_scrollable: bool

Always scrollable.

property is_scrolling: bool

Is this widget currently scrolling?

property is_vertical_scroll_end: bool

Is the vertical scroll position at the maximum?

property is_vertical_scrollbar_grabbed: bool

Is the user dragging the vertical scrollbar?

property last_child: bool

Is this the last widget in its siblings?

property last_line: int

The index of the last line.

property last_of_type: bool

Is this the last widget of its type in its siblings?

property layer: str

Get the name of this widgets layer.

Returns:

Name of layer.

property layers: tuple[str, ...]

Layers of from parent.

Returns:

Tuple of layer names.

property layout: Layout

Get the layout object if set in styles, or a default layout.

Returns:

A layout object.

Style of links.

Returns:

Rich style.

Style of links underneath the mouse cursor.

Returns:

Rich Style.

property log: Logger

Get a logger for this object.

Returns:

A logger.

property max_scroll_x: int

The maximum value of scroll_x.

property max_scroll_y: int

The maximum value of scroll_y.

property message_queue_size: int

The current size of the message queue.

property name: str | None

The name of the node.

property offset: Offset

Widget offset from origin.

Returns:

Relative offset.

property opacity: float

Total opacity of widget.

property outer_size: Size

The size of the widget (including padding and border).

Returns:

Outer size.

property parent: DOMNode | None

The parent node.

All nodes have parent once added to the DOM, with the exception of the App which is the root node.

property pseudo_classes: frozenset[str]

A (frozen) set of all pseudo classes.

property region: Region

The region occupied by this widget, relative to the Screen.

Returns:

Region within screen occupied by widget.

property rich_style: Style

Get a Rich Style object for this DOMNode.

Returns:

A Rich style.

property screen: Screen[object]

The screen containing this node.

Returns:

A screen object.

Raises:

NoScreen: If this node isn’t mounted (and has no screen).

property scroll_offset: Offset

Get the current scroll offset.

Returns:

Offset a container has been scrolled by.

property scrollable_content_region: Region

Gets an absolute region containing the scrollable content (minus padding, border, and scrollbars).

Returns:

Screen region that contains a widget’s content.

property scrollable_size: Size

The size of the scrollable content.

Returns:

Scrollable content size.

property scrollbar_corner: ScrollBarCorner

The scrollbar corner.

Note:

This will create a scrollbar corner if one doesn’t exist.

Returns:

ScrollBarCorner Widget.

property scrollbar_gutter: Spacing

Spacing required to fit scrollbar(s).

Returns:

Scrollbar gutter spacing.

property scrollbar_size_horizontal: int

Get the height used by the horizontal scrollbar.

Returns:

Number of rows in the horizontal scrollbar.

property scrollbar_size_vertical: int

Get the width used by the vertical scrollbar.

Returns:

Number of columns in the vertical scrollbar.

property scrollbars_enabled: tuple[bool, bool]

A tuple of booleans that indicate if scrollbars are enabled.

Returns:

A tuple of (<vertical scrollbar enabled>, <horizontal scrollbar enabled>)

property scrollbars_space: tuple[int, int]

The number of cells occupied by scrollbars for width and height

property select_container: Widget

The widget’s container used when selecting text..

Returns:

A widget which contains this widget.

property selection_style: Style

The style of selected text.

property siblings: list[Widget]

Get the widget’s siblings (self is removed from the return list).

Returns:

A list of siblings.

property size: Size

The size of the content area.

Returns:

Content area size.

property text_selection: Selection | None

Text selection information, or None if no text is selected in this widget.

property text_style: Style

Get the text style object.

A widget’s style is influenced by its parent. for instance if a parent is bold, then the child will also be bold.

Returns:

A Rich Style.

property tooltip: VisualType | None

Tooltip for the widget, or None for no tooltip.

property tree: Tree

A Rich tree to display the DOM.

Log this to visualize your app in the textual console.

Example:

`python self.log(self.tree) `

Returns:

A Tree renderable.

property vertical_scrollbar: ScrollBar

The vertical scrollbar (create if necessary).

Note:

This will create a scrollbar if one doesn’t exist.

Returns:

ScrollBar Widget.

property virtual_region: Region

The widget region relative to its container (which may not be visible, depending on scroll offset).

Returns:

The virtual region.

property virtual_region_with_margin: Region

The widget region relative to its container (including margin), which may not be visible, depending on the scroll offset.

Returns:

The virtual region of the Widget, inclusive of its margin.

property visible: bool

Is this widget visible in the DOM?

If a widget hasn’t had its visibility set explicitly, then it inherits it from its DOM ancestors.

This may be set explicitly to override inherited values. The valid values include the valid values for the visibility rule and the booleans True or False, to set the widget to be visible or invisible, respectively.

When a node is invisible, Textual will reserve space for it, but won’t display anything.

property visible_siblings: list[Widget]

A list of siblings which will be shown.

Returns:

List of siblings.

property visual_style: Style

The widget’s current style.

property window_region: Region

The region within the scrollable area that is currently visible.

Returns:

New region.

property workers: WorkerManager

The app’s worker manager. Shortcut for self.app.workers.

root

The root node of the tree.

absolute_offset: Offset | None

Force an absolute offset for the widget (used by tooltips).

lock

asyncio lock to be used to synchronize the state of the widget.

Two different tasks might call methods on a widget at the same time, which might result in a race condition. This can be fixed by adding async with widget.lock: around the method calls.

classes

CSS class names for this node.

message_signal: Signal[Message]

Subscribe to this signal to be notified of all messages sent to this widget.

This is a fairly low-level mechanism, and shouldn’t replace regular message handling.