API

class pytabby.Menu(config, start_tab_number=0)[source]

Base class to import to create a menu

Parameters
  • config (dict) – a nested dict, in a schema which will be validated, containing everything needed to instantiate the Menu class

  • start_tab_number (int) – default 0, the number of the tab to start at

safe_read_yaml(path_to_yaml)[source]

static method to read a yaml file into a config dict

read_json(path_to_json)[source]

static method to read a json file into a config dict

run(message=None)[source]

Displays menu at currently selected tab, asks for user input and returns it as a string

Examples

>>> config = Menu.safe_read_yaml('config.yaml')
>>> menu = Menu(config, start_tab_number=0)
>>> result = menu.run()
>>> if result = "action name":
>>>         my_great_function()
>>> # with a submenu
>>> config = Menu.safe_read_yaml('config.yaml')
>>> menu = Menu(config, start_tab_number=0)
>>> result = menu.run()
>>> if result = "further options":
>>>     submenu = Menu(submenu_config)
>>>     if submenu_result = "action name":
>>>         my_great_function()