Skip to content

Your First Application

rafageist edited this page Dec 2, 2026 · 2 revisions

Your First Application

This tutorial builds a TurboFrame application in five steps, from an empty desktop to windows, menus, dialogs, themes and background tasks. Each step is a program in examples/tutorial that runs on its own, and each one is tested in CI, so what you read here is what runs.

Step You learn
1. Hello (this page) DesktopApp, the menu bar, the status line, commands, hints
2. [Windows and menus](Tutorial-Windows-and-Menus) numbered windows, Alt+1..9, F6, Tile and Cascade, a list you filter by typing
3. [Dialogs](Tutorial-Dialogs) File Open, Find with a history, message boxes, input dialogs, a settings store
4. [Themes](Tutorial-Themes) Options > Colors, switching themes, colour roles in CSS and in code
5. [Tasks](Tutorial-Tasks) the progress box, running a command, git and the diff viewer, a busy spinner

Install TurboFrame first (Installation), then clone the repository to have the examples:

git clone https://github.com/divengine/turboframe
cd turboframe
pip install -e .

Step 1: Hello

python examples/tutorial/step1_hello.py

Step 1: a desktop, a menu bar and a status line

The whole program, step1_hello.py:

# SPDX-License-Identifier: GPL-3.0-or-later
"""Step 1: the smallest TurboFrame application. A desktop, a menu bar, a status line, Alt+X to exit.

    python examples/tutorial/step1_hello.py
"""

from __future__ import annotations

from textual_vision.constants import Command
from textual_vision.menus import Menu, MenuItem, SubMenu
from textual_vision.status_line import StatusDef, StatusItem

from turboframe.ui.app import DesktopApp


class Hello(DesktopApp):
    TITLE = "Hello"

    def init_menu_bar(self) -> Menu:
        # ~X~ marks the hotkey: Alt+F opens File, then X runs Exit
        return Menu([SubMenu("~F~ile", MenuItem("E~x~it", Command.QUIT, "Alt+X"))])

    def init_status_line(self) -> list[StatusDef]:
        # the status line's items are keys too: a click or the key runs the command
        return [StatusDef(0, 0xFFFF, [StatusItem("~Alt+X~ Exit", "alt+x", Command.QUIT),
                                      StatusItem("~F10~ Menu", "f10", Command.MENU)])]

    # Textual calls on_mount and on_command_message of every class in the hierarchy, the subclass's first.
    # So the tutorial's later steps do not redefine them: they override start() and handle(), and call
    # super() when they want what the step before did.
    def on_mount(self) -> None:
        self.start()

    def on_command_message(self, message) -> None:
        if self.handle(message.command):
            message.prevent_default()  # handled: textual-vision's own handler (Exit, F10...) is not called

    def start(self) -> None:
        """What the application does once its screen is up."""
        self.hint("Welcome to TurboFrame")

    def handle(self, command: int) -> bool:
        """Run one of the application's own commands; False for the others (textual-vision's run them)."""
        return False


if __name__ == "__main__":
    Hello().run()

What it does

DesktopApp is the base of every TurboFrame application. It is a textual-vision Application, so a Textual App, that already:

  • registers TurboFrame's nine themes and starts in Turbo Pascal's;
  • draws Turbo Vision's drop shadows under menus, dialogs and windows;
  • puts a menu bar at the top and a status line at the bottom;
  • numbers windows and binds Alt+1..9 to them;
  • fixes Alt+letter and Alt+digit in terminals that send them as Esc and a key;
  • ends every process the application started, however it exits.

See The Desktop for all of it.

The menu bar comes from init_menu_bar(): a Menu of SubMenus of MenuItems. In a label, the letter between tildes is its hotkey: ~F~ile opens with Alt+F, and inside it E~x~it runs with X. The third argument of MenuItem ("Alt+X") is only the text shown at the right; a key works because a binding or a status item says so.

The status line comes from init_status_line(): a list of StatusDef(min, max, items). Each StatusItem(text, key, command) shows its text, binds its key and runs its command when clicked. StatusDef(0, 0xFFFF, ...) applies to every help context; the numbers exist because Turbo Vision changed the status line by context.

Commands are integers. textual-vision's own (Command.QUIT, Command.MENU, Command.OK...) do what they say. Your own start at Command.USER; step 2 adds some. TurboFrame keeps Command.USER + 10000 and above for itself.

on_mount and on_command_message need a word of warning, and the program shows the pattern the next steps use. Textual calls these handlers on every class in the hierarchy, the subclass's first, unless one calls message.prevent_default(). So step 1 defines them once and calls two plain methods, start() and handle(command), which later steps override like any Python method, calling super() when they want the step before. DesktopApp's own on_mount and on_unmount keep running either way.

hint(text) writes in the status line, after its items.

Try it

  • F10 opens the menu; arrows move; Esc closes it.
  • Alt+F opens File directly; X exits.
  • Alt+X exits from anywhere: it is a status line item.

Next: Step 2: windows and menus.

Clone this wiki locally