pymenu package

Package main definition.

class pymenu.DictMenuEntry(name, data, parent=None)[source]

Bases: pymenu.MenuEntry

A menu tree node made of a dictionary structure.

Parameters:
  • name (str) – The name of this node.
  • data (dict) – The value of this node. If this is a dictionary, child nodes will be created from it.
  • parent (pymenu.MenuEntry) – Parent entry node.
class pymenu.FileSystemMenuEntry(path, parent=None)[source]

Bases: pymenu.MenuEntry

A menu tree node made from a filesystem path.

Parameters:
  • path (str) – Filesystem path from which to build the menu tree.
  • parent (pymenu.MenuEntry) – Paren entry node.

Note

The creation of child nodes if not lazy. This means that creating an instance of this class from a top level folder of a large file sets will consumes a lot of RAM.

class pymenu.Menu(root_entry, prompt)[source]

Bases: object

Parameters:
choose_menu()[source]

Prompt for a choice of menu items.

Returns:The chosen menu object
Return type:pymenu.Menu
choose_value()[source]

Prompt until a leaf menu item is choosen.

Returns:The associated value for the chosen item.
Return type:Any
entry

Returns – pymenu.MenuEntry

class pymenu.MenuEntry(name, value=None, parent=None)[source]

Bases: anytree.node.Node

A menu tree node.

This is essentially a tree node, as inherited by anytree.node.Node. Sub classes may require to implement the creation of child entries.

Parameters:
  • name (str) – A name for this node.
  • value (Any) – Associated value.
  • parent (pymenu.MenuEntry) – Parent entry node.
value
class pymenu.Prompt[source]

Bases: object

Abstract class for defining menu user interfaces.

prompt_for_one(choices)[source]
Parameters:choices (list) – List from which to choose from.
Returns:str
class pymenu.SimpleCommandPrompt(question=None, prompt=None)[source]

Bases: pymenu.Prompt

Simply prompt a user for choices in command line.

Parameters:
  • question (str) – Header question displayed before the choices.
  • prompt (str) – Actual prompt message for the user.
prompt_for_one(choices)[source]
Parameters:choices (list) – List from which to choose from.
Returns:Chosen key
Return type:str
Raises:KeyError – when the select item in not a valid choice.