Repository navigation
Dialogs
turboframe.ui.dialogs has Turbo Vision's dialogs, laid out as Turbo Pascal's, with shadows over the desktop.
| Use it for | asking, confirming, choosing a file, finding text, any modal form |
| Import | from turboframe.ui.dialogs import MessageBox, FileDialog, InputDialog, TVDialog, confirm, information |
| Needs | nothing beyond TurboFrame |
| Extend | subclass TVDialog (compose_content, valid); FileDialog.SELECT_NAME
|
![]() |
![]() |
![]() |
![]() |
From a worker, await app.run_dialog(dialog) returns the command the dialog ended with (see The Desktop). Without DesktopApp: await app.push_screen_wait(DialogScreen(dialog)). Esc is Cancel. Enter in an input line or a cluster presses the default button.
| Dialog | Returns | Afterwards |
|---|---|---|
MessageBox(title, text, buttons, *, width=52, default=0) |
the button's command | |
confirm(title, text) |
Command.YES, Command.NO, or Cancel (Esc) |
|
information(title, text) |
Command.OK |
|
replace_prompt() |
Yes, No, All (CM_CHANGE_ALL), Cancel |
|
FileDialog(title, directory, *, name="", pattern="*", ok_label=None, folders=False, buttons=(), select_name=None) |
Command.OK, Cancel, or a button of yours |
.chosen (a Path) |
SearchDialog(replace=..., query=..., replacement=..., options=...) (all required) |
Command.OK, CM_CHANGE_ALL (Replace's Change all) |
.search_text, .replacement, .options
|
GotoLineDialog(line) |
Command.OK (only with a valid number) |
.line |
InputDialog(title, label, text="", *, hint="", select=None, browse=None, browse_folders=False, allow_empty=False, history=None) |
Command.OK |
.value |
ColorsDialog(current, detected, *, depth="auto", sample=None) (turboframe.ui.colors) |
Command.OK |
.choice, .depth; see Themes and Colors
|
Other modules have dialogs of their own: FindInFilesDialog (Search), ProgressDialog (Progress), PaletteDialog (Command Palette), LanguageDialog (Languages).
Message boxes. buttons is a list of (label, command, id). A plain letter presses the button whose hotkey it is. default chooses the button that starts focused and that Enter presses. Point a question about something risky at its safe answer.
from textual_vision.constants import Command
from turboframe.ui.dialogs import MessageBox
box = MessageBox("Delete", "Delete 3 files?", [("~D~elete", Command.YES, "yes"), ("~C~ancel", Command.CANCEL, "no")],
default=1)
if await app.run_dialog(box) == Command.YES:
...File dialog. Typing a folder goes into it; a wildcard (*.py) filters; .. goes up. folders=True chooses a folder. buttons adds buttons that end the dialog with their own command. The name line is selected at first when select_name=True, or for all of an application's dialogs when it sets FileDialog.SELECT_NAME = True. browse_into(dialog, line, title, pattern, start) opens a file dialog over another dialog and writes the chosen path into its input line.
Input dialog. One line of text with its history: history names it, "input:<title>" by default, so each kind of question has its own. browse=(pattern, folder) adds a Browse button (browse_folders=True: it picks a folder). select=(start, end) selects part of the text at first (a file's name without its extension). An empty line is refused unless allow_empty=True; hint is a line of help under it.
dialog = InputDialog("Rename", "~N~ew name", "report.txt", select=(0, 6))
if await app.run_dialog(dialog) == Command.OK:
rename(dialog.value)Subclass TVDialog and yield its controls from compose_content(). Use textual-vision's Label, InputLine, Button, CheckBoxes and RadioButtons, and TurboFrame's HistoryInput.
from textual.app import ComposeResult
from textual.containers import Horizontal
from textual_vision.button import Button
from textual_vision.constants import Command
from textual_vision.input_line import InputLine
from textual_vision.label import Label
from turboframe.ui.dialogs import TVDialog
from turboframe.ui.history import HistoryInput
class NameDialog(TVDialog):
DEFAULT_CSS = "NameDialog { width: 50; height: 9; }"
def __init__(self) -> None:
super().__init__(title="New project")
self.line = InputLine(max_len=80)
self.project_name = ""
def compose_content(self) -> ComposeResult:
yield Label("~N~ame", link=self.line)
yield HistoryInput(self.line, "project-name")
with Horizontal(classes="dlg-buttons"):
yield Button("O~K~", Command.OK, is_default=True, id="ok")
yield Button("Cancel", Command.CANCEL, id="cancel")
def valid(self, command: Command) -> bool:
"""Called before the dialog ends: False keeps it open."""
if command == Command.OK:
self.project_name = self.line.data.strip()
return bool(self.project_name)
return TrueA dialog is a Textual widget: an attribute of yours must not take a name Textual already uses (name, title, id, screen...), or setting it fails. What its input lines hold joins their histories when it ends with anything but Cancel. A dialog's ready becomes True once its own start-up is done (its text selected); turboframe.testing.dialog_ready waits for it, so a test's keys are never lost (see Testing). _Dialog is an older name of TVDialog.
API: turboframe.ui.dialogs.
TurboFrame · part of Divengine · GPL-3.0-or-later · report an issue
Tutorial
Examples
The desktop
- The Desktop
- Application Mixins
- Windows and Lists
- Dialogs
- Histories
- Progress
- Themes and Colors
- Glyphs
- Settings and Recent Files
- Command Palette
Editing
Tasks
Languages
Running
Reference
Links



