bootstack.Splash#
- class bootstack.Splash(*, until='ready', skippable=False, min_duration=0.0, fade=True, size=None, surface='card', padding=24, gap=12)#
Bases:
FlexContainerA borderless app intro screen shown while the main window is built.
Constructing a
Splashinside anAppcontext registers it with that app and shows it; the app then defers revealing its own window until the splash dismisses. Author the splash’s contents — a logo, a title, a status line — inside itswithblock exactly as you would the app body:with bs.App(title="My App") as app: with bs.Splash(min_duration=1.0): bs.Picture(logo) bs.Label("My App", font="heading-lg") bs.Label("Loading…", textsignal=status) # ...build the heavy app body — the splash covers this cost... app.run()
Where you write the
Splashdetermines how much of startup it covers: put it first to cover the most. Thewithblock scopes content authoring only — it does not bound the splash’s lifetime, which is governed byuntil,min_duration,skippable, anddismiss().- Parameters:
until (float | Literal['ready', 'manual']) – What automatically closes the splash.
'ready'(default) closes it when the app finishes building. A number of seconds closes it after that delay (app-ready does not auto-close it).'manual'never auto-closes — useskippable, an authored button, ordismiss().skippable (bool) – When
True, a click or the Escape key dismisses the splash.min_duration (float) – A floor in seconds — the splash never closes before this has elapsed, even if its trigger fires sooner (prevents a blink on a fast startup).
fade (bool) – Fade the window in and out where the platform supports window alpha; snap instantly where it does not.
size (tuple[int, int] | None) – Fixed size as
(width, height). Defaults to auto-fitting the content. Either way the splash is centered on screen.surface (SurfaceToken | str) – Surface token for the panel background.
padding (Padding) – Inner content padding.
gap (int) – Spacing between content items.
- property schedule: Schedule#
Scheduler tied to this widget’s lifetime.
All jobs are automatically cancelled when the widget is destroyed. First access creates the
Scheduleinstance; subsequent accesses return the same instance.Usage:
self.schedule.delay(500, callback) self.schedule.every(1000, tick) job = self.schedule.idle(refresh) job.cancel()
- capture(path, *, inset=0, settle=0.1)#
Save a picture of this widget to an image file.
Captures the area this widget occupies on screen — one widget, a whole window, or the entire application, depending on what you call it on. The file extension selects the format, so
.png,.jpg, and.pdfall work.The widget has to be visible. A capture reads pixels from the display, so the window is brought to the front first and a hidden or detached widget cannot be captured at all. Any always-on-top setting the window already had is left as it was found.
Pair it with a save dialog to let the user choose where it goes:
import bootstack as bs def on_export(): chosen = bs.ask_save_file(initial_file="dashboard.png") if chosen: app.capture(chosen)
- Parameters:
path (str | Path) – Where to write the image. Missing parent folders are created, and the extension chooses the format.
inset (int) – Pixels to trim from every edge, zero or more. Use
2on a whole window to drop the native border artifact.settle (float) – Seconds to let the desktop finish repainting before the pixels are read. The default covers the common case of a dialog closing just beforehand. The interface pauses for this long, so a second click on the control that started the capture waits its turn rather than starting an overlapping one.
- Returns:
The path that was written.
- Raises:
BootstackError – If the widget is not visible on screen or has been scrolled out of view, if
insetis negative, if no capture backend is available, or if the file cannot be written.- Return type:
Path
Added in version 0.3.0.
- destroy()#
Destroy the widget and release the resources it holds.
Removes the widget from its parent, destroys its children, and cancels any pending or repeating jobs on its
schedule. After this the widget must not be used again. Destroying a container destroys everything inside it.
- dismiss()#
Dismiss the splash now, fading out and revealing the app.
Respects
min_duration— if the floor has not elapsed, the dismissal is deferred until it has. Safe to call more than once; later calls are ignored once a dismissal is under way.
- emit(event, *, data=None)#
Fire a named event on this widget, as if it produced the event itself.
This is how a composite widget surfaces high-level activity to its listeners, and the generic counterpart to the
on_*()shorthands for firing events that have no dedicated method.It is meant for the framework’s own events —
'change','select','input'and the rest of the data-carrying names. A handler registered throughon()or anon_<event>()shorthand receives what is emitted.Names that map onto a native event instead (
'click','focus','blur','submit', …) are a different matter: emitting one asks the toolkit to deliver a real input event, which carries no payload and can reach handlers the widget installed for its own use. Emitting those is not a way to notify listeners, and a listener bound throughon()may not see it. Drive the widget through its properties and methods instead.- Parameters:
Example
from bootstack.events import ChangeEvent field.emit("change", data=ChangeEvent(value=new_value))
- guide_layout(child, **layout_kw)#
Place
childinto this container’s flow and snapshot its placement.
- on(event, handler=None)#
Bind
handlertoevent, or return a composableStream.With a handler — binds immediately and returns a
Subscription:sub = widget.on("change", handler) sub.cancel()
Without a handler — returns a
Streamfor operator chaining. The Tk binding is created lazily when.listen()is called:sub = widget.on("change").debounce(300).listen(handler) sub.cancel()
- Parameters:
event (str) – Event name (e.g.
"change","click").handler (Callable[[Any], Any] | None) – Optional callback. If omitted, a
Streamis returned.
- Returns:
Subscriptionwhen a handler is provided;Streamotherwise.- Return type:
- on_destroy(handler=None)#
Register a callback fired when the widget is destroyed.
Fires once, as the widget is torn down — the place to release resources the widget owns that aren’t cleaned up automatically (file handles, observers, external subscriptions). The handler receives a curated
Event.- Parameters:
handler (Callable[[Event], Any] | None) – Called as the widget is destroyed. Omit to get a composable
Stream.- Returns:
A cancellable
Subscriptionwhen a handler is given, otherwise aStream.- Return type:
- on_dismiss() Stream#
- on_dismiss(handler: Callable[[SplashDismissEvent], Any]) Subscription
Register a callback fired when the splash begins dismissing.
The handler receives a
SplashDismissEventwhosereasonsays why it closed ('ready','timer','manual', or'skip'). Fires once, as the fade-out starts.- Parameters:
handler (Callable[[SplashDismissEvent], Any] | None) – Called with the dismiss event. Omit to get a composable
Stream.- Returns:
A cancellable
Subscriptionwhen a handler is given, otherwise aStream.- Return type: