Text, images and progress

Use words and a picture to explain a number in your Python script’s native interface. A reading goal is easier to follow when the bar has a book title and a chapter count beside it.

A reading goal on iPhone A reading goal on iPhone
"""A bookmark that tracks chapters as you finish them."""

from dataclasses import dataclass

from juno import ui


CHAPTERS = 8


@dataclass
class State:
    read: int = 3


state = State()


def finish_chapter():
    state.read = min(state.read + 1, CHAPTERS)


def body(s):
    return ui.VStack(
        ui.HStack(ui.Image(symbol="book.fill", color="indigo", size=24),
                  ui.Text("The Glass Orchard", font="title2", weight="bold")),
        ui.Text(f"{s.read} of {CHAPTERS} chapters read"),
        ui.ProgressView(value=s.read / CHAPTERS, accessibility_label="Reading progress"),
        ui.Button("Finish a chapter", on_press=finish_chapter,
                  style="bordered", disabled=s.read == CHAPTERS),
        spacing=12, alignment="leading", padding=20, width="fill", max_width=480)


if __name__ == "__main__":
    ui.run(body, state, title="Reading goal")

Give the number a name

Use Text for the title and chapter count, and Image(symbol="book.fill") for the book symbol. For your own picture, give Image a file path or encoded image bytes. Give a picture that carries information an accessibility_label describing what it shows.

Show how far along you are

A ProgressView with a value from zero to one draws a bar. Divide chapters read by chapters in the book to get that fraction. Tap Finish a chapter to move from three chapters read to four. When you don’t know the fraction, omit value to show a spinner.

For a longer job with a Cancel button, see work in small steps.

Parameters

Text

Parameter

Default

Meaning

text

Required

A string; use str(number) for numbers.

font

'body'

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

weight

None

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

design

None

None, default, rounded, serif, or monospaced.

size

None

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

color

None

None for the label colour, a colour name, or hex.

markdown

False

When True, render inline Markdown in text.

Common keywords

key, padding, disabled, accessibility_label, width, height, min_width, min_height, max_width, max_height. See Description and callback rules.

Image

Parameter

Default

Meaning

source

None

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

symbol

None

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'

fit, fill, or center; defaults to fit.

color

None

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

multicolor

False

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

font

None

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

hierarchical

False

Symbol only: True draws color in layered opacities.

palette

None

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

size

None

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

Common keywords

key, padding, disabled, accessibility_label, width, height, min_width, min_height, max_width, max_height. See Description and callback rules.

ProgressView

Parameter

Default

Meaning

value

None

None for activity, or a finite number from 0 to 1; not bool.

label

''

Optional caption string.

Common keywords

key, padding, disabled, accessibility_label, width, height, min_width, min_height, max_width, max_height. See Description and callback rules.

Seen in

Run Device Dashboard from Home’s Native UI section and look at the memory card for another use of a progress bar.