juno.ui

Build a native window from a plain dataclass and a pure body(state) function. Keep data in the state object, change it in synchronous callbacks, and return new immutable descriptions from body. Do not mutate a view or perform I/O, dialogs, timers or state changes while building the description.

See the Native UI guide for examples.

ui.run(body, state) shows the window and blocks the script or notebook cell until the window closes. Close returns normally; Stop raises KeyboardInterrupt. Callback, body and timer errors close the window and re-raise with their original traceback. No window or callback survives the run. Where windows are unavailable, importing the module and building descriptions still work; opening a window raises UIError.

A run without access to the screen raises UIError with this message:

The window needs the screen. Save this script and run it in Juno to open the window.

Description and callback rules

Use constructor keyword arguments, not modifier chains. Common arguments are key, padding, disabled, accessibility_label, width, height, min_width, min_height, max_width and max_height. Dimensions are nonnegative points or None; width and height also accept "fill". Padding is a number or (top, leading, bottom, trailing). A readable form uses width="fill", max_width=680, padding=16. Native safe areas, keyboard avoidance, Dynamic Type and rotation are automatic. HStack never wraps; use ScrollView for long forms. List scrolls itself: avoid same-axis nesting.

Image, Button and Tab take symbol= with an SF Symbol name such as "star.fill". An Image takes a source or a symbol, not both; Button("", symbol="plus", on_press=add) is an icon-only button. A name the device does not have shows nothing and raises no error.

Set busy=True on a Button or a menu Picker to show an indeterminate spinner and block activation. Keep the title and selection in your own state. Segmented Pickers accept only busy=False. Use ProgressView(value=...) to show measured progress. Schedule long work in later ui.after callbacks so the busy state can render.

Buttons call their callback with no arguments. Text fields pass a string, toggles a Boolean, sliders a float, and pickers and tabs a key string. Callbacks run on the same interpreter main thread as run. Committed text edits arrive before submit, focus exit and actions; marked IME text waits for commit while native draft editing remains immediate. Return the new state value as text= on the next render.

Give dynamic siblings persistent, unique string keys. List.item_key(item) returns a stored string, never a freshly generated UUID. Its on_delete callback receives that key and must remove the item from state. A Sheet is a direct child of the root VStack; its on_dismiss() callback must clear is_presented in state. Programmatic hiding and teardown do not call it.

Dialogs and timers

Use alert, confirm and prompt only in active run callbacks; elsewhere use juno.dialogs. Prompt returns "" for empty OK and None for Cancel. Dialogs block their callback and pause other callbacks and timers until dismissal.

Start effects with run(..., on_appear=fn). after(ms, fn) schedules a one-shot callback; after(0, fn) schedules a later tick. Eight user events are served per due timer; dialog/background union pauses deadlines. Timer.cancel() is idempotent. Timer is returned by after and View is the description base; neither is a user constructor.

API

Build a window from plain Python state and immutable view descriptions.

Change state in synchronous callbacks. body(state) describes the window; run(body, state) refreshes it after each callback and waits until Close.

Common keywords (**P):

key=None is a persistent, nonempty sibling string key, compared exactly without Unicode normalization. Use stable data IDs rather than row indices. Changing a view’s type or parent creates a new identity; removed identities are never reused during a run. padding=0 accepts a nonnegative number or (top, leading, bottom, trailing). disabled=False disables interaction in the subtree. accessibility_label=None overrides its spoken label. width=None and height=None accept nonnegative points or "fill"; min_width, min_height, max_width, and max_height default to None and accept nonnegative points. Minimums must not exceed maximums; fixed dimensions must lie within their bounds. TextField, TextEditor, Toggle, Slider, Picker, DatePicker and ProgressView fill the width of their column or row unless given a width. Tab and Sheet have only their explicitly listed keywords.

State and callbacks:

Descriptions are immutable. Keep state in ordinary dictionaries, lists or objects; mutate it in synchronous callbacks. body(state) must only construct descriptions: no side effects, dialogs, timers, or asynchronous work. Controlled fields display the value returned by the next body call; update state in on_change to retain an edit. Pending edits are delivered in capture order before actions, tab changes and dialogs. Removing a TextField discards its pending debounced text. List deletion is explicit: on_delete(key) must remove the item from state. Sheet dismissal calls on_dismiss(); clear is_presented or remove the Sheet in that callback. Going back in a NavigationStack calls on_back(key); remove every page after key from state in that callback.

Window lifetime:

run blocks until Close or close(). Stop cleans up and raises the original KeyboardInterrupt. Callback errors, including SystemExit, retain their original exception and traceback after cleanup. Timers pause for the union of dialog waits and background time, counting overlap once and only the pause after each timer’s creation. After eight dequeued inputs (including ignored inputs), a due timer gets a turn; at most one timer runs per tick, without a burst on resume. Queued input gets the next opportunity.

Colours and fonts:

Colours are names or hex strings. The names are the system colours red, orange, yellow, green, mint, teal, cyan, blue, indigo, purple, pink, brown and gray; the text levels label, secondary_label and tertiary_label; the backgrounds background, secondary_background and tertiary_background; and accent, the window tint. Names follow dark mode and Increase Contrast. Hex "#RRGGBB" or "#RRGGBBAA" (the # required, any case) is one fixed colour in light and dark mode alike, so prefer names for text and backgrounds. Colour should not be the only way a window carries meaning. Fonts are system text styles with an optional weight, design and size; all follow Dynamic Type.

Availability:

Importing this module and constructing descriptions does not open a window. Unsupported features raise UIError("not available in this build"). Running without access to the screen raises UIError("The window needs the screen. Save this script and run it in Juno to open the window.").

Typical usage:

from juno import ui

state = {"count": 0}

def increment():
    state["count"] += 1

def body(s):
    return ui.VStack(ui.Text(str(s["count"])),
                     ui.Button("Add", on_press=increment))

ui.run(body, state)
class juno.ui.View

Bases: object

An immutable description returned by body(state).

Note

Construct a listed view such as Text; do not instantiate or subclass View. Change state and return a new description to update a window.

class juno.ui.VStack(*children, spacing=8, alignment='center', background=None, corner_radius=0, **P)

Bases: View

Arrange views vertically.

Parameters:
  • *children – Views, each with a unique key when dynamically reordered.

  • spacing – Nonnegative gap in points; defaults to 8.

  • alignment – leading, center, or trailing.

  • background – Optional colour behind the children and the padding.

  • corner_radius – Nonnegative points rounding the background; defaults to 0.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(*children, spacing=8, alignment='center', background=None, corner_radius=0, **P)

Arrange child views vertically.

Arrange views vertically.

Parameters:
  • *children – Views, each with a unique key when dynamically reordered.

  • spacing – Nonnegative gap in points; defaults to 8.

  • alignment – leading, center, or trailing.

  • background – None, a colour name, or hex "#RRGGBB" / "#RRGGBBAA", drawn behind the children and the padding.

  • corner_radius – Nonnegative points rounding the background’s corners; defaults to 0.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.HStack(*children, spacing=8, alignment='center', background=None, corner_radius=0, adaptive=False, **P)

Bases: View

Arrange views horizontally without wrapping.

Parameters:
  • *children – Views to arrange.

  • spacing – Nonnegative gap in points; defaults to 8.

  • alignment – top, center, or bottom.

  • background – Optional colour behind the children and the padding.

  • corner_radius – Nonnegative points rounding the background; defaults to 0.

  • adaptive – When True, the children sit side by side in a horizontally regular window and stack vertically in a horizontally compact one (an iPhone in portrait, an iPad in Slide Over or narrow Split View). The switch follows the window without calling body again, and the children keep their state, focus and scroll position. Defaults to False.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(*children, spacing=8, alignment='center', background=None, corner_radius=0, adaptive=False, **P)

Arrange child views horizontally.

Arrange views horizontally without wrapping.

Parameters:
  • *children – Views to arrange.

  • spacing – Nonnegative gap in points; defaults to 8.

  • alignment – top, center, or bottom. When an adaptive stack is vertical, top aligns to the leading edge and bottom to the trailing edge.

  • background – None, a colour name, or hex "#RRGGBB" / "#RRGGBBAA", drawn behind the children and the padding.

  • corner_radius – Nonnegative points rounding the background’s corners; defaults to 0.

  • adaptive – When True, the children sit side by side in a horizontally regular window and stack vertically in a horizontally compact one. Defaults to False.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.Spacer(*, min_length=0, **P)

Bases: View

Share remaining space along the enclosing stack’s axis.

Parameters:
  • min_length – Nonnegative minimum space in points.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(*, min_length=0, **P)

Build flexible space with a minimum length.

Share remaining space along the enclosing stack’s axis.

Parameters:
  • min_length – Nonnegative minimum space in points.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.Text(text, *, font='body', weight=None, design=None, size=None, color=None, markdown=False, **P)

Bases: View

Display text that wraps within the available width.

Parameters:
  • text – A string; use str(number) for numbers.

  • font – Text style: large_title, title, title2, title3, headline, subheadline, body, callout, footnote, or caption.

  • weight – None for the style’s own, or regular, medium, semibold, or bold.

  • design – None, default, rounded, serif, or monospaced.

  • size – None, or 6 to 160 points at the default text size.

  • color – None for the label colour, a colour name, or hex.

  • markdown – When True, render inline Markdown in text.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(text, *, font='body', weight=None, design=None, size=None, color=None, markdown=False, **P)

Build a text label.

Display text that wraps within the available width. Every font follows Dynamic Type.

Parameters:
  • text – A string; use str(number) for numbers.

  • font – Text style: large_title, title, title2, title3, headline, subheadline, body, callout, footnote, or caption; defaults to body.

  • weight – None keeps the style’s own weight; otherwise regular, medium, semibold, or bold.

  • design – None or default for the system font; rounded, serif, or monospaced for its other designs.

  • size – None for the style’s size, or a number from 6 to 160: points at the default text size, scaled with Dynamic Type like the chosen style.

  • color – None for the label colour, a colour name such as "red" or "secondary_label", or hex "#RRGGBB" / "#RRGGBBAA". Names follow dark mode; hex is the same colour in both, so prefer names for text.

  • markdown – When True, render inline Markdown: **bold**, *italics*, code between backticks, ~~strikethrough~~ and [links](https://example.com). Tapping an http or https link opens it in Safari over the window. Inline Markdown only: headings and lists show as written, and text that cannot be parsed shows as written. A fenced block shows as one run of inline code, its line breaks turned into spaces; to show code with its lines, use a Text without markdown and with design="monospaced". The runs keep font, weight, design, size and color as their base.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.Image(source=None, *, symbol=None, content_mode='fit', color=None, multicolor=False, font=None, hierarchical=False, palette=None, size=None, **P)

Bases: View

Display an encoded image or an SF Symbol, decorative unless accessibility_label is set.

Parameters:
  • source – Existing image path relative to the script’s working directory, or PNG/JPEG/HEIC/HEIF/GIF bytes (first frame), at most 700 KB.

  • symbol – SF Symbol name such as "star.fill", instead of source. A name this device does not have shows nothing in the same space.

  • content_mode – fit, fill, or center; defaults to fit.

  • color – Symbol only: None for the label colour, a colour name, or hex.

  • multicolor – Symbol only: True draws the symbol’s own colours.

  • hierarchical – Symbol only: True draws color in layered opacities.

  • palette – Symbol only: two or three colours for the symbol’s layers.

  • font – Symbol only: None for body, or a Text style that sizes the symbol.

  • size – Symbol only: None, or 6 to 160 points at the default text size.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(source=None, *, symbol=None, content_mode='fit', color=None, multicolor=False, font=None, hierarchical=False, palette=None, size=None, **P)

Build an image; downscale large images with PIL first.

Parameters:
  • source – Existing image path or encoded bytes, bytearray or memoryview; PNG/JPEG/HEIC/HEIF/GIF (first frame), at most 700 KB.

  • symbol – SF Symbol name such as "star.fill"; pass source or symbol, not both. An unknown name shows nothing in the same space.

  • content_mode – fit, fill, or center.

  • color – Symbol only. None draws the label colour; otherwise a colour name such as "orange" or hex "#RRGGBB" / "#RRGGBBAA". Names follow dark mode; hex does not.

  • multicolor – Symbol only. True draws the symbol’s own colours where it has them; color then fills only the parts left to the tint.

  • hierarchical – Symbol only. True draws color, or the label colour, in layered opacities: the main shape solid, the rest lighter.

  • palette – Symbol only. A tuple of two or three colours, one per layer of the symbol, such as ("gray", "yellow"); color cannot go with it. multicolor, hierarchical and palette are different ways to colour a symbol; use at most one.

  • font – Symbol only. None sizes the symbol like body text; a Text style such as "large_title" sizes it like that style. Symbols follow Dynamic Type.

  • size – Symbol only. None for the size font gives, or a number from 6 to 160: points at the default text size, scaled with Dynamic Type like font. size replaces the size font would give, so size=96 draws a symbol larger than any text style.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.ProgressView(*, value=None, label='', **P)

Bases: View

Display determinate progress or an indeterminate activity indicator.

Parameters:
  • value – None for activity, or a finite number from 0 to 1; not bool.

  • label – Optional caption string.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(*, value=None, label='', **P)

Build a progress indicator.

Parameters:
  • value – None for activity, or a finite number from 0 to 1; not bool.

  • label – Optional caption string. Beside an activity spinner it follows the spinner on one line, as a status; above a bar it captions the bar.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.Button(title, *, on_press=None, symbol=None, role='normal', style='plain', tint=None, size='regular', menu=None, busy=False, **P)

Bases: View

Call a function when pressed, or show a menu.

Parameters:
  • title – Button label; may be empty when symbol is given.

  • on_press – Synchronous function accepting no arguments; omit it when menu is given.

  • symbol – Optional SF Symbol name shown before the title.

  • role – normal or destructive.

  • style – plain, bordered, tinted, or filled.

  • tint – Optional colour; defaults to the window tint.

  • size – small, regular, or large, a control size, not points.

  • menu – Optional Menu shown when the button is tapped.

  • busy – Boolean; show an activity indicator and block activation.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(title, *, on_press=None, symbol=None, role='normal', style='plain', tint=None, size='regular', menu=None, busy=False, **P)

Build a button that calls on_press, or shows menu, when activated.

Call a function when pressed, or show a menu.

Parameters:
  • title – Button label; "" with a symbol makes an icon-only button, which VoiceOver reads as the symbol’s own description unless accessibility_label is set. An icon-only bordered, tinted or filled button is a circle.

  • on_press – Synchronous function accepting no arguments. Required unless menu is given; omit it then.

  • symbol – Optional SF Symbol name such as "plus", shown before the title. An unknown name shows nothing in the same space.

  • role – normal or destructive; destructive colours the button red whatever the tint, and style still draws it: a plain destructive button is red text, a tinted one a red capsule.

  • style – plain (text only, with no space on either side, so its symbol and title line up with the Text above or below it), bordered (a grey capsule), tinted (a light capsule in the tint), or filled (a solid capsule in the tint); defaults to plain. Prefer bordered or tinted for a standalone action.

  • tint – None follows the window tint; otherwise a colour name such as "green" or hex "#RRGGBB" / "#RRGGBBAA".

  • size – small, regular (default), or large: the title, symbol and padding scale together; a small button draws its symbol at the small symbol scale.

  • menu – A Menu shown as a pull-down when the button is tapped; its items call their own on_select. A disabled button does not open it. A menu button’s title stays on one line, cut short with an ellipsis when it does not fit.

  • busy – Boolean, default False. True dims the button, shows an indeterminate spinner in the symbol’s place (or before the title), and blocks the action and menu. Set the title and clear busy from your own state. An independently disabled button stays disabled.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.TextField(placeholder, *, text, on_change, on_submit=None, keyboard='default', debounce_ms=150, **P)

Bases: View

Edit a single line of controlled text.

Parameters:
  • placeholder – Hint shown when empty.

  • text – Current string from state.

  • on_change – Function receiving the committed string; update state here.

  • on_submit – Optional function receiving the string on Return.

  • keyboard – default, decimal, number, email, or url.

  • debounce_ms – Trailing change delay; 0 delivers on the next tick.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(placeholder, *, text, on_change, on_submit=None, keyboard='default', debounce_ms=150, **P)

Build an editable single-line text field.

Edit a single line of controlled text.

Parameters:
  • placeholder – Hint shown when empty.

  • text – Current string from state.

  • on_change – Function receiving the committed string; update state here.

  • on_submit – Optional function receiving the string on Return.

  • keyboard – default, decimal, number, email, or url.

  • debounce_ms – Trailing change delay; 0 delivers on the next tick. Text typed within the delay before Close, close() or Stop reaches on_change once, after the window closes; not after Stop interrupts a callback. In that last call ui.after and dialogs end the callback at once, so save before calling them.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.Toggle(title, *, value, on_change, **P)

Bases: View

Show a controlled on/off switch.

Parameters:
  • title – Switch label.

  • value – Current bool from state.

  • on_change – Function receiving a bool.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(title, *, value, on_change, **P)

Build a labelled on/off control.

Show a controlled on/off switch.

Parameters:
  • title – Switch label.

  • value – Current bool from state.

  • on_change – Function receiving a bool.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.Slider(value, *, on_change, minimum=0.0, maximum=1.0, step=None, **P)

Bases: View

Choose a controlled number within a finite range.

Parameters:
  • value – Current number between minimum and maximum.

  • on_change – Function receiving a float.

  • minimum – Lower bound; defaults to 0.

  • maximum – Upper bound; defaults to 1.

  • step – Optional positive increment.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(value, *, on_change, minimum=0.0, maximum=1.0, step=None, **P)

Build a numeric slider.

Choose a controlled number within a finite range.

Parameters:
  • value – Current number between minimum and maximum.

  • on_change – Function receiving a float.

  • minimum – Lower bound; defaults to 0.

  • maximum – Upper bound; defaults to 1.

  • step – Optional positive increment.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.Picker(title, *, options, value, on_change, style='menu', size='regular', busy=False, **P)

Bases: View

Choose one tagged option.

Parameters:
  • title – Picker label.

  • options – Nonempty iterable of unique (string_tag, string_label) pairs.

  • value – Selected tag, which must exist in options.

  • on_change – Function receiving a string tag.

  • style – menu or segmented; segmented requires 2–6 options.

  • size – small, regular, or large, a control size, not points.

  • busy – Boolean; show an activity indicator and block selection in menu style.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(title, *, options, value, on_change, style='menu', size='regular', busy=False, **P)

Build a labelled choice control.

Choose one tagged option.

Parameters:
  • title – Picker label, shown before the selection on the same row; "" shows the control alone.

  • options – Nonempty iterable of unique (string_tag, string_label) pairs.

  • value – Selected tag, which must exist in options.

  • on_change – Function receiving a string tag.

  • style – menu (a form row: the title at the leading edge, the selected option and a pop-up indicator at the trailing edge; tapping opens the options) or segmented; segmented requires 2–6 options.

  • size – small, regular (default), or large; a large segmented control is a 44-point tall touch target with wider segments.

  • busy – Boolean, default False. In menu style, True dims the picker, blocks selection and replaces the pop-up indicator with an indeterminate spinner. The selected label remains visible. Segmented style only accepts False.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.List(items, *, item_key, row, on_delete=None, on_select=None, selected=None, clears_selection=True, section=None, footer=None, separators=True, selection_style='default', deletable=None, style='plain', anchor=None, context_menu=None, **P)

Bases: View

Display rows identified by persistent item keys.

Parameters:
  • items – Iterable of data; an empty list is valid.

  • item_key – Function returning each item’s unique, nonempty string ID.

  • row – Function returning one view for an item.

  • on_delete – Optional function receiving the swiped item’s key. Remove the item from state yourself.

  • on_select – Optional function receiving the key of the row the person tapped anywhere outside its own controls.

  • selected – None or the key of the row drawn selected.

  • clears_selection – False keeps selected drawn when the person comes back to the list.

  • section – Optional function receiving an item and returning its section header, or None; neighbouring rows with the same header share a section.

  • footer – Optional plain text drawn under the last row, in the system’s footnote style; blank lines separate paragraphs.

  • separators – False hides the lines between rows.

  • selection_style – default or none; none draws no system highlight behind the selected row.

  • deletable – Optional function receiving an item and returning False for a row that offers no Delete swipe.

  • style – plain (rows span the list’s width) or inset (rows in a rounded group on a grouped background, kept to a readable width in a wide window). Defaults to plain.

  • anchor – None or "bottom" to keep the last row in view.

  • context_menu – Optional function receiving an item and returning a Menu shown when its row is long-pressed, or None for no menu.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(items, *, item_key, row, on_delete=None, on_select=None, selected=None, clears_selection=True, section=None, footer=None, separators=True, selection_style='default', deletable=None, style='plain', anchor=None, context_menu=None, **P)

Build a keyed list of row descriptions.

Display rows identified by persistent item keys.

Parameters:
  • items – Iterable of data; an empty list is valid.

  • item_key – Function returning each item’s unique, nonempty string ID.

  • row – Function returning one view for an item.

  • on_delete – Optional function receiving the swiped item’s key. Remove the item from state yourself.

  • on_select – Optional function receiving the key of the row the person tapped, or chose with the keyboard or VoiceOver. A tap on a Button or another control in the row runs that control only.

  • selected – None (default) or an item key. That row is drawn selected, as in a sidebar; a key not in items selects nothing. Beside its page on a wide window the highlight stays; see clears_selection for a list shown alone.

  • clears_selection – True (default) clears the highlight when the person comes back to a list shown alone (a back on a narrow window, or a return to its tab), as iOS lists do, until selected names another row. False keeps selected drawn there too, so the row stays highlighted until you change selected, for example to None in on_back.

  • section – Optional function receiving an item and returning a section header (a nonempty str) or None. Neighbouring rows with the same result form one section under that header; None starts a section without one.

  • footer – None (default) or plain text shown under the list’s last row (under the last section with section), in the system’s footer style: footnote size, secondary colour. It scrolls with the rows, also shows on an empty list, and grows with the text size; blank lines separate paragraphs. An empty string shows no footer. Text only: no Markdown or views.

  • separators – True (default) draws a line between rows; False hides them.

  • selection_style – default draws the system highlight behind the selected row; none draws none there, so a row with its own background can show selected itself. A pressed row still highlights while the finger is down either way. Selection still works and VoiceOver still reads the row as selected.

  • deletable – Optional function receiving an item and returning False for a row that offers no Delete swipe, such as an action row; other rows keep on_delete’s swipe.

  • style – plain or inset. Defaults to plain.

  • anchor – None (default) or "bottom". With "bottom", after each update the list scrolls to its last row, without animation, when it was showing the end before the update. A list scrolled away from the end stays where it is.

  • context_menu – Optional function receiving an item and returning a Menu, or None for a row without one. Called for every row like row; a long press on the row shows its menu.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.TabView(*tabs, value, on_change, **P)

Bases: View

Show one of one to five tabs.

Parameters:
  • *tabs – Tab descriptions with unique keys.

  • value – Selected tab key, which must exist.

  • on_change – Function receiving a selected string key.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(*tabs, value, on_change, **P)

Build a controlled group of tabs.

Show one of one to five tabs.

Parameters:
  • *tabs – Tab descriptions with unique keys.

  • value – Selected tab key, which must exist.

  • on_change – Function receiving a selected string key.

  • **P – Common layout, key, disabled, and accessibility keywords.

class juno.ui.Tab(title, content, *, key, symbol=None)

Bases: View

Describe a named tab with a persistent selection key.

Parameters:
  • title – Tab label.

  • content – One view to show when selected.

  • key – Unique nonempty string used by TabView.value.

  • symbol – Optional SF Symbol name for the tab bar icon.

__init__(title, content, *, key, symbol=None)

Describe one keyed tab and its content.

Describe a named tab with a persistent selection key.

Parameters:
  • title – Tab label.

  • content – One view to show when selected.

  • key – Unique nonempty string used by TabView.value.

  • symbol – Optional SF Symbol name such as "gear" for the tab bar icon; an unknown name leaves the tab title-only.

class juno.ui.ScrollView(content, *, axis='vertical', anchor=None, indicators=True, **P)

Bases: View

Scroll one content view along one axis.

Parameters:
  • content – One view, often a VStack.

  • axis – vertical or horizontal; same-axis nesting is unavailable.

  • anchor – None or "bottom" to keep the end of the content in view.

  • indicators – False hides the scroll indicator.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(content, *, axis='vertical', anchor=None, indicators=True, **P)

Build a scrolling container for content.

Scroll one content view along one axis.

Parameters:
  • content – One view, often a VStack.

  • axis – vertical or horizontal; same-axis nesting is unavailable.

  • anchor – None (default) or "bottom", vertical axis only. With "bottom", after each update the content scrolls to its end, without animation, when it was showing the end before the update. Content scrolled away from the end stays where it is.

  • indicators – True (default) shows the scroll indicator while scrolling; False hides it.

  • **P – Common layout, key, disabled, and accessibility keywords. padding insets the content inside the scrolling area, so the scroll indicator stays at the view’s edge.

class juno.ui.Sheet(content, *, is_presented, on_dismiss, title='', top_bar=None, key=None)

Bases: View

Describe the window’s optional, non-blocking sheet.

Parameters:
  • content – One view shown in the sheet.

  • is_presented – Controlled bool; clear it when the user dismisses.

  • on_dismiss – Function accepting no arguments and clearing presentation.

  • title – Sheet title; defaults to an empty string.

  • top_bar – Optional view of Buttons, Text and TextFields, shown in a bar under the sheet’s title, as a Page’s top_bar.

  • key – Optional persistent sibling key.

Note

Include at most one Sheet, directly inside the root VStack of body or of a Page.

__init__(content, *, is_presented, on_dismiss, title='', top_bar=None, key=None)

Describe a controlled modal sheet.

Describe the window’s optional, non-blocking sheet.

Parameters:
  • content – One view shown in the sheet.

  • is_presented – Controlled bool; clear it when the user dismisses.

  • on_dismiss – Function accepting no arguments and clearing presentation.

  • title – Sheet title; defaults to an empty string.

  • top_bar – None (default) or one view of the kinds a Page’s top_bar holds, such as a search TextField, shown in a bar pinned under the sheet’s title, on the same material with a hairline below it. A List, vertical ScrollView, WebView or TabView at the top of the content runs under it. A TextField in it keeps its focus and text while the content changes.

  • key – Optional persistent sibling key.

Note

Include at most one Sheet, directly inside the root VStack of body or of a Page.

class juno.ui.NavigationStack(*pages, on_back=None, columns=2)

Bases: View

Show a stack of pages, the last one on top, with a back button.

Parameters:
  • *pages – One to sixteen Page descriptions with unique keys; the first is the root page.

  • on_back – Optional function receiving the key of the page the person went back to. Remove every page after that key from state.

  • columns – 2 (default) shows the root page beside the top page on a wide window; 1 shows one page at a time everywhere.

Note

Return NavigationStack from body as the window’s root; it cannot be placed inside another view. Append a page to state to push it and remove pages to pop them; removing pages calls nothing. On a wide window the root page shows beside the top page.

__init__(*pages, on_back=None, columns=2)

Build a navigation stack from pages kept in state.

Show a stack of pages, the last one on top, with a back button.

Parameters:
  • *pages – One to sixteen Page descriptions with unique keys; the first is the root page.

  • on_back – Optional function receiving the key of the page the person went back to with the back button or a swipe. Remove every page after that key from state. Without on_back, pages show no back button; remove pages from state to go back.

  • columns – 2 (default) or 1. With 1 every window shows one page at a time, as a narrow one does; a root without width/max_width still gets a readable column on an iPad.

Note

Return NavigationStack from body as the window’s root. Append a page to state to push it; remove pages to pop them, which calls nothing. Each page lays out from the top. On a wide window, such as an iPad in full screen, the root page shows in a column beside the top page, with “No Selection” while it is the only page; a narrow window shows one page at a time.

class juno.ui.Page(title, content, *, key, top_bar=None, bottom_bar=None)

Bases: View

Describe one keyed page of a NavigationStack.

Parameters:
  • title – Title shown in the navigation bar while the page is on top.

  • content – One view shown as the page.

  • key – Unique nonempty string identifying the page in its stack.

  • top_bar – Optional view of Buttons, Text and TextFields, often an HStack, shown in a bar under the navigation bar.

  • bottom_bar – Optional view of Buttons, Text and TextFields, often an HStack, shown in a bar along the bottom of the page.

Note

A List, vertical ScrollView, WebView or TabView at the top or bottom edge of the page’s content runs under the bars at that edge; other content sits between the bars.

__init__(title, content, *, key, top_bar=None, bottom_bar=None)

Describe one keyed page of a NavigationStack.

Parameters:
  • title – Title shown in the navigation bar while the page is on top.

  • content – One view shown as the page, laid out from the top.

  • key – Unique nonempty string identifying the page in its stack; on_back receives it.

  • top_bar – None (default) or one view of Buttons, Text and TextFields, often an HStack, shown in a bar pinned under the navigation bar, on the same material with a hairline below it. It may not hold a TextEditor, List, vertical ScrollView, TabView, WebView or Sheet.

  • bottom_bar – None (default) or one view of the same kinds, shown in a bar pinned along the bottom of the page. While a TextField in it is being edited, the bar sits on the keyboard.

Note

A List, vertical ScrollView, WebView or TabView at the top or bottom edge of the page’s content runs under the bars at that edge (the navigation bar and top_bar, or bottom_bar); other content sits between the bars.

juno.ui.run(body, state, *, title='Python UI', on_appear=None, tint=None, keep_awake=False)

Show body(state) and wait until the window closes.

Parameters:
  • body – Pure synchronous function returning one immutable view description.

  • state – Ordinary mutable data changed by callbacks.

  • title – Window title; defaults to Python UI.

  • on_appear – Optional no-argument function called once after appearance.

  • tint – Optional window tint, a colour name such as "teal" or hex "#RRGGBB" / "#RRGGBBAA". Every control without its own tint follows it, and the colour name accent means it.

  • keep_awake – When True, the screen does not dim or lock while the window is up and in the foreground, for a timer or a long download. Close, Stop and leaving the app give the screen back its usual timeout.

Raises:
  • UIError – Another run is active, the window connection fails, or the screen is unavailable to this run.

  • KeyboardInterrupt – Stop was pressed; the window is cleaned up first.

Return type:

None

Note

Callback exceptions close the window and propagate with their traceback. Call UI effects and cancel active timers on the thread calling run. Close and close() return None; Stop raises KeyboardInterrupt. SystemExit and callback exceptions remain the original errors if cleanup also fails. Without access to the screen, run raises UIError(“The window needs the screen. Save this script and run it in Juno to open the window.”).

juno.ui.close()

Close the active window and discard queued actions.

Returns:

None. Calling this without an active window is harmless.

Raises:

UIError – Called inside body or outside the thread running UI.

Return type:

None

juno.ui.after(ms, fn)

Schedule one synchronous callback on a later tick.

Parameters:
  • ms (int) – Nonnegative integer delay in milliseconds; 0 means a later tick.

  • fn – Function accepting no arguments.

Returns:

A Timer with an idempotent cancel() method.

Raises:

UIError – No run is active, called inside body or outside its callback thread, or timers are unavailable.

Return type:

Timer

Note

Call from a callback or on_appear. Dialog and background pauses form a union; overlap is counted once, and a timer born during a pause excludes the earlier part. Eight dequeued inputs allow one due timer, with at most one timer per tick and no resumed burst. Close cancels all timers.

class juno.ui.Timer

Bases: object

A one-shot timer returned by after(ms, fn).

Note

Create timers with after during a callback or on_appear. All timers are cancelled when the window closes.

cancel()

Cancel this timer; repeated calls are harmless.

Returns:

None.

Raises:

UIError – An active timer is cancelled from another thread or during body construction.

Return type:

None

juno.ui.alert(title, message='')

Show an OK dialog and wait for dismissal.

Parameters:
  • title – Dialog title.

  • message – Optional explanatory text.

Raises:

UIError – Dialogs are unavailable, or called outside a callback or inside body. Use juno.dialogs for dialogs outside run.

Return type:

None

Note

Call inside a callback, timer, or on_appear. The callback waits for the result. Other callbacks and timers pause; Close cancels the dialog and closes the entire window. A dialog shown before the window took any input since the previous dialog ended also offers Close Window, which ends ui.run.

juno.ui.confirm(title, message='', *, ok_text='OK', cancel_text='Cancel', destructive=False)

Wait for confirmation and return whether OK was chosen.

Parameters:
  • title – Dialog title.

  • message – Optional explanatory text.

  • ok_text – Confirmation button label.

  • cancel_text – Cancellation button label.

  • destructive – Whether the confirmation has destructive styling.

Returns:

True for confirmation, False for cancellation.

Raises:

UIError – Dialogs are unavailable, or called outside a callback or inside body. Use juno.dialogs for dialogs outside run.

Return type:

bool

Note

Call inside a callback, timer, or on_appear. The callback waits for the result. Other callbacks and timers pause; Close cancels the dialog and closes the entire window. A dialog shown before the window took any input since the previous dialog ended also offers Close Window, which ends ui.run.

juno.ui.prompt(title, message='', *, initial='', placeholder='', ok_text='OK', cancel_text='Cancel', secure=False)

Wait for single-line text input.

Parameters:
  • title – Dialog title.

  • message – Optional explanatory text.

  • initial – Initial text.

  • placeholder – Hint for empty input.

  • ok_text – Submission button label.

  • cancel_text – Cancellation button label.

  • secure – Whether to hide typed characters.

Returns:

Submitted text, including an empty string, or None for Cancel.

Raises:

UIError – Dialogs are unavailable, or called outside a callback or inside body. Use juno.dialogs for dialogs outside run.

Return type:

str | None

Note

Call inside a callback, timer, or on_appear. The callback waits for the result. Other callbacks and timers pause; Close cancels the dialog and closes the entire window. A dialog shown before the window took any input since the previous dialog ended also offers Close Window, which ends ui.run.

exception juno.ui.UIError

Bases: Exception

Raised when a window, dialog, or UI connection cannot continue.

Note

Invalid arguments raise TypeError or ValueError instead.

class juno.ui.TextEditor(placeholder='', *, text, on_change, debounce_ms=150, **P)

Bases: View

Edit multiple lines of controlled text.

Parameters:
  • placeholder – Hint shown while the text is empty.

  • text – Current string from state, at most 64 KiB of UTF-8.

  • on_change – Function receiving the whole text; update state here.

  • debounce_ms – Trailing change delay; 0 delivers on the next tick.

  • **P – Common layout, key, disabled, and accessibility keywords.

Note

Return inserts a newline. The editor fills the space its parent gives it and scrolls its own text; it cannot sit inside a vertical ScrollView or a List. Typing or pasting past 64 KiB is refused on screen.

__init__(placeholder='', *, text, on_change, debounce_ms=150, **P)

Build an editable multi-line text area.

Edit multiple lines of controlled text.

Parameters:
  • placeholder – Hint shown while the text is empty.

  • text – Current string from state, at most 64 KiB of UTF-8.

  • on_change – Function receiving the whole text; update state here.

  • debounce_ms – Trailing change delay; 0 delivers on the next tick. Text typed within the delay before Close, close() or Stop reaches on_change once, after the window closes; not after Stop interrupts a callback. In that last call ui.after and dialogs end the callback at once, so save before calling them.

  • **P – Common layout, key, disabled, and accessibility keywords.

Raises:
  • TypeError – An argument has the wrong type.

  • ValueError – text exceeds 64 KiB or debounce_ms is out of range.

Note

A new text from state that differs from what is on screen replaces it and clears the editor’s undo history; echoing the text received in on_change leaves both untouched.

class juno.ui.DatePicker(title, *, value, on_change, minimum=None, maximum=None, **P)

Bases: View

Choose a controlled date, time of day, or both.

The type of value picks the control: datetime.date shows a date, datetime.time a time of day, and a naive datetime.datetime both. Values are local wall time in whole minutes; seconds are ignored.

Parameters:
  • title – Row label.

  • value – Current date, time or naive datetime from state.

  • on_change – Function receiving a value of the same type as value.

  • minimum – Optional earliest value, of the same type as value.

  • maximum – Optional latest value, of the same type as value.

  • **P – Common layout, key, disabled, and accessibility keywords.

__init__(title, *, value, on_change, minimum=None, maximum=None, **P)

Build a labelled date or time row.

Choose a controlled date, time of day, or both.

Parameters:
  • title – Row label.

  • value – Current date, time or naive datetime from state.

  • on_change – Function receiving a value of the same type as value.

  • minimum – Optional earliest value, of the same type as value.

  • maximum – Optional latest value, of the same type as value.

  • **P – Common layout, key, disabled, and accessibility keywords.

Raises:
  • TypeError – If value is not a date, time or datetime, or a bound has a different type.

  • ValueError – If a value has a time zone, or value lies outside minimum and maximum.

class juno.ui.Menu(*items, title='', key=None)

Bases: View

A pull-down or context menu of MenuItems.

Parameters:
  • *items – One to 24 MenuItem or Menu descriptions.

  • title – Optional header.

  • key – Optional persistent sibling key.

__init__(*items, title='', key=None)

Describe a menu for Button(menu=…) or List(context_menu=…).

A pull-down or context menu of MenuItems.

Parameters:
  • *items – One to 24 MenuItem or Menu descriptions, shown in order. A Menu inside a Menu is a submenu when titled, or a group set off by separators when its title is empty; it cannot contain another Menu.

  • title – Optional text shown above the items.

  • key – Optional persistent sibling key; give submenus that can change order or come and go one, as for stack children.

class juno.ui.MenuItem(title, on_select, *, symbol=None, checked=False, destructive=False, disabled=False, key=None)

Bases: View

One choice in a Menu.

Parameters:
  • title – Nonempty item label.

  • on_select – Synchronous function accepting no arguments.

  • symbol – Optional SF Symbol name shown beside the title.

  • checked – Show a checkmark.

  • destructive – Draw the item in red.

  • disabled – Show the item dimmed; it cannot be chosen.

  • key – Optional persistent sibling key.

__init__(title, on_select, *, symbol=None, checked=False, destructive=False, disabled=False, key=None)

Describe one menu choice that calls on_select when chosen.

One choice in a Menu.

Parameters:
  • title – Nonempty item label.

  • on_select – Synchronous function accepting no arguments, called after the menu closes.

  • symbol – Optional SF Symbol name such as "trash"; an unknown name shows the title alone.

  • checked – True shows a checkmark; derive it from state for a single or multiple choice.

  • destructive – True draws the item in red.

  • disabled – True dims the item; it cannot be chosen.

  • key – Optional persistent sibling key.

class juno.ui.WebView(url=None, *, html=None, **P)

Bases: View

Show a web page or a piece of HTML inside the window.

Parameters:
  • url – http:// or https:// address of a page, loaded with JavaScript on.

  • html – HTML text up to 64 KiB, shown with JavaScript off and no base address: scripts do not run, and relative links, images and local files do not load.

  • **P – Common layout, key, disabled, and accessibility keywords.

Note

Pass url or html, not both. The view fills the space it is given, like List, with a 120-point minimum height, and cannot sit inside a vertical ScrollView or a List. It stays on the page you name: links within that page and the page’s own redirects work, a tapped link to another page opens in Safari over the window (Done returns to the window), mailto:, tel: and sms: links open their apps, and the page’s own forms do not submit (a form inside an embedded frame can). To show another page, return a WebView with a different url or html. A page that fails to load shows a message with Try Again. Nothing in the page can call Python and there is no JavaScript bridge, so build buttons, fields and lists with juno.ui views, not HTML. Cookies and site data last only as long as the view. Each WebView runs its own web content process; use one per screen. webbrowser.open(url) while the window is open shows an http or https page in the same Safari view over the window.

__init__(url=None, *, html=None, **P)

Build a view showing a web page or HTML text.

Parameters:
  • url – http:// or https:// address, loaded with JavaScript on.

  • html – HTML text up to 64 KiB, shown with JavaScript off and no base address; pass url or html, not both.

  • **P – Common layout, key, disabled, and accessibility keywords.

juno.ui.data_folder(name)

Return the folder an app keeps its data in, creating it if needed.

The folder is App Data/<name> in Juno’s folder in the Files app (On My iPhone or On My iPad, then Juno). It sits outside every script’s folder, so moving, deleting or restoring a script never touches it, and every copy of a script that asks for the same name gets the same folder. Keep settings, saved documents and caches there; keep files the script ships with beside the script and find them through __file__.

Parameters:

name (str) – The app’s name, used as the folder’s name: nonempty, at most 255 bytes in UTF-8, without / or \, not starting with . and not starting or ending with a space.

Returns:

A pathlib.Path to the folder, created if it did not exist. When it cannot be created (no space left, or a file in the way), the path is returned anyway and reading or writing there raises OSError.

Raises:
Return type:

Path

Typical usage:

from juno import ui

path = ui.data_folder("Tasks") / "tasks.json"