Skip to content

Div

pywry.toolbar.Div

Bases: ToolbarItem

A container div for custom HTML content within a toolbar.

Supports nested toolbar items and custom scripts for advanced layouts. Parent context (component IDs) is passed to children via data-parent-id attribute.

Emits: No automatic events (unless content has interactive elements)

ATTRIBUTE DESCRIPTION
content

HTML content to render inside the div.

TYPE: str

script

JS file path or inline string to inject (executed after toolbar script).

TYPE: str or Path or None

class_name

Custom CSS class for the div container.

TYPE: str

children

Nested toolbar items (Button, Select, other Divs, etc.).

TYPE: list or None

Examples:

>>> Div(
...     content="<h3>Controls</h3>",
...     class_name="my-controls",
...     children=[
...         Button(label="Action", event="app:action"),
...         Div(content="<span>Nested</span>", class_name="nested-div"),
...     ],
... )

Functions

build_html

build_html(parent_id: str | None = None) -> str

Build div HTML with content and nested children.

PARAMETER DESCRIPTION
parent_id

Parent component ID for context chain inheritance.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
str

HTML string for the div container.

collect_scripts

collect_scripts() -> list[str]

Collect scripts from this div and all nested children (depth-first).

RETURNS DESCRIPTION
list[str]

List of script content strings (file contents or inline scripts).

auto_generate_component_id

auto_generate_component_id() -> ToolbarItem

Auto-generate component_id based on type if not provided.

validate_event_name classmethod

validate_event_name(v: str) -> str

Validate event follows namespace:event-name pattern.