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.2.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.2-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mdmenu-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f601018351484ce66c4c48bc1e8206f523edb50fc0bd6bfa2e8481109b5f18fe
MD5 e3b41b95fe9d7783ff2826e6610ecd41
BLAKE2b-256 3bf52b7dbfaa973d086928859057b779c9b7634019c5300193940a2f5140dea4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdmenu-0.0.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: mdmenu-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 39f72aeaf685664a67638fc685762a4fa5d5300d7a716d54c0914cbd1b52d532
MD5 855dcecac1dca6727a60e706a913640f
BLAKE2b-256 4c1c9228017c811be600ced19f5a4a9450293a7ccc01c37fe3b18387b891de8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdmenu-0.0.2-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