Menu

A generic class to manage the user navigation through a multilevel options menu.

Created on March. 04, 2019

@author: Jesús Cid Sueiro

Based on former menu manager scripts by Jerónimo Arenas.

class rdigraphs.menu_navigator.menu_navigator.MenuNavigator(tm: SgTaskManager, path2menu: str, paths2data: Optional[str] = None, option1: Optional[str] = None)

Bases: object

A class to manage the user navigation through a multilevel options menu.

The structure of multilevel menu options with their associated actions and parameters should be defined in a yaml file.

A taskmanager class is required to take the selected actions with the given parameters.

__init__(tm: SgTaskManager, path2menu: str, paths2data: Optional[str] = None, option1: Optional[str] = None)

Initializes a menu navigator.

Parameters:
  • tm (object) – A task manager object, that will be in charge of executing all actions selected by the user through the menu interaction. Thus, it must contain: (1) One action method per method specified in the menu structure (2) Data collection methods, required for some menus with dynamic options.

  • path2menu (str) – The route to the yaml file containing the menu structure

  • paths2data (dict or None, optional (default=None)) – A dictionary of paths to data repositories. The key is a name of the path, and the value is the path.

__weakref__

list of weak references to the object (if defined)

clear()

Cleans terminal window

front_page(title)

Prints a simple title heading the application user screen

Parameters:

title (str) – Title message to be printed

navigate(option=None, active_options=None)

Manages the menu navigation loop

Parameters:
  • options (dict) – A dictionary of options

  • active_options (list or None, optional (default=None)) – List of option keys indicating the available options to print. If None, all options are shown.

query_options(options, active_options=None, msg=None, zero_option='exit')

Prints a heading mnd the subset of options indicated in the list of active_options, and returns the one selected by the used

Parameters:
  • options (dict) – A dictionary of options

  • active_options (list or None, optional (default=None)) – List of option keys indicating the available options to print. If None, all options are shown.

  • msg (str or None, optional (default=None)) – Heading message to be printed before the list of available options

  • zero_option (str {‘exit’, ‘up’}, optional (default=’exit’)) – If ‘exit’, an exit option is shown If ‘up’, an option to go back to the main menu

Returns:

option – Selected option

Return type:

str

request_confirmation(msg='     Are you sure?')

Request confirmation from user

Parameters:

msg (str, optional (default=” Are you sure?”)) – Message printed to request confirmation

Returns:

r – User respones

Return type:

str {‘yes’, ‘no’}