Panels
A panel of your own: blocks, HTML in the platform's theme, and desk blocks.
An App can declare its own panel. You declare a layout once and afterwards
push values into named slots — While25 renders it, so a plugin panel cannot
break the platform's look or its rendering performance.
import while25
from while25 import App, on, ui
ui.panel("market_pulse", label="Market Pulse")
ui.layout(
ui.row(ui.metric("level"), ui.metric("chg")),
ui.table("headlines"),
)
class MarketPulse(App):
id = "market_pulse"
@on.schedule(every="10m")
def refresh(self, ctx):
while25.ui.push("level", 6_012.5)
while25.ui.push("headlines", [{"headline": "…"}])Widgets available today are row, metric, chart, table, text, view
and html. They are display-only; the interaction model is still being
designed, and shipping a half-considered callback contract would freeze an API
you would then be stuck with.
Choosing the component
The default is an HTML page — ui.layout(ui.html("view")), built on the
platform's brand theme (see "HTML" below). Reach for something else only when it
fits the job better:
| The job | Reach for |
|---|---|
| Almost anything — a dashboard, a desk, a monitor, a screener | ui.html (the default) |
| Backtest or strategy results — equity, drawdown, monthly returns, statistics, trades | the backtest block, built with ui.backtest_block(trades, data=[...]) and sealed by Python — the platform's backtest view |
| A chart inside your page | draw it in the page: inline <svg> built in Python, or CSS bars. For hover and tooltips, an optional chart block beside an html block in a ui.view |
| The platform's own components instead of markup | tiles, kv, table blocks in a ui.view |
Wiz is never required: a panel needs no chart block, and a chart needs no Wiz.
Blocks — ui.view
ui.view(slot) is the one to reach for first: push a dict describing WHAT to
show and the platform renders it in its own components — header, tiles,
kv, table, badges, text, progress, chart, backtest, html,
section, row, divider. A chart block is the interactive Wiz surface by
default (hover, legend, resize; "live": true buys the SVG fast path for a
data-rate redraw), and an html block is your own markup as one sandboxed
section — so custom HTML and an interactive chart share ONE panel:
ui.layout(ui.view("main")) # the ONLY widget → the view IS the panel
while25.ui.push("main", {"blocks": [
{"kind": "header", "title": "Sector map"},
{"kind": "row", "blocks": [
{"kind": "html", "html": "<div class='card'><h1>Notes</h1><p>…</p></div>"},
{"kind": "chart", "title": "Weight", "spec": {
"kind": "treemap", "rows": rows, "x": "sector", "value": "mcap"}},
]},
]})Tones: money (coloured by SIGN), profit, loss, active, attention,
error, muted, neutral. Pass raw numbers, never pre-formatted strings, and
None for "not known yet" — the platform formats every number and shows —
for absence, so a figure you do not have never reads as a zero you do. The
docstring on ui.view carries every field.
HTML — ui.html
ui.html(slot) is the app's page, and the default for a panel. Push a markup
string; you own the page — structure and look, and your CSS renders as
written. Build on the brand theme first — the classes below, the tokens and the
styled bare tags — so the page reads as part of the platform and follows its
light/dark switch:
| Group | Classes |
|---|---|
| layout | .page .stack .row .flex .col .wrap .between .center .grow · .grid-2 .grid-3 .grid-4 .grid-auto · .span-2 .span-3 .span-4 .span-all |
| spacing — N = 0…6 → 0 2 4 8 12 16 24px | .p-N .px-N .py-N .m-N .mt-N .mb-N .gap-N |
| type | .t-xs 11 · .t-sm 12 · .t-base 13 · .t-lg 14 · .t-xl 16 · .t-2xl 20 · .t-3xl 24 · .w-4 .w-5 .w-6 · .t-up · .t-num · .t-mono .t-prose · .t-left .t-center .t-right · .micro |
| tone | .c-profit .c-loss .c-data .c-bright .c-dim .c-amber .c-active .c-attn .c-error (the older .profit .loss .muted … still work) |
| ground | .bg-0 .bg-1 .bg-2 .bg-amber-dim .bg-profit-dim .bg-loss-dim .bg-attn-dim .bg-error-dim |
| components | .header + .stamp · .card > .card-h + .card-b · .tiles > .tile > .k .v .sub · .stat > .stat-k .stat-v .stat-d (.stat-d.up / .down add the arrow) · .kv (<dl>) · .badge + -active -attention -error -profit -loss -warning -amber · .pill · .callout.info / .warn / .error · .progress > i (width inline) · .divider · .seg > span (.on = selected) · .section + .section-title |
| tables | zebra by default · table.dense · table.sticky (sticky header) · .num right-aligns |
| heat (an HTML heatmap) | .heat-p1….heat-p5 gains, .heat-l1….heat-l5 losses — you pick the step |
Utilities win over components (.card.p-0, .v.c-loss). Your own <style>
block (or inline style) always wins over the brand sheet, which sits in a lower
cascade layer; bare CSS before your first tag is wrapped in <style> for you,
never shown:
ui.layout(ui.html("view")) # the ONLY widget → the view IS the panel
while25.ui.push("view", """
<div class="card">
<small>Day P&L</small>
<div class="t-3xl t-num c-profit">+12,480.25</div>
</div>
""")Declare either alone and it takes the whole panel — full height, no caption, no padding. Put it beside other widgets and it is one content-sized section among them.
You are not starting from a blank page: the platform's theme tokens resolve
inside (var(--color-amber), --color-profit, --color-loss,
--color-text-dim, --color-surface-2, …) and follow a theme switch, bare
markup is already styled (headings, tables with tabular numerals and zebra
rows, code, lists), and the class catalog above is there to use. Type is three faces by role — IBM Plex Mono for
data, Inter for <p> / <li> prose, JetBrains Mono for code — on a four-step
scale (h1 20, h2 16, h3 14, text 12, labels 11, tile values 22). A
.card / .tile carries a 2px left stripe that names its meaning
(.tile.profit, .card.error).
Nothing you write is snapped, stripped or rewritten — colours, fonts, shadows,
gradients, radii and emoji render as written. Prefer the tokens to literal
colours: a literal does not follow the light/dark switch. Charts are yours to
draw: inline <svg> (build its points / d in Python, give it axes and
labels — it keeps the width / height you set) or CSS bars (.progress,
.heat-*). A backtest still goes in the backtest block.
It renders in a sandboxed frame without script permission: <script>,
on* handlers and javascript: URLs are inert, so compute in Python and push
new markup rather than scripting. CSS animations and :hover do work. Links
open in the system browser (https only).
Desk blocks
A strategy's desk is its app panel. Build it from blocks in a ui.view; each
helper returns one block and checks its shape at the call (TypeError or
ValueError naming the field).
import while25
from while25 import ui
while25.ui.push("main", {"blocks": [
ui.strategy_block(), # this module's reconciled figures
ui.conditions("Entry", [
ui.rule("RSI(14)", rsi, "<", 30, near=10),
ui.rule("Close", close, "crosses_above", vwap, prev=prev_close),
], need="all"),
ui.levels(price=close, levels=[ui.level("Stop", stop, tone="loss"),
ui.level("Target", target, tone="profit")]),
ui.timeline([(t_ms, "entered long 10"), (t_ms2, "stop moved", "attention")]),
ui.chart_block({"kind": "line", "rows": rows, "x": "time", "y": ["spread"]}),
ui.custom("Notes", html="<p>Anything else, framed as the script's own.</p>"),
]})ui.strategy_block(strategy=None, *, open="auto", sections=None, title=None, capital=None): the same figures as the strategy's Live Strategies row, drawn by the platform and marked Reconciled, headed by its equity curve.strategy=Noneis the module doing the push; in a strategy's desk, that strategy (an App that imports a Strategy class is that App: its orders are its own).open:"auto","holds","working","combos","log"orFalse(folded).sections: a subset of["holds", "working", "combos", "log"].capital: what the strategy was given to trade, in its own currency (e.g.5000): the curve then shows its equity (capital plus Total P&L) from its first figure, with the % against the capital; without it the curve is the Total P&L against zero. No figure can be passed: any other keyword raisesTypeErrornaming it, and Python drops every other key from a hand-built{"kind": "strategy"}.ui.rule(label, value, op, target, *, prev=None, near=None, unit=None, fmt=None)andui.conditions(title, rules, *, need="all"):opis one of<<=>>===between(target=[lo, hi], lo <= hi)crosses_abovecrosses_below(both needprev).near> 0 is the band the bar fills across, in the value's units.unitis a word after the distance ("+32 pts");fmtis a suffix glued onto every figure of the rule, its value, target and distance (fmt="x"shows1.8x), never a number format.need:"all","any"or a count of 1 or more (more than the rules is never met, so dropping an unknown rule never raises). The platform decides Met or Not yet;value=Noneshows the absent marker.ui.level(label, value, *, tone=None)andui.levels(*, price, levels, title=None): the price against your levels; alossstop and aprofittarget add reward/risk.ui.timeline(events, *, title=None):(t_ms, text)or(t_ms, text, tone),t_msan int (numpy's too) of epoch milliseconds.ui.chart_block(spec, *, title=None, live=False): thechartblock (a Wiz spec dict, or a list of numbers).ui.custom(title, *, html): your own sandboxed markup, framed and labelled as the script's.
Numbers may be ints, floats, Decimals or numpy / pandas numbers. A NaN, a
pd.NA (a nullable column's gap), a Decimal NaN or an infinite value,
target, prev, near, level value or price (an indicator still warming up)
becomes None, "not known yet", so a draw never halts on one; a wrong op,
a between target that is not [lo, hi] or a crossing with no prev still
raises.
Only While25 says where a figure was checked: any text a script puts on screen
that says "Reconciled by While25" or "Sealed by While25" (any case, in a block's
title, label, value, text or html, a ui.html page, a text, metric or table
value) is replaced by a visible refusal (R-IMPERSONATE), and a panel or widget
label that says it is replaced by "Refused label (R-IMPERSONATE)". Honest words
such as "reconciled with broker" are fine.