Skip to content

The Desktop

rafageist edited this page Dec 3, 2026 · 5 revisions

The Desktop

DesktopApp (turboframe.ui.app) is the base of a TurboFrame application. It is a textual-vision Application, so a Textual App, with everything a Turbo Vision desktop does before your own features.

Use it for the application class of every TurboFrame program
Import from turboframe.ui.app import DesktopApp; from turboframe.ui.desktop import FRAMEWORK_COMMANDS, check_commands
Needs nothing beyond TurboFrame (Textual and textual-vision come with it)
Extend subclass it; override init_menu_bar(), init_status_line(), raise_window(); mix features in (see Application Mixins)

A TurboFrame desktop

What DesktopApp does for you

It So that
fixes Alt+letter and Alt+digit (turboframe.ui.compat.fix_alt_keys) Alt+F opens File and Alt+1 brings window 1 up in terminals that send Esc and the key
draws scroll bars' thumbs in whole cells (turboframe.ui.compat.install_cell_scrollbars) every scroll bar keeps to CP437, as the rest of the screen (below)
starts in the theme and colour depth its store keeps, or in those you pass Options > Colors' choice holds on the next start
registers the nine themes, with their $tf-* roles your CSS and your code can use the roles
paints the desktop, the menus' active item and the hotkeys from the roles the monochrome themes stay readable
repaints what code paints on a theme change shadows, lists and diffs follow the theme
draws Turbo Vision's drop shadows (ShadowScreen) menus, dialogs and windows cast them
uses DropMenuBar and HintStatusLine F10 drops the first menu; the status line shows hints and a spinner
binds Alt+1..9 to the windows with those numbers
lets processes start once mounted, and when it closes starts no more, waits for those being started, and kills what is left nothing it started outlives it

Starting

from turboframe.config import JsonStore
from turboframe.ui.app import DesktopApp

settings = JsonStore("myapp")         # ~/.config/myapp/config.json


class MyApp(DesktopApp):
    TITLE = "My application"

    def __init__(self) -> None:
        self.colors_store = settings  # load() -> dict, save(dict): where "palette" and "colors" are kept
        super().__init__()            # reads colors_store: set it first

DesktopApp(*, palette=None, colors=None, **kwargs): a theme name ("modern-dark") and a colour depth ("auto", "truecolor", "256", "16") that override what the store keeps; the other arguments go to Textual's App. A command-line option of yours can pass them through. The store is described in Settings and Recent Files. Without one, the application starts in turbo-pascal and Options > Colors keeps nothing.

The menu bar and the status line

Override textual-vision's init_menu_bar() and init_status_line(), as in Your First Application.

F10, the arrows, Alt+F and a letter

  • DropMenuBar: F10 opens the first menu at once, as Turbo Vision does.
  • HintStatusLine: the status line's items, then a hint.
    • app.hint(text) writes the hint.
    • with app.busy("Indexing"): adds a spinner and a label while the block runs. Several can run at once: the line shows the latest.

Commands

A command is an integer posted as a CommandMessage by a menu item, a status item, a button or your code (app.post_message(CommandMessage(CM_X))). textual-vision handles its own (Command.QUIT, Command.MENU...). Number yours from Command.USER:

CM_OPEN = Command.USER + 1
CM_FIND = Command.USER + 2
check_commands([CM_OPEN, CM_FIND])  # ValueError on a duplicate, or one in TurboFrame's range

FRAMEWORK_COMMANDS (Command.USER + 10000 to + 10999) is TurboFrame's own range: the dialogs', the explorer's, the Git menu's, the editor's, the palette's and Options > Language's commands live there, so yours never clash with them. Application Mixins has the table. check_commands is in turboframe.ui.desktop.

A menu item's key text ("F3") is only shown. To make the key work, bind it with Textual's BINDINGS to an action that posts the command; Application Mixins shows the pattern.

Handlers run on every class. Textual calls on_command_message (and on_mount, on_key...) on every class of your application's hierarchy, the subclass's first, until one calls message.prevent_default(). Handle your commands in one place, prevent the default when you did, and let the rest reach textual-vision's handler. The tutorial's handle() pattern does exactly that.

Windows

Method
insert_window(window) textual-vision's: on the desktop, on top
windows() the windows, bottom to top
active_window() the one on top, or None
free_number() the lowest number from 1 to 9 no window has (0: all taken)
raise_window(window) bring it up; override it (calling super()) to update your status line
action_window(n) Alt+n
cycle_windows(forward=True) F6 (forward) and Shift+F6
desktop.tile(), desktop.cascade() arrange the windows; tile() leaves the windows docked at a side uncovered (below)

See Windows and Lists for the windows themselves.

Tile beside the explorer

desktop.tile() arranges the tileable windows in a grid. Since v0.2.1 it leaves out the columns of the windows docked at a side: a window that is shown, not tileable, not zoomed, and against the desktop's left or right edge. The explorer is one (ExplorerWindow is not tileable), so Window > Tile puts the editors beside it, not over it. desktop.tile_region() says which part it uses; desktop.tile(region) uses the region you give. To keep a window of your own out of tiling and docked:

window.tv_options &= ~OptionFlag.TILEABLE   # from textual_vision.constants

The desktop is TurboFrame's turboframe.ui.desktop.DeskTop, which DesktopApp.init_desktop() returns.

Dialogs

await app.run_dialog(dialog), from a worker, runs a dialog modally and returns the command it ended with; app.dialog_open() says whether one is up. See Dialogs.

Closing

DesktopApp.on_unmount stops new processes from starting, waits for those being started, and kills those still running (see Processes). Your own on_unmount runs too, before it. Stop your servers there.

Alt keys in the terminal

Many terminals send Alt+F as two bytes, Esc and f. Textual reads that as two keys. fix_alt_keys() makes Textual read Esc followed at once by a letter or a digit as Alt+that key. DesktopApp calls it; an application that does not use DesktopApp calls it once, before its App starts. It is idempotent. On macOS (untested), Option+digit no longer types its symbol in a text field.

Whole-cell scroll bars

Textual draws a scroll bar's thumb with eighths of a cell at its ends (▁▂▃, ▉▊▋). Those are not CP437 (see Glyphs): a font without them draws something else, or two cells wide. So DesktopApp installs CellScrollBarRender, which draws the thumb in whole cells, as Turbo Vision did, on every Textual scroll bar: an editor's, a scrolling view's, a list's.

  • DesktopApp.CELL_SCROLLBARS = False, in your subclass, keeps Textual's eighths.
  • install_cell_scrollbars() (turboframe.ui.compat) does it for an application that does not use DesktopApp. It changes Textual's ScrollBar.renderer, the way Textual documents, for the whole process; it returns False when it was already installed.
class MyApp(DesktopApp):
    CELL_SCROLLBARS = False   # Textual's own thumbs

The scroll bars on a window's border (FrameScrollBar, see Windows and Lists) are Turbo Vision's own, drawn by textual-vision in CP437 whatever this setting says.

API: turboframe.ui.app, turboframe.ui.desktop, turboframe.ui.compat.

Features you mix in

DesktopApp already includes ColorsMixin: choose_colors() runs Options > Colors (see Themes and Colors). The other features are mixins you add before DesktopApp; Application Mixins composes them all:

Clone this wiki locally