Skip to main content

A customisable text driven menu system.

Project description

pylint Lint Test Build Codecov PyPI version Python versions PyPI Publish

mdmenu

A simple and customisable text based menu system.

Installation

Install mdmenu using pip:

pip install mdmenu

Usage

A new MDMenu object can be instantiated by calling its empty constructor for a default menu or it can be called with any combination of the instance parameters. Menu items can be added and removed with .add_menu_item() and .remove_menu_item() respectively.

The appearance of the menu is customisable by setting any of the menu instance parameters

Create a default menu object

# examples/default_menu.py
from mdmenu import MDMenu

my_menu = MDMenu()
print(my_menu)

"""
################################################################################
                                      Menu
################################################################################
     1:   Exit
################################################################################
"""

Create a menu with a predefined set of menu options

# examples/defined_options.py
from mdmenu import MDMenu

def hello_world():
    print("Hello World!")

my_options = {
    1: ("Item 1", hello_world),
    2: ("Item 2", hello_world),
    10: ("Item x", hello_world)
}

my_menu = MDMenu(menu_items=my_options)
print(my_menu)

"""
################################################################################
                                      Menu
################################################################################
     1:   Item 1
     2:   Item 2
    10:   Item x
################################################################################
"""

Parameters

The following table list the parameters of the Menu which can be altered to customise the look and formatting of the table.

Parameter Description
footer_content
Type: str
Default: None
A text body to be displayed in the footer of the menu, after the main body of the menu.
footer
Type: bool
Default: True
Enabled by default, this boolean attribute indicates if the menu will be displayed with footer.
key_trailing_gap
Type:int
Default: 3
The number of white space to be added after the menu item key and before the items name when displaying the menu.
eg. 5:<key_trailing_gap>Hello World
key_width
Type: int
Default: 7
The number of characters to pad the menu item key to when displayed.
eg.<key_width>: Hello World
menu_character
Type: str
Default: '#'
The character used to create borders of 'self.menu_width' for the menu
menu_hold_last
Type: bool
Default: True
When true, the last item in the 'self.menu_items" dict is maintained as the item with the highest/last key value. As the default and most likely first item added is the exit, this provides a easy mechanism to keep it as the last last menu item even when key values are automatically assigned.
menu_items
Type: dict[int, tuple]
Default: {1: ("Exit", exit)}
The dict of menu items in the system. Each item has a int key and a tuple with the items title and associated function.
menu_name
Type: str
Default: True
The name of the menu as a string. The name is displayed when the attribute 'title' is true.
menu_width
Type: int
Default: 80
The width of the menu system
title_border
Type: bool
Default: True
Enabled by default, this boolean attribute indicates if the menus title should be surrounded by a border of 'self.menu_character'.
title_padding
Type: str
Default: " "
The character to use to pad the left and right of 'self.menu_name' when displayed in the menu title.
title_preface
Type: str
Default: None
A text body to be displayed between the menu title and the main body of the menu.
title
Type: bool
Default: True
Enabled by default, this boolean attribute indicates if the menus title should be displayed.

Examples

Several working examples have been included and are listed in the table below

Link Description
examples/default_menu.py Create an empty menu with the default formatting and implied exit menu option
examples/examples/defined_options.py Create a menu with a predefined set of menu options
examples/examples/add_option.py Add a menu option with a defined index key and with out and index key
examples/remove_option.py Remove a menu option from the menu
examples/custom_formatting.py Create menu with custom formatting
examples/call_function.py Call a function selected from the menu

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

mdmenu-0.0.0.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

mdmenu-0.0.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file mdmenu-0.0.0.tar.gz.

File metadata

  • Download URL: mdmenu-0.0.0.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mdmenu-0.0.0.tar.gz
Algorithm Hash digest
SHA256 4e9b4b0a6965e6feb4afb292b212857b42e7f331b32a4ffafabb46534c5429ad
MD5 f85344fda6670dd292f31d16c70e49b8
BLAKE2b-256 820d410445046b38b5065318a9df33ec56f0ec2f9e7166e070516c5aab7ba85a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdmenu-0.0.0.tar.gz:

Publisher: pypi-publish.yml on matthewdennett/python-mdmenu

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

File details

Details for the file mdmenu-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: mdmenu-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mdmenu-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38de32a005a3844a1554e4789326b9781ca5dd82fc91e2b406dda094522f792f
MD5 2bf45c7b7172eec39f970871350748b8
BLAKE2b-256 5c53d8a9893eaffa21379fc0ffbed39c5f482ed4dc3873eb5803bb871008eb5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdmenu-0.0.0-py3-none-any.whl:

Publisher: pypi-publish.yml on matthewdennett/python-mdmenu

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