Skip to main content

A collection of tools for python TUIs

Project description

Boxes

Python 3.9+ License: 2-Clause-BSD

Boxes is a collection of tools for making TUI python projects.

Dependencies

Boxes uses curses, with comes with python, so nothing must be installed additionally

How to use

Setup

First you will have to import the package:

from boxes_tui import TUI

Now you will need to create a new TUI object intance:

my_tui = TUI()

After that you can use the tools that this package supplies.

Curses Wrapper

It is adviced to use the curses wrapper. It supports error handling, in the case your program terminates before calling:

my_tui.cleanup()

To use the wrapper you will have to import:

from curses import wrapper
from boxes_tui import TUI

Change your main function to take in the parameter stdsrc:

def main(srdsrc):

and call it using:

wrapper(main)

You will also need to construct the TUI opject with stdsrc:

my_tui = TUI(stdsrc)

Tool usage

See example.py for a basic TUI script example.

  1. Menu

    Creation

    This simple menu is navigatable by arrow keys and enter.

    You have to pass in the lable and a function to execute; all in a list.

    Here is an example for a super basic menu:

    my_menu = tui.Menu(stdscr, [("Hello", tui.nothing), ("Quit", quit_app)])
    

    Here the entrys get stored as a list of tuples of (label, function_to_call)

    As you can see, you also put in a window. Its values (aka the origin coord and the height & width) will be used for the Menu.

    You can chage them later using:

    my_menu.chage_values(x, y, width, height)
    

    Ticking

    Ticking refreshes the menu and processes keypresses. For values it returns, see Returns

    You can tick the function using:

    my_menu.tick(key)
    

    key can be gotten by using:

    key = stdsrc.getch()
    

    Keybinds

    You can set the Menu's keybinds by passing in a keybinds list:

    my_menu = tui.Menu(stdscr, 
                       [("Hello", tui.nothing), ("Quit", quit_app)], 
                       [([curses.KEY_UP, ord("W"), ord("w")], tui.Menu.move_up),
                        ([curses.KEY_DOWN, ord("S"), ord("s")], tui.Menu.move_down),
                        ([10], tui.Menu.select) # (10 = Enter key)
                       ]
                    )
    

    The default keybindings are:

    [
        ([curses.KEY_UP], tui.Menu.move_up),
        ([curses.KEY_DOWN], tui.Menu.move_down),
        ([10, curses.KEY_RIGHT], tui.Menu.select),
        ([curses.KEY_BACKSPACE, curses.KEY_LEFT], tui.Menu.back)
    ]
    

    Returns

    When ticking, the menu may (when the user presses "enter" or "backspace") return a tuple of (index, return_of_the_function)

    Were index is the index of the entry the user selected. -1 if the user pressed backspace.

    return_of_the_function is whatever the function may have returned, that has been called by the menu.

If you encounter any bug, optimization issue or anything else you would like me to change, please feel free to let me know :)

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

boxes_tui-2.2.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boxes_tui-2.2.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file boxes_tui-2.2.1.tar.gz.

File metadata

  • Download URL: boxes_tui-2.2.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for boxes_tui-2.2.1.tar.gz
Algorithm Hash digest
SHA256 fbb7986a7534bc95c9a594c99e77b714d340590d705ce1ae5651635f3babce1f
MD5 a8b3630ac6a57741971132ead81e6c8a
BLAKE2b-256 4556a59990274ce82905c9d11a0576a89c08eb948bba48c180939a72503bb9f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for boxes_tui-2.2.1.tar.gz:

Publisher: publish-to-pypi.yml on IamLegende7/boxes-tui

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boxes_tui-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: boxes_tui-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for boxes_tui-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f432a751dca9c3ae249853d90000aeb0366983777164619f14cb2260d66e9647
MD5 715e0ed8217c2ffce8c7dd1bddc17a79
BLAKE2b-256 f2a8e68776e3a6b103433352bc5b4c54c04559fd0f01f0e168a96496a0101293

See more details on using hashes here.

Provenance

The following attestation bundles were made for boxes_tui-2.2.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on IamLegende7/boxes-tui

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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