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

The main module. All of its public functions get exported by the package (see __init__.py)
 
Copyright (c) 2013, Jonas Pfannschmidt
Licensed under the MIT license http://www.opensource.org/licenses/mit-license.php

 
Modules
       
__builtin__
datetime
string
sys
types

 
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.
input = raw_input(...)
raw_input([prompt]) -> string
 
Read a string from standard input.  The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled.  The prompt string, if given,
is printed without a trailing newline before reading.
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
        print_function = _Feature((2, 6, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 65536)