inputhook: make stdin_ready() function reusable

Move it from lib.inputhookwx to lib.inputhook, as the former
module can only be loaded if wx itself is available.
inputhook: improve stdin_ready()
 - move select and msvcrt imports in the function itself
   as they're only needed there
 - switch on os.name for platform dependent code
 - for unknow platforms, assume there's something to read
inputhook: make PyQt4 plays nicer with pyreadline

PyQt4's own input hook is not really appropriate when PyReadline is active
(and possibly other readline packages running the PyOS_InputHook repeatedly).
Arguably this should be fixed in PyQt4 itself, but in the meantime we can
install a local hook which does the Qt event loop processing in a less
aggressive way.
inputhook: improve CTRL+C handling with qt4

Allow a first CTRL+C to interrupt the qt4 event loop
and a second to trigger a KeyboardInterrupt.
inputhook_qt4: handle KeyboardInterrupt in a way compatible with 'readline'.

While the previous code works fine on Windows, on Linux with
'readline' the situation is different: once we disable the Qt4 event
loop, we go back waiting in the select() inside readline.c's
readline_until_enter_or_signal() function. When that select() is
interrupted, the PyOS_InputHook is executed if present and the pending
KeyboardInterrupt is delivered as soon as bytecode execution starts,
even before entering the `try:` clause! As at that point we're in a
ctypes callback, this will lead to an internal error. The only
solution is therefore to disable the PyOS_InputHook temporarily.
inputhook: further cleanups for stdin_ready()

 - split stdin_ready() in 3 platform specific functions and choose
   the appropriate one at import time
 - add docstrings for each of these
inputhook: move inputhook_qt4 related code in own file
inputhookqt4: forgot to reset KeyboardInterrupt flag
inputhookqt4: polish the qt4 related hooks

 - make sure we don't install more than one 'pre_prompt_hook'
   for a given ipapi instance
 - clarify the internal documentation and move it from comments
   into docstrings
inputhookqt4: use get_ipython() instead of deprecated ipapi.get()
inputhook: use '%gui none' for disabling the input hook.
inputhook: disable CTRL+C when a hook is active.

On systems with 'readline', it's very likely to intercept a signal
during a select() call. The default SIGINT handler will schedule a
KeyboardInterrupt exception to be raised as soon as possible. If
ctypes is used to install a Python callback for PyOS_InputHook, this
will happen as soon as the bytecode execution starts, so even if the
first instruction of the callback is a
`try: ... except KeyboardInterrupt` clause, it's actually too late.

As ctypes doesn't allow a Python callback to raise an exception, this
ends up with IPython detecting an internal error... not pretty.  We
must therefore ignore the SIGINT signals until we are sure the
exception handler is active, in the Python callback.
inputhookqt4: need to ignore CTRL+C when exiting input hook
inputhookqt4: use InteractiveShell.instance instead of get_ipython

The latter is meant for user code only.
move hlen_before_cell into _replace_rlhist_multiline

make hlen_before_cell a class member and move all multiline
history functionality into _replace_rlhist_multiline.
Closes gh-911
Fix a couple of core tests under Python 3.
Minor tweak to nbformat, still not passing test on Python 3.
replace rl history after running the cell

so one does not save e.g. raw_input entries in the history
move parallel doc figures into 'figs' subdir

also fix a few broken links after some renames in the examples dir.
update parallel docs with some changes from scipy tutorial

also added a couple more parallel examples:

* iopubwatcher for watching stdout/stderr of a cluster
* itermapresult for iterating through AsyncMapResults without waiting for all to complete
* customresults for advanced handling of results not provided by AsyncResult objects