Back to index

python3.2  3.2.2
Functions
curses.wrapper Namespace Reference

Functions

def wrapper

Detailed Description

curses.wrapper

Contains one function, wrapper(), which runs another function which
should be the rest of your curses-based application.  If the
application raises an exception, wrapper() will restore the terminal
to a sane state so you can read the resulting traceback.

Function Documentation

def curses.wrapper.wrapper (   func,
  args,
  kwds 
)
Wrapper function that initializes curses and calls another function,
restoring normal keyboard/screen behavior on error.
The callable object 'func' is then passed the main window 'stdscr'
as its first argument, followed by any other arguments passed to
wrapper().

Definition at line 12 of file wrapper.py.

00012 
00013 def wrapper(func, *args, **kwds):
00014     """Wrapper function that initializes curses and calls another function,
00015     restoring normal keyboard/screen behavior on error.
00016     The callable object 'func' is then passed the main window 'stdscr'
00017     as its first argument, followed by any other arguments passed to
00018     wrapper().
00019     """
00020 
00021     try:
00022         # Initialize curses
00023         stdscr = curses.initscr()
00024 
00025         # Turn off echoing of keys, and enter cbreak mode,
00026         # where no buffering is performed on keyboard input
00027         curses.noecho()
00028         curses.cbreak()
00029 
00030         # In keypad mode, escape sequences for special keys
00031         # (like the cursor keys) will be interpreted and
00032         # a special value like curses.KEY_LEFT will be returned
00033         stdscr.keypad(1)
00034 
00035         # Start color, too.  Harmless if the terminal doesn't have
00036         # color; user can test with has_color() later on.  The try/catch
00037         # works around a minor bit of over-conscientiousness in the curses
00038         # module -- the error return from C start_color() is ignorable.
00039         try:
00040             curses.start_color()
00041         except:
00042             pass
00043 
00044         return func(stdscr, *args, **kwds)
00045     finally:
00046         # Set everything back to normal
00047         if 'stdscr' in locals():
00048             stdscr.keypad(0)
00049             curses.echo()
00050             curses.nocbreak()
00051             curses.endwin()

Here is the call graph for this function:

Here is the caller graph for this function: