xnano.components.loader
xnano.components.loader
¶
xnano.components.loader
Show determinate progress or an indeterminate spinner.
Classes:
-
Loader–Determinate progress indicator or indeterminate spinner.
Functions:
-
resolve_loader_symbols–Resolve a preset name or frame sequence into spinner frames.
Attributes:
-
LoaderStyle(TypeAlias) –Visual style for a
Loadercomponent. -
LoaderSymbolPreset(TypeAlias) –Named spinner frame presets.
-
LoaderSymbols(TypeAlias) –Explicit spinner frames or a named preset.
-
LoaderLabel(TypeAlias) –Label text, nested Text, auto percentage, or hidden.
LoaderStyle
module-attribute
¶
Visual style for a Loader component.
LoaderSymbolPreset
module-attribute
¶
Named spinner frame presets.
LoaderSymbols
module-attribute
¶
LoaderSymbols: TypeAlias = (
Sequence[str] | LoaderSymbolPreset
)
Explicit spinner frames or a named preset.
LoaderLabel
module-attribute
¶
LoaderLabel: TypeAlias = (
"str | Text | Literal[False] | None"
)
Label text, nested Text, auto percentage, or hidden.
Loader
dataclass
¶
Loader(
value: float | None = None,
total: float | None = None,
style: LoaderStyle = "spinner",
label: LoaderLabel = None,
symbols: LoaderSymbols = "dots",
interval: int = 80,
foreground: "ColorLike" = "green",
background: "ColorLike | None" = None,
filled_color: "ColorLike | None" = None,
unfilled_color: "ColorLike | None" = None,
running: bool = True,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = False
)
Bases: Component
Determinate progress indicator or indeterminate spinner.
Leave value as None to show a spinner. Set value to a ratio,
or pair it with total, to show measurable progress.
Example
Loader(value=42, total=100, label=True)
Attributes:
-
value(float | None) –Current amount, ratio, or
Nonefor indeterminate. -
total(float | None) –When set, ratio is
value / total. -
style(LoaderStyle) –"spinner","bar", or"line". -
label(LoaderLabel) –Overlay text, auto percentage, nested Text, or hidden.
-
symbols(LoaderSymbols) –Spinner frames or a named preset.
-
interval(int) –Milliseconds between spinner frames.
-
foreground('ColorLike') –Primary foreground / filled color (deprecated alias:
color). -
background('ColorLike | None') –Widget background color.
-
filled_color('ColorLike | None') –Line style filled-portion color.
-
unfilled_color('ColorLike | None') –Line style unfilled-portion color.
-
running(bool) –Whether spinner animation advances.
Methods:
-
component_post_init–Resolve spinner frames and start the animation epoch.
-
restart–Reset the spinner epoch to the current monotonic time.
-
current_frame–Return the active spinner glyph, advanced by the framework clock.
-
inline_text–Return the spinner glyph plus its label for inline embedding.
-
compose–Compose spinner text or gauge content for this loader.
-
get_frame–Optional frame/panel chrome around composed content.
-
get_size–Return the preferred cell size of this component.
-
before_render–Called before rendering; returns the effective render area.
-
after_render–Called after rendering for optional post-paint work.
-
compose_extra_small–Compose content when the viewport is extra small (< 40 cols).
-
compose_small–Compose content when the viewport is small (40–79 cols).
-
compose_medium–Compose content when the viewport is medium (80–119 cols).
-
compose_large–Compose content when the viewport is large (120–159 cols).
-
compose_extra_large–Compose content when the viewport is extra large (>= 160 cols).
-
handle_keyboard–Optional keyboard handler while focused.
-
handle_paste–Optional paste handler while focused.
value
class-attribute
instance-attribute
¶
value: float | None = None
Current amount, ratio, or None for indeterminate work.
total
class-attribute
instance-attribute
¶
total: float | None = None
When set, the ratio is value / total.
style
class-attribute
instance-attribute
¶
style: LoaderStyle = 'spinner'
"spinner", block "bar", or thin "line" gauge.
label
class-attribute
instance-attribute
¶
label: LoaderLabel = None
Overlay text. None auto-derives a percentage when determinate.
symbols
class-attribute
instance-attribute
¶
symbols: LoaderSymbols = 'dots'
Spinner frames or a named preset.
interval
class-attribute
instance-attribute
¶
interval: int = 80
Milliseconds between spinner frames.
foreground
class-attribute
instance-attribute
¶
Primary foreground / filled color (deprecated alias: color).
background
class-attribute
instance-attribute
¶
Widget background color.
filled_color
class-attribute
instance-attribute
¶
Line style filled-portion color (defaults to foreground).
unfilled_color
class-attribute
instance-attribute
¶
Line style unfilled-portion color.
running
class-attribute
instance-attribute
¶
running: bool = True
Whether spinner animation advances with wall time.
fit_content
class-attribute
instance-attribute
¶
fit_content: bool = dataclasses.field(
default=False, kw_only=True
)
Whether layout should use the loader's natural size.
ratio
property
¶
ratio: float
Return the completion ratio, clamped to 0.0–1.0.
Indeterminate loaders report 0.0.
visible
class-attribute
instance-attribute
¶
visible: bool = dataclasses.field(
default=True, kw_only=True
)
Whether this component paints at all.
z
class-attribute
instance-attribute
¶
z: int = dataclasses.field(default=0, kw_only=True)
Stacking order among sibling content.
component_post_init
¶
Resolve spinner frames and start the animation epoch.
Source code in xnano/components/loader.py
restart
¶
current_frame
¶
current_frame() -> str
Return the active spinner glyph, advanced by the framework clock.
The inline path: embed this in any Text/flow content to animate a
spinner mid-line without a manual per-tick frame counter — e.g.
Text(content=f"{loader.current_frame()} generating…").
Source code in xnano/components/loader.py
compose
¶
Compose spinner text or gauge content for this loader.
Returns:
-
–
Interface-neutral content for this loader.
Source code in xnano/components/loader.py
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> None
compose_extra_small
¶
compose_extra_small(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:compose. When
overridden, it is used instead of compose while the window
is in this size tier. Overriding any compose_* variant opts the
component into breakpoint dispatch; a component that overrides none
pays no per-frame cost.
Source code in xnano/components/component.py
compose_small
¶
compose_small(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is small (40–79 cols).
See :meth:compose_extra_small.
compose_medium
¶
compose_medium(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is medium (80–119 cols).
See :meth:compose_extra_small.
compose_large
¶
compose_large(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is large (120–159 cols).
See :meth:compose_extra_small.
compose_extra_large
¶
compose_extra_large(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is extra large (>= 160 cols).
See :meth:compose_extra_small.
Source code in xnano/components/component.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
resolve_loader_symbols
¶
resolve_loader_symbols(
symbols: LoaderSymbols,
) -> tuple[str, ...]
Resolve a preset name or frame sequence into spinner frames.
Parameters:
-
symbols(LoaderSymbols) –Named preset or ordered frame strings.
Returns:
Raises:
-
ValueError–When no frames are provided.