Skip to content

Toolbar

pywry.toolbar.Toolbar

Bases: BaseModel

A toolbar container with positioned items.

ATTRIBUTE DESCRIPTION
component_id

Unique identifier for this toolbar (auto-generated if not provided).

TYPE: str

position

Where to place the toolbar: "top", "bottom", "left", "right", or "inside".

TYPE: str

items

List of toolbar items (Button, Select, TextInput, Div, etc.).

TYPE: list

style

Optional inline CSS for the toolbar container.

TYPE: str

script

JS file path or inline string to inject into the toolbar.

TYPE: str or Path or None

class_name

Custom CSS class added to the toolbar container.

TYPE: str

collapsible

Enable collapse/expand behavior with toggle button.

TYPE: bool

resizable

Enable drag-to-resize on toolbar edge (direction based on position).

TYPE: bool

Examples:

>>> Toolbar(
...     position="top",
...     class_name="my-toolbar",
...     collapsible=True,
...     resizable=True,
...     items=[
...         Button(label="Refresh", event="app:refresh"),
...         Select(label="View:", event="view:change", options=[...]),
...         Div(content="<span>Custom</span>", class_name="custom-section"),
...     ],
... )

Functions

normalize_items classmethod

normalize_items(v: Any) -> list[ToolbarItem]

Accept list of dicts or ToolbarItem objects.

build_html

build_html() -> str

Build complete toolbar HTML with collapsible/resizable support.

collect_scripts

collect_scripts() -> list[str]

Collect scripts from toolbar and all nested Div children (depth-first).

Toolbar script runs first, then Div scripts in item order.

RETURNS DESCRIPTION
list[str]

List of script content strings.

to_dict

to_dict() -> dict[str, Any]

Convert toolbar to dict.

get_secret_inputs

get_secret_inputs() -> list[SecretInput]

Get all SecretInput items in this toolbar (including nested in Divs).

RETURNS DESCRIPTION
list[SecretInput]

All SecretInput components found.

register_secrets

register_secrets() -> None

Register all SecretInput values in the secret registry.

Called automatically when rendering. Ensures secrets are available for reveal/copy handlers.

get_secret_events

get_secret_events() -> list[tuple[str, str, str]]

Get all secret-related events that need handlers.

RETURNS DESCRIPTION
list[tuple[str, str, str]]

List of (component_id, reveal_event, copy_event) tuples.