Skip to content

Dom node

Bases: MessagePump

The base class for object that can be in the Textual DOM (App and Widget)

add_class(*class_names)

Add class names to this Node.

Parameters:

Name Type Description Default
*class_names str

CSS class names to add.

()

ancestors() property

list[DOMNode]: A list of ancestor nodes Nodes by tracing ancestors all the way back to App.

ancestors_with_self() property

list[DOMNode]: A list of Nodes by tracing a path all the way back to App.

Note: This is inclusive of self.

background_colors() property

Get the background color and the color of the parent's background.

Returns:

Type Description
tuple[Color, Color]

tuple[Color, Color]: Tuple of (base background, background)

classes() property

frozenset[str]: A frozenset of the current classes set on the widget.

colors() property

Gets the Widgets foreground and background colors, and its parent's (base) colors.

Returns:

Type Description
tuple[Color, Color, Color, Color]

tuple[Color, Color, Color, Color]: Tuple of (base background, base color, background, color)

css_identifier() property

css_identifier_styled() property

css_path_nodes() property

list[DOMNode] A list of nodes from the root to this node, forming a "path".

display() property writable

Check if this widget should display or not.

Returns:

Name Type Description
bool bool

True if this DOMNode is displayed (display != "none") otherwise False .

displayed_children() property

The children which don't have display: none set.

Returns:

Type Description
list[Widget]

list[DOMNode]: Children of this widget which will be displayed.

get_component_styles(name)

Get a "component" styles object (must be defined in COMPONENT_CLASSES classvar).

Parameters:

Name Type Description Default
name str

Name of the component.

required

Raises:

Type Description
KeyError

If the component class doesn't exist.

Returns:

Name Type Description
RenderStyles RenderStyles

A Styles object.

get_default_css()

Gets the CSS for this class and inherited from bases.

Returns:

Type Description
list[tuple[str, str, int]]

list[tuple[str, str]]: a list of tuples containing (PATH, SOURCE) for this and inherited from base classes.

get_pseudo_classes()

Get any pseudo classes applicable to this Node, e.g. hover, focus.

Returns:

Type Description
Iterable[str]

Iterable[str]: Iterable of strings, such as a generator.

has_class(*class_names)

Check if the Node has all the given class names.

Parameters:

Name Type Description Default
*class_names str

CSS class names to check.

()

Returns:

Name Type Description
bool bool

True if the node has all the given class names, otherwise False.

has_pseudo_class(*class_names)

Check for pseudo class (such as hover, focus etc)

id() property writable

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

name() property

str | None: The name of the node.

parent() property

DOMNode | None: The parent node.

pseudo_classes() property

frozenset[str]: A set of all pseudo classes

query(selector=None)

Get a DOM query matching a selector.

Parameters:

Name Type Description Default
selector str | type | None

A CSS selector or None for all nodes. Defaults to None.

None

Returns:

Name Type Description
DOMQuery DOMQuery[Widget] | DOMQuery[ExpectType]

A query object.

query_one(selector, expect_type=None)

Get the first Widget matching the given selector or selector type.

Parameters:

Name Type Description Default
selector str | type

A selector.

required
expect_type type | None

Require the object be of the supplied type, or None for any type. Defaults to None.

None

Returns:

Type Description
ExpectType | Widget

Widget | ExpectType: A widget matching the selector.

remove_class(*class_names)

Remove class names from this Node.

Parameters:

Name Type Description Default
*class_names str

CSS class names to remove.

()

reset_styles()

Reset styles back to their initial state

rich_style() property

Get a Rich Style object for this DOMNode.

screen() property

Note

This may not be the currently active screen within the app.

set_class(add, *class_names)

Add or remove class(es) based on a condition.

Parameters:

Name Type Description Default
add bool

Add the classes if True, otherwise remove them.

required

set_styles(css=None, **update_styles)

Set custom styles on this object.

text_style() property

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:

Name Type Description
Style Style

Rich Style object.

toggle_class(*class_names)

Toggle class names on this Node.

Parameters:

Name Type Description Default
*class_names str

CSS class names to toggle.

()

tree() property

Get a Rich tree object which will recursively render the structure of the node tree.

Returns:

Name Type Description
Tree Tree

A Rich object which may be printed.

visible() property writable

Check if the node is visible or None.

Returns:

Name Type Description
bool bool

True if the node is visible.

walk_children(filter_type=None, *, with_self=True, method='depth', reverse=False)

Generate descendant nodes.

Parameters:

Name Type Description Default
filter_type type[WalkType] | None

Filter only this type, or None for no filter. Defaults to None.

None
with_self bool

Also yield self in addition to descendants. Defaults to True.

True
method Literal[breadth, depth]

One of "depth" or "breadth". Defaults to "depth".

'depth'
reverse bool

Reverse the order (bottom up). Defaults to False.

False

Returns:

Type Description
list[DOMNode] | list[WalkType]

list[DOMNode] | list[WalkType]: A list of nodes.