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 textworldgo sub menu: opens a sub menu when you press enter on this option
- Sub menu with 4 options:
example 1example 2Quit: closes allBack: 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 openedcallback_quit: called when the menu is exitedcallback_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 elementcallback_go_in: called when the cursor is positioned over the elementcallback_go_out: called when the cursor moves away from the elementcallback_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
193c426bdb4bbab9a52f423a98126dbabc4c54c7426f81c1ed84c52fc9b7c88a
|
|
| MD5 |
722a50628463697c7f5c3b3f32f9e60a
|
|
| BLAKE2b-256 |
705d3a51fc770d4b37312e97c6ff25e8dfab532dd5134dd584d93b94b2519dfa
|