Skip to main content

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 file
  • TextEntryDialog - Ask the user a question and get their answer using an Input 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:

screenshot

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:

screenshot

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:

screenshot

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textual_cogs-0.0.3.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

textual_cogs-0.0.3-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

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

Hashes for textual_cogs-0.0.3.tar.gz
Algorithm Hash digest
SHA256 def6e7370ae686cbcd0b3c70be509502be663f1daa4288c630c800b0f1bd455b
MD5 87670b03c9726af237a0643fe8cc5d25
BLAKE2b-256 4585dd0cb9a952506fbbe4f3fe4be71d04b25648a385733a6ad5dc1c94294a3c

See more details on using hashes here.

File details

Details for the file textual_cogs-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for textual_cogs-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b123e63ff59ed3bc6dd275bfa3a4b5cf64f6c6612cedd676073a0ef25f42e5e0
MD5 1501b631774619508bc8a91ba13f8e04
BLAKE2b-256 0c7be6bcaac5b5d6c28065865c3dff905361b46597d6245dff027b151c1fdcfc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page