Orientation · Lesson 02 of 05

Connect text and colour to Data

Use pointers to change text and colour from inputs, then organize several fields inside a border container.

5:12 · English5 sectionsPrerequisites: The working Hello world project from orientation lesson 01.
Course contents
WATCH THE LESSON5:12 · English
Download MP4 ↓English captions ↓

Recorded with released Gramlot 0.3.8. Animated source editing, a scrolling terminal with automatic Uvicorn reload, and a synchronized live browser. Data pointers change text and colour through inputs, then the same bindings move into a border layout with fields. AI-generated English narration; captions and exact runnable stages included.

Read the transcript / on-screen steps

00:00:00 In this lesson, we will make our welcome page react to Data.

00:00:04 We will replace fixed text with a pointer, then use inputs to change the message and

00:00:09 its colour.

00:00:10 Finally, we will arrange the page in a border container and add name, email and

00:00:15 quantity fields.

00:00:16 We will write each change, save it, and refresh the browser before trying it.

00:00:22 Open the orientation example project from the lesson download in your activated

00:00:27 Python environment.

00:00:29 Its host already registers the published layout components we will use.

00:00:33 The Page is the welcome greeting from lesson one.

00:00:36 Start Uvicorn with app colon application and dash dash reload.

00:00:41 Open its local address in the browser.

00:00:43 We will keep this server running throughout the lesson.

00:00:48 First, give the message a place in Data.

00:00:54 Type data Setter with the literal path demo dot message and its initial value.

00:00:59 In the heading, replace the fixed greeting with caret demo dot message.

00:01:03 The caret makes this a reactive pointer to the value at that path.

00:01:07 We have only edited the file; the browser has not changed.

00:01:11 Save, wait for Uvicorn to reload, then refresh the browser.

00:01:18 The greeting looks the same, but its declaration now follows Data.

00:01:24 Add a label containing a text input below the heading.

00:01:28 Bind its value to the same caret demo dot message, and enable live editing.

00:01:33 The label gives the field its visible name.

00:01:36 Save the file and refresh the browser after automatic server reload.

00:01:43 Now type Hello, Ada in the Message field.

00:01:46 Each keystroke changes Data, and the heading follows immediately.

00:01:50 No file save or browser reload is needed when editing a live input.

00:01:55 Both elements follow the same Data value.

00:01:59 Now add a Data value for colour, starting with steelblue.

00:02:09 Bind the heading colour attribute to caret demo dot color, and add a Colour input

00:02:14 using the same pointer.

00:02:15 Save, wait for server reload, and refresh the browser.

00:02:22 Type crimson in the Colour field.

00:02:25 The title changes colour while its text stays the same.

00:02:28 Type Hello, Ada in the Message field, then change the colour to seagreen.

00:02:32 A pointer can drive the content of an element or one of its attributes.

00:02:37 The Python file has not changed during these input edits.

00:02:42 Keep the Data declarations and arrange the interface in a border container.

00:03:04 Give it a fixed height, then add a top content pane for the heading.

00:03:08 Put the two existing inputs in a left content pane, and add a centre pane for the

00:03:13 form.

00:03:13 Their pointers stay exactly the same.

00:03:16 Save, wait for automatic reload, and refresh the browser.

00:03:22 Now the heading is at the top, settings are on the left, and the centre has space

00:03:27 for our fields.

00:03:28 Move the divider to resize the settings area.

00:03:31 The container organizes space; the pointers still connect controls to Data.

00:03:37 Initialize three more Data values: name, email and quantity.

00:04:01 Add a labelled input for each value in the centre pane, using explicit paths in the

00:04:07 person branch.

00:04:08 The quantity input has type number.

00:04:10 Save the file and refresh after automatic server reload.

00:04:23 Change the name to Grace, the email to grace at example dot com, and the quantity to

00:04:28 three.

00:04:29 Then change the message to Welcome, Grace and the colour to crimson.

00:04:35 The original bindings still work inside the new layout.

00:04:39 We now have a small workspace with independent values in Data.

00:04:44 We initialized Data with data Setter and connected declarations to it with reactive

00:04:50 pointers.

00:04:50 We changed text and colour through live inputs, without manually updating the

00:04:55 heading.

00:04:55 Then we arranged the controls in a border container and added fields with their own

00:05:00 paths.

00:05:01 Source edits required saving and refreshing; input edits changed Data immediately.

00:05:06 In the next lesson, the Inspector will let us explore Data and Source directly.

Follow the recorded example

The video uses the runnable Pages in the orientation examples download. Each stage is included, together with setup instructions and the optional published Inspector. Recordings use Gramlot 0.3.8, Python adapter 0.2.12 and JavaScript adapters 0.2.15.

The recording starts from the orientation example project in the download. Its host registers the published layout components used later in this lesson. Each visible label contains its input, giving the field an accessible name without introducing extra identifiers.

Give the greeting a value in Data

Start with the welcome page from lesson 01. Its greeting is currently literal text in Source. Introduce a Data value for the message and replace the literal greeting with a reactive pointer to that value. In the recorded release, dataSetter initializes each value. We show the Python declaration, save it, wait for Uvicorn to reload automatically, and explicitly refresh the browser.

For this first example, use explicit paths such as demo.message and demo.color. A pointer such as ^demo.message reads the value at that Data path and follows changes. The declaration keeps the pointer; Data holds the current message.

pages/index.py · message in Data
from gramlot import Page as BasePage


class Page(BasePage):
    title = "Welcome to Gramlot"

    def main(self, root):
        page = root.main(padding="16px", font_family="system-ui")
        page.dataSetter("demo.message", "Welcome to Gramlot")
        page.h1("^demo.message")

Change the text and colour through inputs

Bind a text input to the same message path as the heading. With live=True, each keystroke changes Data and the heading follows its pointer immediately. These input edits do not save the Python file or reload the browser.

Initialize demo.color with steelblue and bind the heading colour attribute to ^demo.color. A second text input edits that path: type crimson or seagreen and watch the heading change colour. The Colour field accepts CSS colour names. There is no event handler manually updating the heading.

Give the page a border layout

Introduce a borderContainer with top, left and center contentPane regions. Move the heading into the top pane and the existing message and colour controls into the left pane. Keep their literal pointers unchanged, then save and refresh. Drag the divider to resize the settings area.

Add a few explicit fields, such as name, email and quantity, with their own literal Data paths. Put the message and colour controls in the side area. The container organizes space; each binding still identifies the value the control reads or edits. Relative and symbolic paths are introduced in lesson 04.

What we have learned

We initialized Data, bound content and attributes with pointers, and edited the values through live inputs. We then organized top, left and centre regions and added name, email and quantity fields. Source edits require saving and refreshing; live input edits update Data immediately. The next lesson explores Data and Source in the Inspector.

Your turn

Try it yourself

  1. Replace the literal greeting with a pointer to demo.message and bind a text input to the same path.
  2. Add a colour input and connect the heading colour to demo.color.
  3. Place the heading, settings and several fields into a border layout; check that the original bindings still work.

Check your understanding

When typing changes the greeting, did the Python file change?

Show the answer and expected result

No. The input changed the value in Data. The heading’s Source declaration still contains its pointer, and the runtime updates the display from that value. Editing the page file is a separate authoring action.

Working examples and reference