simplemenus
index
c:\dev\simplemenus\simplemenus\__init__.py

SimpleMenus is a small and simple python module for creating interactive 
console applications. It allows to prompt the user for strings, integers,
dates, booleans, lets him choose between various options and offers 
lightweight menus.
 
I use it for small utilities and prototypes whenever I need a little bit of
interaction with the user. For more complicated applications you should look
at something like curses instead (http://docs.python.org/library/curses.html).
 
Examples:
        # print birthday
        print(get_date("Enter your birthday"))
 
        # print selection
        print(get_from_list(['One', 'Two', 'Three']))
 
        # return if user doesn't want to continue
        if not get_boolean('Continue?'):
                return
 
 
You can find more at the examples and the test direcory.
 
Copyright (c) 2013, Jonas Pfannschmidt
Licensed under the MIT license http://www.opensource.org/licenses/mit-license.php

 
Package Contents
       
main
test (package)
xgetch

 
Functions
       
configure(key, value)
Change the configuration.
 
Args:
        key: One of the following strings
                prompt        - Displayed when the user gets prompted for an input.
                cancel_option - Which text needs to be entered to cancel an operation.
                cancel_text   - Which text gets displayed for the cancel option.
                list_format   - How to display lists. Uses str.format() syntax. Use {option} and {text} as placeholders.
                empty_text    - Text that gets displayed when a list is empty
                date_format   - strptime format to parse dates. See docs.python.org/library/datetime.html#strftime-strptime-behavior
                force_return  - Always confirm input by pressing the return key
        value: The configuration value. See reset_config() for the defaults
get_boolean(text='', default=None)
Repeat until the user enters 'y' or 'n' or a string starting with 'y' or 'n' (i.e. 'yes' and 'no').
get_character(text='', default=None)
Get character without waiting for the enter key.
get_date(text='', default=None)
Repeat until the user enters a valid date.
get_from_dictionary(dictionary, show_cancel=True)
Let the user choose a key and return the corresponding value.
 
Note: Use OrderedDict to preserve the option order
get_from_list(my_list, text='', show_cancel=True, default=None)
Enumerates a list of strings and lets the user choose one value.
 
Example:
 
        a) one
        b) two
        c) three
        d) four
 
        0) Cancel
        >
get_integer(text='', default=None)
Repeat until the user enters a valid number.
get_option(options, text='', default=None)
Repeat until the user chooses a valid option.
 
   If there are only single-letter options the input is accepted directly otherwise the user has to confirm by pressing the return key
 
Args:
        options: a list of strings that are valid options
get_string(text='', default=None)
Get string or default value.
reset_config()
Resets the configuration to the default
show_enumerated_list(my_list)
Shows a list enumerated by a, b, c, ...
show_headline(headline)
Show a headline.
 
Example:
 
        +------+
        | Test |
        +------+
show_small_headline(headline)
Show a smaller headline.
 
Example:
        +-- Test --+
start_menu(menu, headline)
Show a menu and run a function if the user chooses one menu entry.
 
Args:
        menu: an OrderedDict dictionary. The keys are shown as menu entries. If a value is a functions 
                  it gets called when the user chooses the corresponding menu entry otherwise it gets returned.
        headline: the title for the menu
wait_for_enter()
Waits for the user to press enter.

 
Data
        __all__ = ['reset_config', 'configure', 'wait_for_enter', 'get_string', 'get_character', 'get_boolean', 'get_integer', 'get_date', 'get_option', 'get_from_list', 'get_from_dictionary', 'show_enumerated_list', 'show_headline', 'show_small_headline', 'start_menu']