Skip to content

Types

Export some objects that are used by Textual and that help document other features.

ActionParseResult module-attribute

ActionParseResult: TypeAlias = "tuple[str, tuple[Any, ...]]"

An action is its name and the arbitrary tuple of its arguments.

CallbackType module-attribute

CallbackType = Union[
    Callable[[], Awaitable[None]], Callable[[], None]
]

Type used for arbitrary callables used in callbacks.

CursorType module-attribute

CursorType = Literal['cell', 'row', 'column', 'none']

The legal types of cursors for DataTable.cursor_type.

EasingFunction module-attribute

EasingFunction = Callable[[float], float]

Signature for a function that parametrises animation speed.

An easing function must map the interval [0, 1] into the interval [0, 1].

WatchCallbackType module-attribute

WatchCallbackType = Union[
    Callable[[], Awaitable[None]],
    Callable[[Any], Awaitable[None]],
    Callable[[Any, Any], Awaitable[None]],
    Callable[[], None],
    Callable[[Any], None],
    Callable[[Any, Any], None],
]

Type used for callbacks passed to the watch method of widgets.

Animatable class

Bases: Protocol

Protocol for objects that can have their intrinsic values animated.

For example, the transition between two colors can be animated because the class Color satisfies this protocol.

MessageTarget class

Bases: Protocol

Protocol that must be followed by objects that can receive messages.

NoActiveAppError class

Bases: RuntimeError

Runtime error raised if we try to retrieve the active app when there is none.

RenderStyles class

def __init__(self, node, base, inline_styles):

Bases: StylesBase

Presents a combined view of two Styles object: a base Styles and inline Styles.

base property

base: Styles

Quick access to base (css) style.

css property

css: str

Get the CSS for the combined styles.

gutter property

gutter: Spacing

Get space around widget.

Returns
Type Description
Spacing

Space around widget content.

inline property

inline: Styles

Quick access to the inline styles.

rich_style property

rich_style: Style

Get a Rich style for this Styles object.

animate method

def animate(
    self,
    attribute,
    value,
    *,
    final_value=Ellipsis,
    duration=None,
    speed=None,
    delay=0.0,
    easing=DEFAULT_EASING,
    on_complete=None
):

Animate an attribute.

Parameters
Name Type Description Default
attribute str

Name of the attribute to animate.

required
value str | float | Animatable

The value to animate to.

required
final_value object

The final value of the animation. Defaults to value if not set.

Ellipsis
duration float | None

The duration of the animate.

None
speed float | None

The speed of the animation.

None
delay float

A delay (in seconds) before the animation starts.

0.0
easing EasingFunction | str

An easing method.

DEFAULT_EASING
on_complete CallbackType | None

A callable to invoke when the animation is finished.

None

clear_rule method

def clear_rule(self, rule_name):

Clear a rule (from inline).

get_rules method

def get_rules(self):

Get rules as a dictionary

has_rule method

def has_rule(self, rule):

Check if a rule has been set.

merge method

def merge(self, other):

Merge values from another Styles.

Parameters
Name Type Description Default
other StylesBase

A Styles object.

required

reset method

def reset(self):

Reset the rules to initial state.