Skip to main content

ASCII Designer

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.10, attrs. To use the Qt toolkit you need qtpy.

DOCUMENTATION

Please proceed to https://ascii-designer.readthedocs.io/

For some examples, look at test_ascii_designer.py as well as the examples folder.

LICENSE

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

TODO

Beta-state software, somewhat battle-tested.

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

Release files for ascii_designer 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ascii_designer 2.1.0
File Size Uploaded
ascii_designer-2.1.0.tar.gz 114.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ascii_designer 2.1.0
File Interpreter ABI Platform
ascii_designer-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 167.3 kB

Release files / ascii_designer-2.1.0.tar.gz

Download URL ascii_designer-2.1.0.tar.gz
Size 114.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dc0788f441435a5272d5d4636b5f20a9a90667ecd04144baefa4cd677ccc42e9
BLAKE2b-256 checksum
How to use checksums
eecaade2cb3fdd317d2edf11a27240e090135f951c6764a259fe964c0313594d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / ascii_designer-2.1.0-py3-none-any.whl

Download URL ascii_designer-2.1.0-py3-none-any.whl
Size 52.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06d95b91c89f95c5fb8a4dec74664606fba9f19533223762c850ade4a4255280
BLAKE2b-256 checksum
How to use checksums
baacaecf1f7d5b3a2b71441d1edbaa75b9893d19bc4cdc93d01c8423f9eb2044
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.0.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page