textual-pyfiglet-demo


Nametextual-pyfiglet-demo JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummarySmall demo proposal of integrating PyFiglet with Textual
upload_time2024-10-20 00:02:07
maintainerNone
docs_urlNone
authoredward-jazzhands
requires_python<4.0,>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            A very simple demo of integrating PyFiglet into Textual

This demo was heavily inspired by https://patorjk.com/software/taag/

The key feature is to showcase how the text can actually change size with the terminal dynamically. Despite being ASCII art, the text will re-size and word-wrap with the terminal, just like normal text. It is also possible to change the font while the program is running.

Thanks to the great design of both Textual and PyFiglet, this was actually quite easy to implement.

The trick to this is that:
1) It uses the `Static` widget as a base, and integrates the PyFiglet class
2) It adds a `change_width` method to the widget
3) It over-rides the `render` method

First, use Textual's `on_resize` event to set the width:
```python
async def on_resize(self, event):
    """Handle the terminal being resized."""
    width, height = event.size
    self.figlet_static.change_width(width-4)   # the minus 4 is for padding
```

Connects to the `change_width` method in the widget:
```python
def change_width(self, width: int) -> None:
    self.figlet.width = width
```

Then finally, here is the `render` over-ride:
```python
def render(self):
    text = str(self.renderable)   
    self.set_styles("width: auto;")
    return self.figlet.renderText(text)
```

Note that although there's only 11 fonts in the program (simple ones I hand picked), There's actually hundreds built in. FIGlet fonts have existed for a long time. Check out https://patorjk.com/software/taag/ for a more full-featured, browser-based Demo.

Thanks to:

https://github.com/pwaller/pyfiglet
https://patorjk.com/ (https://github.com/patorjk)

And of course, Textual
https://github.com/Textualize/textual
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "textual-pyfiglet-demo",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "edward-jazzhands",
    "author_email": "ed.jazzhands@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/25/f0/6f126ce4ce442e44bb1cdad92185aa8c8edcd87d240fc018dd597d6f6062/textual_pyfiglet_demo-0.1.0.tar.gz",
    "platform": null,
    "description": "A very simple demo of integrating PyFiglet into Textual\n\nThis demo was heavily inspired by https://patorjk.com/software/taag/\n\nThe key feature is to showcase how the text can actually change size with the terminal dynamically. Despite being ASCII art, the text will re-size and word-wrap with the terminal, just like normal text. It is also possible to change the font while the program is running.\n\nThanks to the great design of both Textual and PyFiglet, this was actually quite easy to implement.\n\nThe trick to this is that:\n1) It uses the `Static` widget as a base, and integrates the PyFiglet class\n2) It adds a `change_width` method to the widget\n3) It over-rides the `render` method\n\nFirst, use Textual's `on_resize` event to set the width:\n```python\nasync def on_resize(self, event):\n    \"\"\"Handle the terminal being resized.\"\"\"\n    width, height = event.size\n    self.figlet_static.change_width(width-4)   # the minus 4 is for padding\n```\n\nConnects to the `change_width` method in the widget:\n```python\ndef change_width(self, width: int) -> None:\n    self.figlet.width = width\n```\n\nThen finally, here is the `render` over-ride:\n```python\ndef render(self):\n    text = str(self.renderable)   \n    self.set_styles(\"width: auto;\")\n    return self.figlet.renderText(text)\n```\n\nNote that although there's only 11 fonts in the program (simple ones I hand picked), There's actually hundreds built in. FIGlet fonts have existed for a long time. Check out https://patorjk.com/software/taag/ for a more full-featured, browser-based Demo.\n\nThanks to:\n\nhttps://github.com/pwaller/pyfiglet\nhttps://patorjk.com/ (https://github.com/patorjk)\n\nAnd of course, Textual\nhttps://github.com/Textualize/textual",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Small demo proposal of integrating PyFiglet with Textual",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5991b9e061885eabd903e0da42ff00d3b3dad0691773d8bd38404810f889da44",
                "md5": "35559395afba24dc2c14a40263f0d704",
                "sha256": "b7318a0eeadbd9c6381726af1aeef866ba6a669981f8d239cc4e25d72e80e56c"
            },
            "downloads": -1,
            "filename": "textual_pyfiglet_demo-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "35559395afba24dc2c14a40263f0d704",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 4966,
            "upload_time": "2024-10-20T00:02:05",
            "upload_time_iso_8601": "2024-10-20T00:02:05.496132Z",
            "url": "https://files.pythonhosted.org/packages/59/91/b9e061885eabd903e0da42ff00d3b3dad0691773d8bd38404810f889da44/textual_pyfiglet_demo-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "25f06f126ce4ce442e44bb1cdad92185aa8c8edcd87d240fc018dd597d6f6062",
                "md5": "18041d724ecba05992573bb281f793e2",
                "sha256": "2c8b5a9290f3966780a811951a22e72aca5218bf89a57f3e5d4d1d3ed37430f4"
            },
            "downloads": -1,
            "filename": "textual_pyfiglet_demo-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "18041d724ecba05992573bb281f793e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 3801,
            "upload_time": "2024-10-20T00:02:07",
            "upload_time_iso_8601": "2024-10-20T00:02:07.238814Z",
            "url": "https://files.pythonhosted.org/packages/25/f0/6f126ce4ce442e44bb1cdad92185aa8c8edcd87d240fc018dd597d6f6062/textual_pyfiglet_demo-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-20 00:02:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "textual-pyfiglet-demo"
}
        
Elapsed time: 0.55771s