Skip to content

Tutorial: A Tasks App

Getting Started builds a counter. This tutorial builds a small Tasks app in six steps, each a working program that adds one idea to the last, to show you the options you have: inline styling and separate files, built-in widgets and your own, one view or several, an ordinary window or your own frame. Every step is a folder in examples/tutorial/ that Tesserae's tests run; the page shows the files a step adds or changes.

The files here sit side by side. The same app as a project puts them in the folders tesserae new makes and finds them by name.

You need a working install (Getting Started). Make a folder for the app, and for each step put its files in it (or run a step straight from a checkout: python examples/tutorial/step3/app.py).

1. A screen

One screen: a title, a count, and a button. A view is a TDL file; its ViewModel is the Python that holds the state. The view says which ViewModel serves it with its Name, and the ViewModel says which views it serves with views.

Tasks_View.tdl
---
TDL: 0.2
Name: Tasks
Tesserae: "0.6"
---
Container {
  Name: Tasks
  Style { Flex_Direction: vertical, Width: 100%, Height: 100%, Gap: 12, Padding: 24, Background: surface }
  Children {
    Text {
      Name: title
      Text: Tasks
      Typography_Role: headline_medium
      Style { Foreground: on_surface }
    }
    Text {
      Name: summary
      Text: <| summary |>
      Typography_Role: body_large
      Style { Foreground: on_surface_variant }
    }
    Button {
      Name: add
      Label: "Add a task"
      Variant: filled
      Handlers {
        On_Click: add_task
      }
    }
  }
}
Tasks_ViewModel.py
from tess_ui import Computed, Signal, ViewModel


class TasksViewModel(ViewModel):
    views = "Tasks"  # the view it serves: the name after `View` at the top of Tasks_View.tdl

    def __init__(self):
        super().__init__()
        self.tasks = Signal([])
        self.summary = Computed(lambda: f"{len(self.tasks.get())} tasks")

    def add_task(self):
        self.tasks.update(lambda tasks: [*tasks, f"Task {len(tasks) + 1}"])
app.py
from pathlib import Path

from tess_ui import App

from Tasks_ViewModel import TasksViewModel

HERE = Path(__file__).parent

app = App(width=420, height=520, title="Tasks", root=HERE, search=["."], theme_seed=(0x0B, 0x6B, 0x58, 0xFF))
app.bind(TasksViewModel)
app.open_view("Tasks")
app.show("Tasks")
app.run()
  • Every node is a widget. Container { ... } lays things out, Text { ... } shows text, and Button { ... } is MD3's button; its keys are that widget's properties (Label, Variant), a Style { ... }, and a Name to find the node by. Every widget and component has a page.
  • Inline styling. Each node has its own Style { ... }, with colours named for theme roles (surface, on_surface), not hex codes, so they follow light and dark.
  • State. tasks is a Signal; summary is a Computed that follows it. A Signal reads as its value in a view, so Text: <| summary |> stays up to date, and Handlers { On_Click: add_task } calls add_task on a click.
  • The app. app.bind joins the ViewModel to the views it serves, app.open_view opens the view and app.show puts it in the window. theme_seed makes the colours, and search=["."] says the app's other views are found in this folder, which the next step uses.
python app.py

2. A list of views

A task is more than a line of text: it has a checkbox and a remove button. That makes it a view of its own, TaskItem, called once for each task. A view with Params is called by its name, with the params as keys, and For task In ... Key ... repeats the call for each element of a list, adding and removing rows as the list changes.

TaskItem_View.tdl
---
TDL: 0.2
Name: TaskItem
Tesserae: "0.6"
---
# One row. A view with `params:` is a component: Tasks_View.yaml calls it as `widget: TaskItem`.
Container {
  Params {
    Task { Type: dict, Required: true }
    On_Toggle { Type: handler }
    On_Remove { Type: handler }
  }
  Style { Flex_Direction: horizontal, Align_Content: left, Gap: 8, Width: 100% }
  Children {
    Checkbox {
      Name: done
      Checked: <| task.done |>
      Label: <| task.text |>
      Style { Flex: expand_horizontal }
      Handlers {
        On_Change: on_toggle
      }
    }
    IconButton {
      Name: remove
      Icon: close
      Label: Remove
      Handlers {
        On_Click: on_remove
      }
    }
  }
}
Tasks_View.tdl
---
TDL: 0.2
Name: Tasks
Tesserae: "0.6"
---
Container {
  Name: Tasks
  Style { Flex_Direction: vertical, Width: 100%, Height: 100%, Gap: 12, Padding: 24, Background: surface }
  Children {
    Text {
      Name: title
      Text: Tasks
      Typography_Role: headline_medium
      Style { Foreground: on_surface }
    }
    Text {
      Name: summary
      Text: <| summary |>
      Typography_Role: body_large
      Style { Foreground: on_surface_variant }
    }
    Button {
      Name: add
      Label: "Add a task"
      Variant: filled
      Handlers {
        On_Click: add_task
      }
    }
    Container {
      Name: list
      Style { Flex_Direction: vertical, Gap: 4, Width: 100% }
      Children {
        For task In <| tasks |> Key <| task.id |> {
          TaskItem {
            Name: row
            Task: <| task |>
            On_Toggle: "toggle(task.id)"
            On_Remove: "remove(task.id)"
          }
        }
      }
    }
  }
}
Tasks_ViewModel.py
from tess_ui import Computed, Signal, ViewModel


class TasksViewModel(ViewModel):
    views = "Tasks"

    def __init__(self):
        super().__init__()
        self.tasks = Signal([])  # a list of {"id", "text", "done"}: the one source of truth
        self._next_id = 1
        self.summary = Computed(lambda: f"{len(self.tasks.get())} tasks")

    def add_task(self):
        task = {"id": self._next_id, "text": f"Task {self._next_id}", "done": False}
        self._next_id += 1
        self.tasks.update(lambda tasks: [*tasks, task])

    def toggle(self, task_id):
        self.tasks.update(lambda tasks: [{**t, "done": not t["done"]} if t["id"] == task_id else t for t in tasks])

    def remove(self, task_id):
        self.tasks.update(lambda tasks: [t for t in tasks if t["id"] != task_id])
  • tasks holds one dictionary for each task, and is the single source of truth. Each change replaces the list, which is how a view notices it. The Key is the task's id, so a row that stays is kept as it is.
  • A view cannot read the names of the view that calls it, so what it needs comes in as a param: task is the data. On_Toggle and On_Remove are handler params: the caller writes what to do (remove(task.id) is written in the caller's names) and the row runs it by name.
  • A row removes itself by changing the list; nobody tears the row down by hand.
  • A Checkbox shows Checked and runs On_Change when the user changes it. Its Checked here is a plain expression, so it is one-way, and the ViewModel makes the change.

See Components & Embedding and Component Views.

3. Styling in files

Inline Style is fine for one node. Two kinds of file take styling out of the views:

Brand_Theme.tdl
---
TDL: 0.2
Name: Brand
Tesserae: "0.6"
---
Theme {
  Seed: "#0B6B58"
  Typography {
    Headline_Medium { Font_Weight: 600 }
  }
}
Tasks_Stylesheet.tdl
---
TDL: 0.2
Name: Tasks
Tesserae: "0.6"
---
Styles {
  Rule {
    Widget: Container
    Classes: [page]
    Style { Flex_Direction: vertical, Width: 100%, Height: 100%, Gap: 12, Padding: 24, Background: surface }
  }
  Rule { Widget: Text, Classes: [heading], Style { Foreground: on_surface } }
  Rule { Widget: Text, Classes: [muted], Style { Foreground: on_surface_variant } }
  # a rule for a view of your own: every TaskItem is a row
  Rule { Widget: TaskItem, Style { Flex_Direction: horizontal, Align_Content: left, Gap: 8, Width: 100% } }
  Rule { Widget: Container, Classes: [rows], Style { Flex_Direction: vertical, Gap: 4, Width: 100% } }
  # the add button, a tertiary one: a rule for Button goes over the one Tesserae ships
  Rule { Widget: Button, Variant: filled, Style { Background: tertiary } }
  Rule { Widget: Button, Variant: filled, Part: label, Style { Foreground: on_tertiary } }
}
Tasks_View.tdl
---
TDL: 0.2
Name: Tasks
Tesserae: "0.6"
---
Container {
  Name: Tasks
  Classes: [page]
  Children {
    Text {
      Name: title
      Classes: [heading]
      Text: Tasks
      Typography_Role: headline_medium
    }
    Text {
      Name: summary
      Classes: [muted]
      Text: <| summary |>
      Typography_Role: body_large
    }
    Button {
      Name: add
      Label: "Add a task"
      Variant: filled
      Style { Width: 140 }
      Handlers {
        On_Click: add_task
      }
    }
    Container {
      Name: list
      Classes: [rows]
      Children {
        For task In <| tasks |> Key <| task.id |> {
          TaskItem {
            Name: row
            Task: <| task |>
            On_Toggle: "toggle(task.id)"
            On_Remove: "remove(task.id)"
          }
        }
      }
    }
  }
}
TaskItem_View.tdl
---
TDL: 0.2
Name: TaskItem
Tesserae: "0.6"
---
Container {
  Params {
    Task { Type: dict, Required: true }
    On_Toggle { Type: handler }
    On_Remove { Type: handler }
  }
  Children {
    Checkbox {
      Name: done
      Checked: <| task.done |>
      Label: <| task.text |>
      Style { Flex: expand_horizontal }
      Handlers {
        On_Change: on_toggle
      }
    }
    IconButton {
      Name: remove
      Icon: close
      Label: Remove
      Handlers {
        On_Click: on_remove
      }
    }
  }
}
app.py
from pathlib import Path

from tess_ui import App

from Tasks_ViewModel import TasksViewModel

HERE = Path(__file__).parent

app = App(
    width=420,
    height=520,
    title="Tasks",
    root=HERE,
    search=["."],
    custom_theme=HERE / "Brand_Theme.tdl",   # the colours: made from one seed
    stylesheet=HERE / "Tasks_Stylesheet.tdl",  # the look of every screen
)
app.bind(TasksViewModel)
app.open_view("Tasks")
app.show("Tasks")
app.run()
  • A theme (Brand_Theme.tdl) is app-wide: one Seed colour makes the whole palette, and Typography changes a type style. Pass it as App(custom_theme=).
  • A stylesheet (Tasks_Stylesheet.tdl) is rules. A rule names a widget and may narrow it by Classes, a property (Variant), a Part (a named node inside that widget) and a State, and gives a Style. A node that says Classes: [page] is styled by the rule with Classes: [page]. Pass the file as App(stylesheet=).
  • A rule for a view of your own. A TaskItem rule styles the root of every TaskItem, so the row's layout is no longer written in its file.
  • A rule for a widget Tesserae ships. The two Button rules go over the shipped look of a filled button, field by field: here, a tertiary one. Part: label is the button's text.

A node's own Style always wins, then the stylesheet, then the theme. See Themes.

4. A view of your own

Two numbers in the same shape: that is a view with params. Stat is a file like any other, and there is no other kind of component.

Stat_View.tdl
---
TDL: 0.2
Name: Stat
Tesserae: "0.6"
---
# A number with a label under it, called as `widget: Stat`. Its look is its rules in Tasks_Stylesheet.yaml.
Container {
  Params {
    Label { Type: str, Required: true }
    Value { Type: str, Required: true }
  }
  Children {
    Text {
      Name: value
      Text: <| value |>
      Typography_Role: title_large
    }
    Text {
      Name: label
      Text: <| label |>
      Typography_Role: label_medium
    }
  }
}
Tasks_View.tdl
---
TDL: 0.2
Name: Tasks
Tesserae: "0.6"
---
Container {
  Name: Tasks
  Classes: [page]
  Children {
    Text {
      Name: title
      Classes: [heading]
      Text: Tasks
      Typography_Role: headline_medium
    }
    Container {
      Name: stats
      Classes: [row]
      Children {
        Stat {
          Name: open
          Label: Open
          Value: <| open_text |>
        }
        Stat {
          Name: finished
          Label: Done
          Value: <| done_text |>
        }
      }
    }
    Button {
      Name: add
      Label: "Add a task"
      Variant: filled
      Style { Width: 140 }
      Handlers {
        On_Click: add_task
      }
    }
    Container {
      Name: list
      Classes: [rows]
      Children {
        For task In <| tasks |> Key <| task.id |> {
          TaskItem {
            Name: row
            Task: <| task |>
            On_Toggle: "toggle(task.id)"
            On_Remove: "remove(task.id)"
          }
        }
      }
    }
  }
}
Tasks_ViewModel.py
from tess_ui import Computed, Signal, ViewModel


class TasksViewModel(ViewModel):
    views = "Tasks"

    def __init__(self):
        super().__init__()
        self.tasks = Signal([])  # a list of {"id", "text", "done"}: the one source of truth
        self._next_id = 1
        # a text property wants a string, so the counts are strings
        self.open_text = Computed(lambda: str(sum(1 for t in self.tasks.get() if not t["done"])))
        self.done_text = Computed(lambda: str(sum(1 for t in self.tasks.get() if t["done"])))

    def add_task(self):
        task = {"id": self._next_id, "text": f"Task {self._next_id}", "done": False}
        self._next_id += 1
        self.tasks.update(lambda tasks: [*tasks, task])

    def toggle(self, task_id):
        self.tasks.update(lambda tasks: [{**t, "done": not t["done"]} if t["id"] == task_id else t for t in tasks])

    def remove(self, task_id):
        self.tasks.update(lambda tasks: [t for t in tasks if t["id"] != task_id])
Tasks_Stylesheet.tdl
---
TDL: 0.2
Name: Tasks
Tesserae: "0.6"
---
Styles {
  Rule {
    Widget: Container
    Classes: [page]
    Style { Flex_Direction: vertical, Width: 100%, Height: 100%, Gap: 12, Padding: 24, Background: surface }
  }
  Rule { Widget: Text, Classes: [heading], Style { Foreground: on_surface } }
  Rule { Widget: Text, Classes: [muted], Style { Foreground: on_surface_variant } }
  # a rule for a view of your own: every TaskItem is a row
  Rule { Widget: TaskItem, Style { Flex_Direction: horizontal, Align_Content: left, Gap: 8, Width: 100% } }
  Rule { Widget: Container, Classes: [rows], Style { Flex_Direction: vertical, Gap: 4, Width: 100% } }
  # the add button, a tertiary one: a rule for Button goes over the one Tesserae ships
  Rule { Widget: Button, Variant: filled, Style { Background: tertiary } }
  Rule { Widget: Button, Variant: filled, Part: label, Style { Foreground: on_tertiary } }
  Rule { Widget: Container, Classes: [row], Style { Flex_Direction: horizontal, Gap: 12 } }
  # the look of Stat: a rule for the widget, and one for each of its named parts
  Rule {
    Widget: Stat
    Style { Flex_Direction: vertical, Align_Content: top, Width: 96, Padding: 12, Background: secondary_container, Corner_Radius: medium }
  }
  Rule { Widget: Stat, Part: value, Style { Foreground: on_secondary_container } }
  Rule { Widget: Stat, Part: label, Style { Foreground: on_secondary_container } }
}
  • Stat { ... } finds Stat_View.tdl by its name. Its params are Label and Value.
  • Value is an expression written where the view is called, so each stat keeps up with its Computed. (A text property takes a string, so the Computeds return strings.)
  • Its look is rules for Stat in the app's stylesheet: one for the view's root and one for each named part (Part: value).
  • A view has no state of its own unless it says State, and no ViewModel of its own: it reads its params, then the names of the ViewModel that serves the view at the top. TaskItem and Stat are the same kind of thing, a repeated look or a repeated piece; the behaviour stays in the one ViewModel.

5. A second screen

A screen is a view that is opened and registered with the app. Settings is a second one, and the two share state: the app owns it, and any ViewModel reads it as self.state.

Settings_View.tdl
---
TDL: 0.2
Name: Settings
Tesserae: "0.6"
---
Container {
  Name: Settings
  Classes: [page]
  Children {
    Text {
      Name: title
      Classes: [heading]
      Text: Settings
      Typography_Role: headline_medium
    }
    TextField {
      Name: name
      Label: "Your name"
      Text: <| name |>
      Style { Width: 240 }
    }
    Container {
      Name: buttons
      Classes: [row]
      Children {
        Button {
          Name: theme
          Label: "Light or dark"
          Variant: outlined
          Handlers {
            On_Click: toggle_dark
          }
        }
        Button {
          Name: back
          Label: Back
          Variant: text
          Disabled: <| not app.can_go_back |>
          Handlers {
            On_Click: go_back
          }
        }
      }
    }
  }
}
Settings_ViewModel.py
from tess_ui import ViewModel


class SettingsViewModel(ViewModel):
    views = "Settings"

    def __init__(self, state):
        super().__init__()
        self.name = state.user  # the shared Signal itself: a bare reference to a Signal is two-way

    def toggle_dark(self):
        self.app.set_dark(not self.app.dark)  # every screen switches, in place

    def go_back(self):
        self.app.back()
Tasks_View.tdl
---
TDL: 0.2
Name: Tasks
Tesserae: "0.6"
---
Container {
  Name: Tasks
  Classes: [page]
  Children {
    Text {
      Name: title
      Classes: [heading]
      Text: <| app.state.user |>'s tasks
      Typography_Role: headline_medium
    }
    Container {
      Name: stats
      Classes: [row]
      Children {
        Stat {
          Name: open
          Label: Open
          Value: <| open_text |>
        }
        Stat {
          Name: finished
          Label: Done
          Value: <| done_text |>
        }
      }
    }
    Container {
      Name: buttons
      Classes: [row]
      Children {
        Button {
          Name: add
          Label: "Add a task"
          Variant: filled
          Handlers {
            On_Click: add_task
          }
        }
        Button {
          Name: settings
          Label: Settings
          Variant: text
          Handlers {
            On_Click: open_settings
          }
        }
      }
    }
    Container {
      Name: list
      Classes: [rows]
      Children {
        For task In <| tasks |> Key <| task.id |> {
          TaskItem {
            Name: row
            Task: <| task |>
            On_Toggle: "toggle(task.id)"
            On_Remove: "remove(task.id)"
          }
        }
      }
    }
  }
}
Tasks_ViewModel.py
from tess_ui import Computed, Signal, ViewModel


class TasksViewModel(ViewModel):
    views = "Tasks"

    def __init__(self):
        super().__init__()
        self.tasks = Signal([])  # a list of {"id", "text", "done"}: the one source of truth
        self._next_id = 1
        # a text property wants a string, so the counts are strings
        self.open_text = Computed(lambda: str(sum(1 for t in self.tasks.get() if not t["done"])))
        self.done_text = Computed(lambda: str(sum(1 for t in self.tasks.get() if t["done"])))

    def add_task(self):
        task = {"id": self._next_id, "text": f"Task {self._next_id}", "done": False}
        self._next_id += 1
        self.tasks.update(lambda tasks: [*tasks, task])

    def toggle(self, task_id):
        self.tasks.update(lambda tasks: [{**t, "done": not t["done"]} if t["id"] == task_id else t for t in tasks])

    def remove(self, task_id):
        self.tasks.update(lambda tasks: [t for t in tasks if t["id"] != task_id])

    def open_settings(self):
        self.app.navigate("Settings")  # a step the user can go back from
app.py
import sys
from pathlib import Path

from tess_ui import App, Signal

from Settings_ViewModel import SettingsViewModel
from Tasks_ViewModel import TasksViewModel

HERE = Path(__file__).parent


class AppState:
    """What every screen shares: `self.state` in a ViewModel, `state` in a view."""

    def __init__(self):
        self.user = Signal("Ada")


state = AppState()
app = App(
    width=420,
    height=520,
    title="Tasks",
    root=HERE,
    search=["."],
    custom_theme=HERE / "Brand_Theme.tdl",
    stylesheet=HERE / "Tasks_Stylesheet.tdl",
    state=state,
)
app.bind(TasksViewModel)
app.bind(SettingsViewModel(state))  # a ViewModel you made yourself
app.open_view("Tasks")
app.open_view("Settings")
app.route("", "Tasks")
app.route("settings", "Settings")

app.navigate_to(sys.argv[1] if len(sys.argv) > 1 else "")  # a route: `python app.py settings`
app.run()
  • state=state gives every screen the same user Signal. A view reads it as app.state.user, so the heading on the Tasks screen follows the name typed in Settings.
  • The Settings field edits the Signal, and a bare reference to a Signal is what makes a property two-way, so SettingsViewModel is made with the state and holds the Signal as name. app.bind(SettingsViewModel(state)) binds the instance you made; app.bind(TasksViewModel) has Tesserae make its one instance.
  • app.navigate("Settings") is a step the user can go back from, and app.back() goes back. The Back button's Disabled is bound to app.can_go_back, so it greys out when there is nowhere to go.
  • app.route(...) names screens by strings, so python app.py settings opens on Settings.
  • app.set_dark(...) switches every screen between light and dark, in place.

See Apps & Screens.

6. A custom window

With Borderless: true the OS draws no title bar, and the app draws its own frame. The window view is that frame: a Window file with a title bar (which gets the window's buttons), a navigation rail that switches screens, a status bar, and the screens themselves, each a call of a view with a Route. The app opens the one file, and the window's file now brings the two screens in.

Window_View.tdl
---
TDL: 0.2
Name: Window
Tesserae: "0.6"
---
# The frame around the screens. With no OS title bar, the window's own title bar is the one at the top.
Window {
  Name: Window
  Title: Tasks
  Borderless: true  # no OS title bar: the title bar below is the window's
  Min_Width: 480
  Min_Height: 360
  Style { Width: 640, Height: 480, Background: surface, Flex_Direction: vertical }
  Title_Bar { Title: Tasks, Style { Background: primary_container }, Buttons: [minimize, maximize, close] }
  Children {
    Container {
      Name: body
      Style { Flex: fill, Flex_Direction: horizontal }
      Children {
        NavigationRailScreens {
          Name: nav
          Items {
            Item { Label: Tasks, Icon: home, Screen: Tasks }
            Item { Label: Settings, Icon: settings, Screen: Settings }
          }
        }
        Container {
          Name: screens
          Style { Flex: fill }
          Children {
            Tasks {
              Name: tasks
              Route: ""
              Style { Flex: fill }
            }
            Settings {
              Name: settings
              Route: settings
              Style { Flex: fill }
            }
          }
        }
      }
    }
    StatusBar {
      Name: status
      Text: Ready
      Style { Width: 100% }
    }
  }
}
Tasks_View.tdl
---
TDL: 0.2
Name: Tasks
Tesserae: "0.6"
---
# A screen of the window: it has no `name:` and no ViewModel of its own. It reads the names of the one that serves Window_View.yaml.
Container {
  Classes: [page]
  Children {
    Text {
      Name: title
      Classes: [heading]
      Text: <| app.state.user |>'s tasks
      Typography_Role: headline_medium
    }
    Container {
      Name: stats
      Classes: [row]
      Children {
        Stat {
          Name: open
          Label: Open
          Value: <| open_text |>
        }
        Stat {
          Name: finished
          Label: Done
          Value: <| done_text |>
        }
      }
    }
    Button {
      Name: add
      Label: "Add a task"
      Variant: filled
      Style { Width: 140 }
      Handlers {
        On_Click: add_task
      }
    }
    Container {
      Name: list
      Classes: [rows]
      Children {
        For task In <| tasks |> Key <| task.id |> {
          TaskItem {
            Name: row
            Task: <| task |>
            On_Toggle: "toggle(task.id)"
            On_Remove: "remove(task.id)"
          }
        }
      }
    }
  }
}
Settings_View.tdl
---
TDL: 0.2
Name: Settings
Tesserae: "0.6"
---
Container {
  Classes: [page]
  Children {
    Text {
      Name: title
      Classes: [heading]
      Text: Settings
      Typography_Role: headline_medium
    }
    TextField {
      Name: name
      Label: "Your name"
      Text: <| name |>
      Style { Width: 240 }
    }
    Container {
      Name: buttons
      Classes: [row]
      Children {
        Button {
          Name: theme
          Label: "Light or dark"
          Variant: outlined
          Handlers {
            On_Click: toggle_dark
          }
        }
      }
    }
  }
}
Window_ViewModel.py
from tess_ui import Computed, Signal, ViewModel


class WindowViewModel(ViewModel):
    """Serves Window_View.tdl, and so the Tasks and Settings screens in it: they read these names."""

    views = "Window"

    def __init__(self, state):
        super().__init__()
        self.name = state.user  # Settings: the shared Signal itself, so the field is two-way
        self.tasks = Signal([])  # Tasks: a list of {"id", "text", "done"}
        self._next_id = 1
        self.open_text = Computed(lambda: str(sum(1 for t in self.tasks.get() if not t["done"])))
        self.done_text = Computed(lambda: str(sum(1 for t in self.tasks.get() if t["done"])))

    def add_task(self):
        task = {"id": self._next_id, "text": f"Task {self._next_id}", "done": False}
        self._next_id += 1
        self.tasks.update(lambda tasks: [*tasks, task])

    def toggle(self, task_id):
        self.tasks.update(lambda tasks: [{**t, "done": not t["done"]} if t["id"] == task_id else t for t in tasks])

    def remove(self, task_id):
        self.tasks.update(lambda tasks: [t for t in tasks if t["id"] != task_id])

    def toggle_dark(self):
        self.app.set_dark(not self.app.dark)
app.py
import sys
from pathlib import Path

from tess_ui import App, Signal

from Window_ViewModel import WindowViewModel

HERE = Path(__file__).parent


class AppState:
    """What every screen shares: `self.state` in a ViewModel, `app.state` in a view."""

    def __init__(self):
        self.user = Signal("Ada")


state = AppState()
app = App(
    title="Tasks",
    root=HERE,
    search=["."],
    custom_theme=HERE / "Brand_Theme.tdl",
    stylesheet=HERE / "Tasks_Stylesheet.tdl",
    state=state,
)
app.bind(WindowViewModel(state))
app.open_view("Window")  # the window: its title bar, its rail, and the screens in it

app.navigate_to(sys.argv[1] if len(sys.argv) > 1 else "")
app.run()
  • Style on the Window is the window's size and colour, and the title bar takes a Style too, so its colour is yours to set.
  • A call with a Route is a screen: Tasks { ... } is the view Tasks_View.tdl, and the app can navigate("Tasks"), show("Tasks") or navigate_to("") it. A routed screen is part of the window view, not opened by itself, so it has no Name and no ViewModel of its own: it reads the names of the ViewModel that serves the window. That is why Tasks_ViewModel.py and Settings_ViewModel.py are now one, Window_ViewModel.py, serving Window: delete the two old files, which nothing uses any more.
  • The rail replaces the Settings and Back buttons, so they are gone from the screens.
  • The window is still resizable (from its edges), and the title bar still drags it.

See Windows, Docks & Embedded Views and Custom Title Bars.

Where next

  • Edit a view or a theme file while the app runs with app.run(hot_reload=True) and the window changes at once, your tasks kept: see Hot Reload for what it watches.
  • tesserae build --check turns the app into one executable: Releasing Your App.
  • Browse the components, and the TDL and Python references.