Skip to content

Progress

rafageist edited this page Dec 2, 2026 · 3 revisions

Progress

The box Turbo Pascal showed while compiling, for anything that takes a while (turboframe.ui.progress).

Use it for a job the user waits for, and may stop: a build, a fetch, an import
Import from turboframe.ui.progress import ProgressDialog, run_with_progress, bar_text
Needs nothing beyond TurboFrame
Extend your rows, your verdict; AUTO_CLOSE, AUTO_CLOSE_PROBLEMS

The progress box

It has rows (File: shop.py), a clock, and a bar in Norton Commander's style, in CP437 blocks. The bar fills while the job says how far it is; when the job cannot say, a block goes back and forth. At the bottom it tells you what to do: Esc stops the job while it runs; then the verdict ("Success", "Errors") and any key closes it. The box also closes by itself, after 2 seconds for a success or 5 for a problem (AUTO_CLOSE, AUTO_CLOSE_PROBLEMS).

from textual import work

from turboframe.ui.progress import ProgressDialog, run_with_progress


@work                                  # a method of your DesktopApp
async def build(self) -> None:
    dialog = ProgressDialog("Build", [("Target", "")])

    async def job() -> int:
        for n, target in enumerate(targets):
            dialog.set("Target", target)
            await compile_one(target)
            dialog.progress((n + 1) / len(targets))
        return len(targets)

    done = await run_with_progress(self, dialog, job(), lambda n: ("Success", True, [("Built", str(n))]))
    if done is None:
        self.hint("stopped")
  • run_with_progress(app, dialog, job, verdict) returns the job's result as soon as it ends, or None when it was stopped with Esc, which cancels the job's task. An exception of the job closes the box and propagates.
  • verdict(result) gives (word, ok, rows): the word to show, whether it went well, and the final rows.
  • ProgressDialog(title, rows, width=52, stoppable=True): stoppable=False for a job that cannot be stopped.
  • dialog.set(label, value) changes or adds a row; dialog.progress(fraction) fills the bar (None: it cannot say).
  • bar_text(width, fraction=None) draws the bar alone, as Rich Text, for a status line. The language server's indexing uses it there (see The Editor).

Use a with app.busy("Indexing"): spinner in the status line instead for work the user does not wait for (see The Desktop). The Git menu's Pull, Push and Fetch run under this box (Git and Diffs); a command's output can go to a log meanwhile (Log and Output Windows).

The box ends filled whatever the verdict: the bar says how far the job got, the verdict how it went. Only a stopped job leaves it where it was.

A job under the progress box

API: turboframe.ui.progress.

Clone this wiki locally