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()
    

    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.1.0.tar.gz (5.3 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.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: boxes_tui-2.1.0.tar.gz
  • Upload date:
  • Size: 5.3 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.1.0.tar.gz
Algorithm Hash digest
SHA256 852ee2aa453700f2e5abdc2cf6b426240ed461b25926f4411bad763513ddfb4c
MD5 f2c1640d4302c7ec0b21c30a9457ebe9
BLAKE2b-256 408c2506eedef8106f4dd3a60981d41f29a11ba6a2d41d38b3f0105639c63c2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for boxes_tui-2.1.0.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: boxes_tui-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6dc599ca9bc6a36e258a998a139f6f81022aaca952518db967b37c8c54f8360b
MD5 0c72f743414540f5a5e7a55178899153
BLAKE2b-256 b6187bbf971b72132e8a4ac75abc21c71625a0fb994f601c323f42528f5f98bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for boxes_tui-2.1.0-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