Skip to main content

A terminal based UI library for Python

Project description

procyon-py

Procyon is a lightweight terminal UI library for python that simplifies building rich, interactive interfaces directly in the terminal. It allows users to split windows into multiple panels and populate them with various UI elements for a fully customizable experience.

Features

  • Panel Splitting: Divide your terminal into several different panels - each with its own menu
  • Flexible Layouts: Add elements and containers to menus in a line by line approach
  • Elements: Support for buttons, checkboxes, progress bars, labels, and many more types of elements
  • Scalability: Panels support resizing dynamically when resizing the terminal
  • Straightforward approach: A simple menu building system allows for quick development

Installation

Prerequisites

  • Python 3.7 or higher
  • curses library

Create a Virtual Environment (Optional but recommended)

This step can be safely skipped if you are already using a default virtual Environment.

python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate

Windows Only

As of now, on windows, in order for procyon to work, the windows-curses package must be installed with

pip install windows-curses

Install Procyon

pip install procyon-py

Quick Start Example

This code is an example that creates two simple menus split vertically with some elements included.

import curses
from procyon import UIManager, Menu, Panel, Button, Label

def buttonFunction():
    ''' Runs when the button is activated '''
    return "Clicked!"

def main(stdscr: curses.window):
    # Initialize a ui manager with the curses window
    manager = UIManager(stdscr)

    # Create a menu for the left panel and insert elements
    leftMenu = Menu('left')
    leftLabel = Label("Left menu")
    leftButton1 = Button("Button1", buttonFunction, setLabelToResult=True)
    leftButton2 = Button("Button2", buttonFunction, setLabelToResult=True)
    leftMenu.addElement(leftLabel)
    leftMenu.addElement(leftButton1)
    leftMenu.addElement(leftButton2)

    # Create a menu for the right panel and insert elements
    rightMenu = Menu('right')
    rightLabel = Label("Right menu")
    rightButton = Button("Click me!", buttonFunction, setLabelToResult=True)
    rightMenu.addElement(rightLabel)
    rightMenu.addElement(rightButton)

    # Split the uiManager root panel in two
    left, right = manager.splitVertical()

    # Load menus into left and right panels
    left.loadMenu(leftMenu)
    right.loadMenu(rightMenu)

    # Run the uiManager
    manager.run()

if __name__ == "__main__":
    # Pass the curses window to the main function
    curses.wrapper(main)

Element types

Procyon has support for many different types of elements, and many more are planned!

Currently implemented element types

  • Label: A simple line of text that can be easily updated
  • Button: Activate with enter to run a function.
  • Checkbox: Toggle state with enter.
  • Progress Bar: Visually show a percentage (Ex. Time played of song on a music player)
  • Row bar: A horizontal container to display multiple elements inline

Usage

Menus

In procyon, a menu is a container for a list of elements. When adding elements to a menu, an element is specified, along with an id string for the element. This id string can be used to easily access elements to modify them. A menu must be loaded into a panel to be displayed

Panels

A panel is a method for splitting up the window that Procyon is running in. A panel can either contain a menu, or two separate panels. Each panel can be split into only two panels, either vertically or horizontally. If a panel contains a menu, that menu will be drawn inside of it when the manager is displayed.

UIManager

The UIManager is the heart of the UI. It handles displaying and updating panels and their menus, as well as capturing user input. The UIManager also keeps track of which panel is selected, which can be changed by the user using keyboard controls. The UIManager runs a main loop that refreshes every time the user makes an input, or every 100 milliseconds.

Controls

Procyon is controlled entirely by the keyboard - there is no mouse support (yet...). Users can use either the arrow keys or vim style directional keys (h,j,k,l). UI Elements can be 'clicked' or activated using the enter/return key

Switching panels

As of now, panels are switched using shift + a directional key. For example, to move to the panel on top of the current panel, shift + up arrow or shift + K can be used

Contributing

Contributions to Procyon are not only welcome, but highly encouraged! For more details on how to contribute, visit the CONTRIBUTING guidelines

Get involved

If you have and questions, suggestions, or feedback, please don't hesitate to open an issue or contact me.

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

procyon_py-0.3.0.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

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

procyon_py-0.3.0-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file procyon_py-0.3.0.tar.gz.

File metadata

  • Download URL: procyon_py-0.3.0.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for procyon_py-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6cc6f4c460adc7190254af83e1d40722ae9b84c61c7337cf1e1bb090ff330011
MD5 bfada721c03c160b80100f4a0ae37ff2
BLAKE2b-256 947caba1ff4c95501f52a3f7d32c2abd8f3c0e771b78dc6165bb0e2638da7c2b

See more details on using hashes here.

File details

Details for the file procyon_py-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: procyon_py-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 31.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for procyon_py-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a9f098fd2f03c40c875c99f41bd14f99c4f7da1cefee90d627caa602221e161
MD5 f70209e8681a7ff60ed686e2fb5dd251
BLAKE2b-256 917e58af8122ad7aeceeede0cdd83e6c04033460f9002940b363272528d5e460

See more details on using hashes here.

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