Dialogs for use with the Textual package.
Project description
textual-cogs
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 fileTextEntryDialog
- Ask the user a question and get their answer using anInput
widget
Installation
You can install textual-cog
using pip:
python -m pip install textual-cog
You also need Textual to run these dialogs.
Example Usage
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:
Creating a TextEntryDialog
Here
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:
Creating a SaveFileDialog
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:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file textual_cogs-0.0.3.tar.gz
.
File metadata
- Download URL: textual_cogs-0.0.3.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | def6e7370ae686cbcd0b3c70be509502be663f1daa4288c630c800b0f1bd455b |
|
MD5 | 87670b03c9726af237a0643fe8cc5d25 |
|
BLAKE2b-256 | 4585dd0cb9a952506fbbe4f3fe4be71d04b25648a385733a6ad5dc1c94294a3c |
File details
Details for the file textual_cogs-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: textual_cogs-0.0.3-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b123e63ff59ed3bc6dd275bfa3a4b5cf64f6c6612cedd676073a0ef25f42e5e0 |
|
MD5 | 1501b631774619508bc8a91ba13f8e04 |
|
BLAKE2b-256 | 0c7be6bcaac5b5d6c28065865c3dff905361b46597d6245dff027b151c1fdcfc |