Skip to content

FigletWidget reference

Bases: Coloromatic

font = font class-attribute instance-attribute

The font to use for the Figlet widget. The reactive attribute takes a string literal type in order to provide auto-completion and type hinting. The font must be one of the available fonts in the Pyfiglet package. You can also use the set_font() method to set the font using a string. This is useful for passing in a variable.

fonts_list = list(get_args(ALL_FONTS)) class-attribute instance-attribute

A list of all the available fonts in the Pyfiglet package.

justify = justify class-attribute instance-attribute

The justification to use for the Figlet widget. The reactive attribute takes a string literal type in order to provide auto-completion and type hinting. You can also use the set_justify() method to set the justification using a string. This is useful for passing in a variable.

text_input = string class-attribute instance-attribute

The text to render in the Figlet widget. You can set this directly, or use the update() method to set it.

__init__(text='', *, font='standard', justify='center', colors=[], animate=False, animation_type='gradient', gradient_quality='auto', horizontal=False, reverse=False, fps='auto', name=None, id=None, classes=None)

Create a FigletWidget.

Parameters:

Name Type Description Default
text str

Text to render in the Figlet widget.

''
font PyFiglet

Font to use for the ASCII art. Default is 'standard'.

'standard'
justify PyFiglet

Justification for the text. Default is 'center'.

'center'
colors list[str]

List of colors to use for the gradient. This is a list of strings that can be parsed by a Textual Color object that allows passing in any number of colors you want. It also supports passing in Textual CSS variables ($primary, $secondary, $accent, etc). If using CSS variables, they will update automatically to match the theme whenever the theme is changed.

[]
animate bool

Whether to animate the gradient.

False
animation_type ANIMATION_TYPE

Can be 'gradient', 'smooth_strobe', or 'fast_strobe'. The default is 'gradient'. - 'gradient' will animate the current gradient it in the direction you specify (using the horizontal and reverse settings). - 'smooth_strobe' will create a gradient and animate through the colors. - 'fast_strobe' will hard switch to the next color in the list. It does not make a gradient, and gradient_quality will be ignored.

'gradient'
gradient_quality int | str

The quality of the gradient. This means how many colors the gradient has in it. This is either 'auto' or an integer between 3 and 100. The higher the number, the smoother the gradient will be. By default, in auto mode, this will be calculated depending on the current animation type. - In gradient mode, if vertical, it will be calculated based on the height of the widget. If horizontal, it will be calculated based on the width of the widget. - In smooth_strobe mode, it will be set to (number of colors * 10). - In fast_strobe mode, this setting is ignored.

'auto'
horizontal bool

Whether the gradient should be horizontal or vertical. Note that this will have no effect if the animation mode is 'smooth_strobe' or 'fast_strobe' because they do not use a direction.

False
reverse bool

Whether the animation should run in reverse. If horizontal is False, this will switch between up and down. If horizontal is True, this will switch between left and right. Note that this will have no effect if the animation mode is 'smooth_strobe' or 'fast_strobe' because they do not use a direction.

False
fps float | str

The Frames per second for the animation. This is a float so that you can set it to values such as 0.5 if you desire. The default is 'auto', which will set the FPS to 12 for 'gradient', 12 for 'smooth_strobe', and 1 for 'fast_strobe'.

'auto'
name str | None

Name of widget.

None
id str | None

ID of Widget.

None
classes str | None

Space separated list of class names.

None

figlet_quick(text, font='standard', width=80, justify='left') classmethod

This is a standalone class method. It just provides quick access to the figlet_format function in the pyfiglet package. It also adds type hinting / auto-completion for the fonts list.

get_figlet_as_string()

Return the PyFiglet render as a string.

set_font(font)

Set the font of the PyFiglet widget. This method, unlike setting the reactive property, allows passing in a string instead of a string literal type. This is useful for passing in a variable. But unlike the reactive property, this does not provide any auto-completion for the available fonts. To get auto-completion for available fonts, set self.font directly with a raw string literal type.

Parameters:

Name Type Description Default
font str

The font to set. Must be one of the available fonts.

required

set_justify(justify)

Set the justification of the PyFiglet widget. This method, unlike the setting the reactive property, allows passing in a string instead of a string literal type. This is useful for passing in a variable.

Parameters:

Name Type Description Default
justify str

The justification to set. Can be 'left', 'center', or 'right'.

required

set_text(text)

Alias for the update() method. This is here for convenience.

Parameters:

Name Type Description Default
new_text

The text to update the PyFiglet widget with.

required

update(text)

Update the PyFiglet area with new text. You can tie this into a user input for real-time updating (or set text_input directly).

Parameters:

Name Type Description Default
new_text

The text to update the PyFiglet widget with.

required