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.

AnimationLevel module-attribute

AnimationLevel = Literal['none', 'basic', 'full']

The levels that the TEXTUAL_ANIMATIONS env var can be set to.

CSSPathType module-attribute

CSSPathType: TypeAlias = Union[
    str, PurePath, List[Union[str, PurePath]]
]

Valid ways of specifying paths to CSS files.

CallbackType module-attribute

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

Type used for arbitrary callables used in callbacks.

Direction module-attribute

Direction: TypeAlias = Literal[-1, 1]

Valid values to determine navigation direction.

In a vertical setting, 1 points down and -1 points up. In a horizontal setting, 1 points right and -1 points left.

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].

IgnoreReturnCallbackType module-attribute

IgnoreReturnCallbackType = Union[
    Callable[[], Awaitable[Any]], Callable[[], Any]
]

A callback which ignores the return type.

InputValidationOn module-attribute

InputValidationOn = Literal['blur', 'changed', 'submitted']

Possible messages that trigger input validation.

NewOptionListContent module-attribute

NewOptionListContent: TypeAlias = (
    "OptionListContent | None | RenderableType"
)

The type of a new item of option list content to be added to an option list.

This type represents all of the types that will be accepted when adding new content to the option list. This is a superset of OptionListContent.

OptionListContent module-attribute

OptionListContent: TypeAlias = 'Option | Separator'

The type of an item of content in the option list.

This type represents all of the types that will be found in the list of content of the option list after it has been processed for addition.

PlaceholderVariant module-attribute

PlaceholderVariant = Literal['default', 'size', 'text']

The different variants of placeholder.

SelectType module-attribute

SelectType = TypeVar('SelectType')

The type used for data in the Select.

WatchCallbackType module-attribute

WatchCallbackType = Union[
    WatchCallbackBothValuesType,
    WatchCallbackNewValueType,
    WatchCallbackNoArgsType,
]

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.

CSSPathError class

Bases: Exception

Raised when supplied CSS path(s) are invalid.

DirEntry class

Attaches directory information to a DirectoryTree node.

loaded class-attribute instance-attribute

loaded: bool = False

Has this been loaded?

path instance-attribute

path: Path

The path of the directory entry.

DuplicateID class

Bases: Exception

Raised if a duplicate ID is used when adding options to an option list.

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.

NoSelection class

Used by the Select widget to flag the unselected state. See Select.BLANK.

OptionDoesNotExist class

Bases: Exception

Raised when a request has been made for an option that doesn't exist.

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=...,
    duration=None,
    speed=None,
    delay=0.0,
    easing=DEFAULT_EASING,
    on_complete=None,
    level="full"
):

Animate an attribute.

Parameters
Parameter Default Description
attribute
str
required

Name of the attribute to animate.

value
str | float | Animatable
required

The value to animate to.

final_value
object
...

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

duration
float | None
None

The duration (in seconds) of the animation.

speed
float | None
None

The speed of the animation.

delay
float
0.0

A delay (in seconds) before the animation starts.

easing
EasingFunction | str
DEFAULT_EASING

An easing method.

on_complete
CallbackType | None
None

A callable to invoke when the animation is finished.

level
AnimationLevel
'full'

Minimum level required for the animation to take place (inclusive).

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
Parameter Default Description
other
StylesBase
required

A Styles object.

reset method

def reset(self):

Reset the rules to initial state.

UnusedParameter class

Helper type for a parameter that isn't specified in a method call.