A collection of Textual dialogs.
Dialogs included so far:
- Generic
MessageDialog
- shows messages to the user SaveFileDialog
- gives the user a way to select a location to save a fileSingleChoiceDialog
- gives the user a series of choices to pick fromTextEntryDialog
- ask the user a question and get their answer using anInput
widget
You can install textual-cog
using pip:
python -m pip install textual-cog
You also need Textual to run these dialogs.
Here is an example of creating a small application that opens the MessageDialog
immediately. You would normally open the dialog in response to a message or event that has occurred, such as when the application has an error or you need to tell the user something.
from textual.app import App
from textual.app import App, ComposeResult
from textual_cogs.dialogs import MessageDialog
from textual_cogs import icons
class DialogApp(App):
def on_mount(self) -> ComposeResult:
def my_callback(value: None | bool) -> None:
self.exit()
self.push_screen(
MessageDialog(
"What is your favorite language?",
icon=icons.ICON_QUESTION,
title="Warning",
),
my_callback,
)
if __name__ == "__main__":
app = DialogApp()
app.run()
When you run this code, you will get something like the following:
Here is how you would create a TextEntryDialog
:
from textual.app import App
from textual.app import App, ComposeResult
from textual_cogs.dialogs import TextEntryDialog
class DialogApp(App):
def on_mount(self) -> ComposeResult:
def my_callback(value: str | bool) -> None:
self.exit()
self.push_screen(
TextEntryDialog("What is your name?", "Information"), my_callback
)
if __name__ == "__main__":
app = DialogApp()
app.run()
When you run this code, you will see the following:
The following code demonstrates how to create a SaveFileDialog
:
from textual.app import App
from textual.app import App, ComposeResult
from textual_cogs.dialogs import SaveFileDialog
class DialogApp(App):
def on_mount(self) -> ComposeResult:
self.push_screen(SaveFileDialog())
if __name__ == "__main__":
app = DialogApp()
app.run()
When you run this code, you will see the following: