textual-forms


Nametextual-forms JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/rhymiz/textual-forms
SummaryDynamic forms for Textual TUI Framework
upload_time2022-12-19 20:45:23
maintainer
docs_urlNone
authorLemuel Boyce
requires_python>=3.7,<4.0
licenseMIT
keywords tui terminal form widget
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Textual Forms

[![Python Versions](https://shields.io/pypi/pyversions/textual-inputs)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Downloads](https://pepy.tech/badge/textual-forms)](https://pepy.tech/project/textual-forms)
[![Downloads](https://pepy.tech/badge/textual-forms/month)](https://pepy.tech/project/textual-forms)

Dynamic forms for [Textual](https://github.com/willmcgugan/textual) TUI framework.

> #### Note: This library is still very much WIP 🧪

## About

Textual Forms aims to make it easy to add forms to your Textual-powered applications.

### Development Requirements

* python >=3.7,<4
* poetry

## Install

```bash
pip install textual-forms
```

## Forms

`textual_forms.forms.Form`

## Buttons

`textual_forms.buttons.Button`

## Fields

`textual_forms.fields.StringField`

`textual_forms.fields.NumberField`

`textual_forms.fields.IntegerField`

### Custom fields and validators

```python
from __future__ import annotations

from typing import Any

from textual_forms.fields import Field
from textual_forms.validators import FieldValidator


class UUIDValidator(FieldValidator):
    def validate(self, value: str, rules: dict[str, Any]) -> tuple[bool, str | None]:
        return True, None


class UUIDField(Field):
    validator = UUIDValidator()

    def __init__(
        self,
        name: str,
        *,
        value: str | None = None,
        required: bool = False,
        placeholder: str | None = None,
        **kwargs,
    ):
        data: dict[str, Any] = {
            "name": name,
            "value": value,
            "required": required,
            "placeholder": placeholder,
            "rules": {},
        }
        super().__init__(data, **kwargs)
```

---

## Example

```python
from rich.table import Table
from textual.app import App, ComposeResult
from textual.widgets import Static

from textual_forms.forms import Form
from textual_forms.fields import StringField, IntegerField
from textual_forms.buttons import Button


class BasicTextualForm(App):
    def compose(self) -> ComposeResult:
        yield Static(id="submitted-data")
        yield Static("Order for beers")
        yield Form(
            fields=[
                StringField("name"),
                IntegerField("age", required=True, min_value=21),
            ],
            buttons=[
                Button(
                    "Submit",
                    enabled_on_form_valid=True,
                )
            ],
        )

    def on_form_event(self, message: Form.Event) -> None:
        if message.event == 'submit':
            table = Table(*message.data.keys())
            table.add_row(*message.data.values())
            self.query_one('#submitted-data').update(table)


if __name__ == '__main__':

    BasicTextualForm().run()

```

**Initial render**
<img width="1004" alt="Screenshot 2022-11-15 at 3 49 46 PM" src="https://user-images.githubusercontent.com/7029352/202023490-e6494105-a102-4d9d-9072-90872ecad41a.png">

**Valid form**
<img width="1006" alt="Screenshot 2022-11-15 at 3 51 15 PM" src="https://user-images.githubusercontent.com/7029352/202023592-1a16f742-6af2-4e88-a9d3-7b84339fd231.png">

**Invalid form**
<img width="1006" alt="Screenshot 2022-11-15 at 3 51 39 PM" src="https://user-images.githubusercontent.com/7029352/202023734-76ae0b55-01b4-48a4-8a34-7c972d7a7df9.png">

## Contributing

TBD

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rhymiz/textual-forms",
    "name": "textual-forms",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "tui,terminal,form,widget",
    "author": "Lemuel Boyce",
    "author_email": "lemuelboyce@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/50/9f/93e647877fdc83e5fdbc767bcc8b1d8ae4e4f5da3432bb18f33f7ba51a3e/textual_forms-0.2.0.tar.gz",
    "platform": null,
    "description": "# Textual Forms\n\n[![Python Versions](https://shields.io/pypi/pyversions/textual-inputs)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Downloads](https://pepy.tech/badge/textual-forms)](https://pepy.tech/project/textual-forms)\n[![Downloads](https://pepy.tech/badge/textual-forms/month)](https://pepy.tech/project/textual-forms)\n\nDynamic forms for [Textual](https://github.com/willmcgugan/textual) TUI framework.\n\n> #### Note: This library is still very much WIP \ud83e\uddea\n\n## About\n\nTextual Forms aims to make it easy to add forms to your Textual-powered applications.\n\n### Development Requirements\n\n* python >=3.7,<4\n* poetry\n\n## Install\n\n```bash\npip install textual-forms\n```\n\n## Forms\n\n`textual_forms.forms.Form`\n\n## Buttons\n\n`textual_forms.buttons.Button`\n\n## Fields\n\n`textual_forms.fields.StringField`\n\n`textual_forms.fields.NumberField`\n\n`textual_forms.fields.IntegerField`\n\n### Custom fields and validators\n\n```python\nfrom __future__ import annotations\n\nfrom typing import Any\n\nfrom textual_forms.fields import Field\nfrom textual_forms.validators import FieldValidator\n\n\nclass UUIDValidator(FieldValidator):\n    def validate(self, value: str, rules: dict[str, Any]) -> tuple[bool, str | None]:\n        return True, None\n\n\nclass UUIDField(Field):\n    validator = UUIDValidator()\n\n    def __init__(\n        self,\n        name: str,\n        *,\n        value: str | None = None,\n        required: bool = False,\n        placeholder: str | None = None,\n        **kwargs,\n    ):\n        data: dict[str, Any] = {\n            \"name\": name,\n            \"value\": value,\n            \"required\": required,\n            \"placeholder\": placeholder,\n            \"rules\": {},\n        }\n        super().__init__(data, **kwargs)\n```\n\n---\n\n## Example\n\n```python\nfrom rich.table import Table\nfrom textual.app import App, ComposeResult\nfrom textual.widgets import Static\n\nfrom textual_forms.forms import Form\nfrom textual_forms.fields import StringField, IntegerField\nfrom textual_forms.buttons import Button\n\n\nclass BasicTextualForm(App):\n    def compose(self) -> ComposeResult:\n        yield Static(id=\"submitted-data\")\n        yield Static(\"Order for beers\")\n        yield Form(\n            fields=[\n                StringField(\"name\"),\n                IntegerField(\"age\", required=True, min_value=21),\n            ],\n            buttons=[\n                Button(\n                    \"Submit\",\n                    enabled_on_form_valid=True,\n                )\n            ],\n        )\n\n    def on_form_event(self, message: Form.Event) -> None:\n        if message.event == 'submit':\n            table = Table(*message.data.keys())\n            table.add_row(*message.data.values())\n            self.query_one('#submitted-data').update(table)\n\n\nif __name__ == '__main__':\n\n    BasicTextualForm().run()\n\n```\n\n**Initial render**\n<img width=\"1004\" alt=\"Screenshot 2022-11-15 at 3 49 46 PM\" src=\"https://user-images.githubusercontent.com/7029352/202023490-e6494105-a102-4d9d-9072-90872ecad41a.png\">\n\n**Valid form**\n<img width=\"1006\" alt=\"Screenshot 2022-11-15 at 3 51 15 PM\" src=\"https://user-images.githubusercontent.com/7029352/202023592-1a16f742-6af2-4e88-a9d3-7b84339fd231.png\">\n\n**Invalid form**\n<img width=\"1006\" alt=\"Screenshot 2022-11-15 at 3 51 39 PM\" src=\"https://user-images.githubusercontent.com/7029352/202023734-76ae0b55-01b4-48a4-8a34-7c972d7a7df9.png\">\n\n## Contributing\n\nTBD\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Dynamic forms for Textual TUI Framework",
    "version": "0.2.0",
    "split_keywords": [
        "tui",
        "terminal",
        "form",
        "widget"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "5e32410fcbc65ff70b5641dd53b984e3",
                "sha256": "558d4cd3e79c2fead376054f78201d334b54b9c8797072e2e20bff063515f3d6"
            },
            "downloads": -1,
            "filename": "textual_forms-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5e32410fcbc65ff70b5641dd53b984e3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 7953,
            "upload_time": "2022-12-19T20:45:21",
            "upload_time_iso_8601": "2022-12-19T20:45:21.347856Z",
            "url": "https://files.pythonhosted.org/packages/92/ad/a4bfc7725e8e3750d47ec65a893e6b31b87c420de6010336660828b45143/textual_forms-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "1d52530ab8070c21e18df6d44f6e4471",
                "sha256": "a46f7d24a9d7766252cd92b4235b564f611551a77d59b4c01ffc97a516859c23"
            },
            "downloads": -1,
            "filename": "textual_forms-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1d52530ab8070c21e18df6d44f6e4471",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 7134,
            "upload_time": "2022-12-19T20:45:23",
            "upload_time_iso_8601": "2022-12-19T20:45:23.619492Z",
            "url": "https://files.pythonhosted.org/packages/50/9f/93e647877fdc83e5fdbc767bcc8b1d8ae4e4f5da3432bb18f33f7ba51a3e/textual_forms-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-19 20:45:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "rhymiz",
    "github_project": "textual-forms",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "textual-forms"
}
        
Elapsed time: 0.01954s