API Reference

TextualApp

class genro_textual.TextualApp(remote_port=None)[source]

The puppeteer: configures and drives a LiveApp.

Subclass and override recipe(page) to define your UI. Everything goes in the recipe: widgets, CSS, bindings.

Parameters:

remote_port (int | None)

builder_class

alias of TextualBuilder

compiler_class

alias of TextualCompiler

__init__(remote_port=None)[source]

Initialize the app. Does NOT call recipe() yet.

Parameters:

remote_port (int | None)

property page: BuilderBag

The page Bag (UI structure). Domain name for source.

property data: Bag

The data Bag. Setting values triggers reactive updates.

recipe(page)[source]

Override to build your UI. page is a BuilderBag with TextualBuilder.

Parameters:

page (BuilderBag)

Return type:

None

render(compiled_bag)[source]

Mount widgets from CompiledBag into the LiveApp.

Overrides BagAppBase.render() — Textual rendering is imperative (mount widgets), not string-based.

Parameters:

compiled_bag (Bag)

Return type:

None

run()[source]

Run the Textual app.

Return type:

None

TextualBuilder

class genro_textual.textual_builder.TextualBuilder(bag, schema_path=None)[source]

Builder for Textual TUI elements.

Includes FoundationMixin (app_shell) and TextualWidgetsMixin (all widgets). Subclass TextualBuilder freely — mixin schemas are inherited via MRO.

To add custom components, define them in a mixin:

from genro_builders.builder import component

class MyMixin:
    @component(sub_tags="")
    def login_form(self, comp, **kwargs):
        comp.input(placeholder="Username")
        comp.button("Login")

class MyBuilder(MyMixin, TextualBuilder):
    pass

To exclude FoundationMixin, compose your own builder:

class MinimalBuilder(TextualWidgetsMixin, BagBuilderBase):
    pass
Parameters:

TextualCompiler

class genro_textual.textual_compiler.TextualCompiler(builder)[source]

Compiler for Textual: compile() + render to Widget tree.

Parameters:

builder (Any)

__init__(builder)[source]

Initialize compiler with builder reference.

Parameters:

builder (Any) – The BagBuilderBase instance that built the bag.

property widget_counter: int

Return current counter and auto-increment.

render(compiled_bag, live_app)[source]

Walk the CompiledBag, extract app config, mount widgets.

Nodes tagged ‘css’ and ‘binding’ are app configuration — applied to live_app, not rendered as widgets. All other nodes are rendered as widgets into live_app.root.

Parameters:
  • compiled_bag (Bag)

  • live_app (Any)

Return type:

None

LiveApp

class genro_textual.textual_app.LiveApp(owner)[source]

The puppet: a bare textual.app.App driven by TextualApp.

Has no CSS or BINDINGS of its own — those come from the recipe and are applied by the compiler at render time. Delegates events to the owner (TextualApp).

Parameters:

owner (TextualApp)

BINDINGS = [('q', 'quit', 'Quit')]

The default key bindings.

__init__(owner)[source]

Create an instance of an app.

Parameters:
  • driver_class – Driver class or None to auto-detect. This will be used by some Textual tools.

  • css_path – Path to CSS or None to use the CSS_PATH class variable. To load multiple CSS files, pass a list of strings or paths which will be loaded in order.

  • watch_css – Reload CSS if the files changed. This is set automatically if you are using textual run with the dev switch.

  • ansi_color – Allow ANSI colors if True, or convert ANSI colors to RGB if False.

  • owner (TextualApp)

Raises:

CssPathError – When the supplied CSS path(s) are an unexpected type.

compose()[source]

Yield child widgets for a container.

This method should be implemented in a subclass.

on_mount()[source]
Return type:

None

on_button_pressed(event)[source]
Parameters:

event (Pressed)

Return type:

None

on_key(event)[source]
Parameters:

event (Any)

Return type:

None

on_descendant_blur(event)[source]

Write Input value to data on blur (not on every keystroke).

Parameters:

event (DescendantBlur)

Return type:

None

on_input_changed(event)[source]
Parameters:

event (Changed)

Return type:

None

on_checkbox_changed(event)[source]
Parameters:

event (Changed)

Return type:

None

on_switch_changed(event)[source]
Parameters:

event (Changed)

Return type:

None