Skip to main content

Builds dialogs from ASCII art definition.

Project description

A library that:

  • creates GUI from ASCII-art (with well-defined syntax)

  • maps widgets to virtual class attributes

  • relieves you from the boring parts of Form building while leaving you in control.

Did you ever design a form by scribbling something like this in your editor:

Text to transform:   [ Text_      ]

Select transformation:

(x) Uppercase
( ) Lowercase
( ) Title-case

    [ OK ]            [ Cancel ]

… and wished that you could be done with design and start coding? Wish no longer:

from ascii_designer import AutoFrame

class TextTransformer(AutoFrame):
    f_body='''
                            |    <->       |
        Text to transform:   [ Text_      ]

        Select transformation:

        (x) Uppercase
        ( ) Lowercase
        ( ) Title-case

            [ OK ]            [ Cancel ]~

    '''
    def ok(self):
        text = self.text
        if self.uppercase:
            text = text.upper()
        elif self.lowercase:
            text = text.lower()
        elif self.titlecase:
            text = text.title()
        print(text)
        self.close()

    def cancel(self):
        self.close()

if __name__ == '__main__':
    TextTransformer().f_show()

Some comments, incidentally highlighting the features of this library:

  • As you probably guessed, all the magic happens in AutoFrame. The f_show call triggers rendering of the form. All the reserved attributes are prepended with f_ to get out of your way when subclassing.

  • There is a well-defined syntax for how to get the usual widget types. In the example you can find labels (plain text), a text box, radio buttons and normal buttons.

  • The columns are defined by the header row with the pipe characters. The minus sign denotes stretching columns. (The < / > chars are just decoration.)

  • Column-span is easily done by having not-a-space underneath the pipe symbol. Row-span can also be done by prepending subsequent cells with a { character.

  • Anchoring is controlled by whether the cell is space-padded or not. For example, the Text box stretches, while the cancel button is centered. The tilde character can be used instead of a fragile trailing space.

  • Widget IDs are automatically generated by lowercasing and whitelisting the captions.

  • If a method exists with the same name as a widget id, it is automatically bound to the usually-wanted event (click in case of button, value-changed in case of basically anything else). Oh, and close and quit are already there for your convenience.

  • Otherwise, you can retrieve and set the widget’s value by using its id like a class attribute.

  • f_show() captures all the usual boilerplate and simply f***ing shows the frame. It can be used for both the toplevel and additional frames.

  • Also note how the class name automatically turned into the window title. Override by setting .f_title.

  • The created widgets are “raw”, native widgets. You can configure the toolkit to use. Currently there is a Qt and a Tkinter implementation. The native widget can accessed using form["widget_id"] (or form.f_controls["widget_id"]).

The general philosophy is to not paint everything over with wrappers. Instead, the library focuses on specific tasks - building the layout, event-/value binding - and lets you do everything else with the API you know and (maybe) love.

INSTALLATION

pip install ascii_designer

Requirements: Python >= 3, attrs. To use the Qt toolkit you need qtpy.

DOCUMENTATION

Please proceed to http://ascii_designer.readthedocs.io/en/latest/index.html

LICENCSE

MIT License: https://github.com/loehnertj/ascii_designer/blob/master/LICENSE

TODO

Alpha-state software, mostly working.

Test coverage is lacking, politely spoken.

This is a hobby project. If you need something quick, open an issue or send a pull request.

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

ascii_designer-0.6.0.tar.gz (46.2 kB view details)

Uploaded Source

Built Distribution

ascii_designer-0.6.0-py3-none-any.whl (52.6 kB view details)

Uploaded Python 3

File details

Details for the file ascii_designer-0.6.0.tar.gz.

File metadata

  • Download URL: ascii_designer-0.6.0.tar.gz
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.32.3 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for ascii_designer-0.6.0.tar.gz
Algorithm Hash digest
SHA256 5992da14f5fb5e1ab270ea848498c6cff6d6bce468464ed2629a3d9d54c3b25c
MD5 ad6f8fc3ab507cbc3df0cfd3a3ae3ad2
BLAKE2b-256 ad54ce200c38e7cfab223a63daa55ed446ec3c69eebfe01f0126026a857cfeeb

See more details on using hashes here.

File details

Details for the file ascii_designer-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: ascii_designer-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 52.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.32.3 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for ascii_designer-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ecfbe2eab351afebf9ff2418df2cedb65e978d77f1cc54c969cc110c9b3f7201
MD5 c1bb543dbd0cac5d38cbc87552916dd3
BLAKE2b-256 27fb6b841c787188c9b42a1bf972934878ad7e0fb2199cf63731dd9973e1f5f3

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