API Reference

TextualApp

class genro_textual.TextualApp(*args, **kw)[source]

The puppeteer: configures and drives a LiveApp.

Subclass and override main(page) to define your UI, and store(data) to populate initial data.

Parameters:
__init__(*args, **kw)
Parameters:
property page: BuilderBag

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

property source: BuilderBag

Alias for page — the source Bag.

property data: Bag

The data Bag. Setting values triggers reactive updates.

property compiled: BuilderBag

The built Bag (components expanded, pointers formal).

as_textual_app()[source]

Return the native Textual App for use with textual devtools.

Creates the LiveApp without starting it. The full lifecycle (store, main, build, subscribe, render) happens in on_mount().

This enables compatibility with textual run --dev and textual serve:

# In your example file:
app = Application().as_textual_app()

# Then run with: textual run --dev examples/my_app.py
Return type:

LiveApp

run(*, subscribe=False)[source]

Run the Textual app.

Lifecycle:
  1. LiveApp.run() — starts Textual event loop

  2. on_mount() → _activate() — store + main + build + subscribe + render

Parameters:

subscribe (bool)

Return type:

None

TextualBuilder

class genro_textual.textual_builder.TextualBuilder(bag=None, schema_path=None, *, manager=None, data=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: built Bag -> Widget tree.

Parameters:

builder (Any)

__init__(builder)[source]

Initialize compiler with builder reference.

Parameters:

builder (Any)

property widget_counter: int

Return current counter and auto-increment.

compile(built_bag, target=None)[source]

Walk the built Bag, extract app config, mount widgets.

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

Parameters:
  • built_bag (Bag) – The built Bag with pointer formali.

  • target (Any) – The LiveApp instance to mount widgets into.

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 main() 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.

async 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