Skip to main content

Easy menu with python3

Project description

ElsaMenu

API to easily create a menu in python3 in the console.

The system supports:

  • automatic refresh where configured
  • colored text
  • non-selectable sections
  • submenus
  • menu history to navigate back to the previous menu

Example

Example in python3, this example shows how to create 2 menus:

  • Root menu with 3 options:
    • hello: with green text
    • world
    • go sub menu: opens a sub menu when you press enter on this option
  • Sub menu with 4 options:
    • example 1
    • example 2
    • Quit: closes all
    • Back: goes back to the previous menu
"""Example"""

from elsa_menu.menu_element import TextBox, OpenMenu, BackMenu, CloseMenu
from elsa_menu.menu_object import MenuObject
from elsa_menu.menu import ElsaMenu
from elsa_menu.color import TextColor


if __name__ == "__main__":
    menu = ElsaMenu()

    menu_obj = MenuObject("test")
    menu_obj.add_element(TextBox(True, f"{TextColor.GREEN.value}hello"))
    menu_obj.add_element(TextBox(True, "world"))

    prova = MenuObject("submenu")
    prova.add_element(TextBox(True, "example 1"))
    prova.add_element(TextBox(True, "example 2"))
    prova.add_element(CloseMenu("Quit"))
    prova.add_element(BackMenu("Back"))
    prova.entry[1].refresh_min = 1
    menu_obj.add_element(OpenMenu("go sub menu", prova))

    menu.set_root(menu_obj)
    menu.start_show()

Personalizzazioni

Input

The menu input can be customized by extending the Input class and implementing the getch method.

The API implements keyboard input by default. The supported keys are:

  • Up arrow
  • Down arrow
  • Enter
  • Back

These are the minimum keys required to use a menu.

PMenu Customization

The class for managing a single menu can also be customized by extending AbstractMenu. There are various useful callbacks:

  • callback_enter: called when the menu is opened
  • callback_quit: called when the menu is exited
  • callback_move: called whenever there is movement within the menu

Menu Element Customization

The elements within the menu can be customized by using the base abstract class Element. To create a custom menu element, extend the class and implement at least the generate_text method, which generates the text to be displayed in the menu.

There are various supportive callbacks for elements to implement desired mechanics:

  • callback_enter: called when Enter is pressed on the element
  • callback_go_in: called when the cursor is positioned over the element
  • callback_go_out: called when the cursor moves away from the element
  • callback_move_on_menu: called whenever there is movement within the menu

Menu Instance Customization

To create a customized version of the menu instance, extend the AbstractInstance class.

By default, this requires implementing the output. The API provides an implementation for console output with ConsoleInstance.

By extending the class, it is also possible to modify input handling if new inputs have been added or if a different handling method is desired.

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

elsamenu-1.0.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

ElsaMenu-1.0.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file elsamenu-1.0.1.tar.gz.

File metadata

  • Download URL: elsamenu-1.0.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for elsamenu-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a2360f0550f9c70b671f6e1a94001a3346f6385d8c5cd3f844875f257e769ed8
MD5 271b8ccafba989eba20e169bf762eac0
BLAKE2b-256 17c18251fa5add014727eaa960c29296853efe82aec8aba0e9de22a2ad9bd589

See more details on using hashes here.

File details

Details for the file ElsaMenu-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: ElsaMenu-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for ElsaMenu-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 193c426bdb4bbab9a52f423a98126dbabc4c54c7426f81c1ed84c52fc9b7c88a
MD5 722a50628463697c7f5c3b3f32f9e60a
BLAKE2b-256 705d3a51fc770d4b37312e97c6ff25e8dfab532dd5134dd584d93b94b2519dfa

See more details on using hashes here.

Supported by

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