Dynamic Screens

While a program runs, it can put its own screens on the display: a calibration wizard, a “press the button to start” prompt, a progress indicator, a live sensor view. These are called dynamic screens. BotUI does not know any of them in advance. It receives a description of the screen from your program, draws it, and sends your taps back.

This page describes what BotUI does with such a screen. To show a screen from your Python code, see UI Steps & Screens in the programming guide. You do not need this page to use the built-in screens; it helps when you build your own screens, or when a screen does not behave as expected.

The Protocol

Two transport channels carry everything (Transport ):

ChannelDirectionContent
raccoon/screen_renderprogram → BotUIThe screen to show, as JSON
raccoon/screen_render/answerBotUI → programWhat the user did, as JSON (sent reliably)
sequenceDiagram
    participant P as Program (raccoon-lib)
    participant T as Transport
    participant B as BotUI
    P->>T: screen_render {title, body, …}
    T->>B: new screen data
    Note over B: draws the widget tree
    B->>T: answer {_action: "click", button_id: "ok", values: {…}}
    T->>P: event handler runs
    P->>T: screen_render {screen: "close"}
    T->>B: close
    Note over B: back to the normal UI

BotUI subscribes to screen_render as soon as it starts, so a program can show a screen at any time. A screen is always sent with the name dynamic_ui; any other name is ignored.

What the Program Sends

A screen is a JSON object:

{
  "title": "Distance Calibration",
  "setup_timer": { "seconds": 120, "paused": false },
  "body": {
    "widget": "column",
    "children": [
      { "widget": "text", "text": "Push the robot 30 cm", "size": "large" },
      { "widget": "numericinput", "id": "distance", "value": 30, "unit": "cm" },
      { "widget": "button", "id": "next", "label": "Next", "style": "primary" }
    ]
  }
}
FieldMeaning
titleText in the top bar
bodyThe root widget (see below)
setup_timerOptional countdown in the top bar
"screen": "close"A message with this field closes the screen

Sending a new screen replaces the old one in place. The same widget tree is simply drawn again, there is no opening and closing in between. A program can update a screen many times per second; BotUI limits the update rate to about 10 per second and always draws the last one of a burst, so nothing gets lost and the Pi is not overloaded.

What BotUI Sends Back

Every answer has an _action, the current values of all input widgets (by their id), and the details of the event:

_actionSent whenExtra fields
clicka button is tappedbutton_id
changean input widget changeswidget_id, value
keypada key of a number pad is tappedkey

values starts from the value of every widget that has an id and a value in the screen, and is updated on every change.

Widgets

The body is a tree. Layout widgets contain other widgets in children.

Layout

WidgetFieldsNotes
columnchildren, align (stretch), spacing (12)Vertical
rowchildren, align (center), spacing (8)Horizontal
centerchildrenCenters its content
containerchildren, bg_color, paddingA box with a background
cardchildren, title, padding (16)A box with a border and an optional title
splitleft, right, ratioTwo columns next to each other
expandedchild, flex (1)Takes the remaining space in a row or column
spacerheight (16)Empty space
dividerthickness, colorA line

A body without a widget field that has children is treated as a column.

Text and Status

WidgetFields
texttext, size (small 14, medium 18, large 24, title 48, xlarge 72, xxlarge 96), bold, muted, align, color
iconname, size (24), color
statusbadgetext, color, glow
statusiconicon (default check), color (green), animated (true)
hintboxtext, icon (touch_app), style (prominent for a big one)
distancebadgevalue, unit (cm), color
resultstablerows: list of lists
progressspinnersize (24), color (orange)

Colors are grey, green, amber, orange, red, blue, white, black, or a hex value such as #FF8800.

Input

Input widgets have an id. Their value is part of every answer.

WidgetFieldsValue
buttonid, label, style (primary, secondary, success, danger, warning), icon, disabledSends click
sliderid, min (0), max (100), value, label, show_value (true)Number
circularsliderid, min, max, value, labelNumber
checkboxid, label, valueBoolean
dropdownid, options, value, labelSelected string
numericinputid, value, unit, show_adjust_buttons (true)Number, with plus and minus buttons
textinputid, value, label, placeholderString
numerickeypadSends keypad events for each key

Live Data and Animation

WidgetFieldsShows
sensorvalueport, sensor_type (analog or digital, default analog)The current value of that port (read directly from the transport, no round trip to the program)
sensorgraphport, sensor_type (analog or digital), max_points (50)A live graph of that port
calibrationchartsamples, thresholds, series, height (200)The chart of an IR sensor calibration
camfeedid, show_fps, show_detections (true), tappableThe live camera picture, optionally with detections. If tappable, a tap sends a change for the widget’s id with the value {"x": …, "y": …}.
lightbulbis_onA light bulb that is on or off
animatedrobotmoving, size (120)A robot that drives or stands
robotdrivinganimationtarget_distance (30)A robot driving the given distance
measuringtapedistance (30)A measuring tape
pulsingarrowA pulsing arrow

An unknown widget name is drawn as red text Unknown widget: <name> and the rest of the screen still works. If you see this, the library is newer than BotUI (check Versions ) or the name is misspelled.

Setup Timer

If the screen has a setup_timer, a countdown is shown at the right of the top bar. The Botball setup period is the typical use.

"setup_timer": { "seconds": 120, "paused": false }
  • BotUI counts down by itself, once per second, so the program does not have to send a message every second.
  • The counter only jumps when the seconds value in a new message changes. A screen update with the same seconds does not disturb the running count.
  • "paused": true freezes it.
  • The timer is green above 30 s, orange at 30 s and below, red at 10 s and below, and keeps counting into negative numbers (overtime, shown with a minus sign and a red border). A paused timer is grey.

How a Dynamic Screen Fits Into BotUI

  • It covers everything. A dynamic screen is drawn above all other screens and overlays. The low-battery popup and the hardware-shutdown popup are hidden while it is up, so they cannot block the screen of a running program. The program decides when it ends.
  • No back button. The system back gesture does nothing, and the top bar has no back arrow. Only the program (by sending close) removes the screen.
  • The Dev Menu stays on top. Holding button 10 for 2 seconds opens the Dev Menu above a dynamic screen, so you can always stop a program that is stuck on a screen.
  • The screensaver gives way. If the screensaver is up when a screen opens, it is dismissed. While a screen is open, the screensaver does not start.

Troubleshooting

SymptomLikely reason
A screen never showsThe program is not publishing on raccoon/screen_render, or raccoon-transport is not in the same bundle version as BotUI (Settings → Versions )
The screen is stuck after the program endedThe program crashed before it sent close. Stop it from the Dev Menu and use Restart UI if the screen stays.
Buttons do nothingThe button is disabled, or the program does not handle the id that comes back
The display freezes while logic continuesThe rendering pipeline stalled, see below

If the display freezes while the program keeps running (some very busy screens on the Pi 3 can do this), the frame stall watchdog notices after a few seconds, tries to get the pipeline going again and otherwise restarts the UI. See Under the Hood .