Repository: ipython/ipython

Issue:
%pylab inline blows up for single process ipython
This isn't that big of a deal, since it doesn't necessarily even make sense to have %pylab inline work in a single-process IPython, but thought I'd make a note of it here, so we can keep track of it.

```
In [1]: pylab inline

Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.kernel.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-550caa57204a> in <module>()
----> 1 get_ipython().magic(u'pylab inline')

/home/pi/code/ipython/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2180         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2181         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2182         return self.run_line_magic(magic_name, magic_arg_s)
   2183 
   2184     #-------------------------------------------------------------------------

/home/pi/code/ipython/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2101                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2102             with self.builtin_trap:
-> 2103                 result = fn(*args,**kwargs)
   2104             return result
   2105 

/home/pi/code/ipython/IPython/core/magics/pylab.pyc in pylab(self, parameter_s)

/home/pi/code/ipython/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    189     # but it's overkill for just that one bit of state.
    190     def magic_deco(arg):
--> 191         call = lambda f, *a, **k: f(*a, **k)
    192 
    193         if callable(arg):

/home/pi/code/ipython/IPython/core/magics/pylab.pyc in pylab(self, parameter_s)
     86             import_all_status = True
     87 
---> 88         self.shell.enable_pylab(parameter_s, import_all=import_all_status, welcome_message=True)

/home/pi/code/ipython/IPython/core/interactiveshell.pyc in enable_pylab(self, gui, import_all, welcome_message)
   2900         # Now we must activate the gui pylab wants to use, and fix %run to take
   2901         # plot updates into account
-> 2902         self.enable_gui(gui)
   2903         self.magics_manager.registry['ExecutionMagics'].default_runner = \
   2904         mpl_runner(self.safe_execfile)

/home/pi/code/ipython/IPython/terminal/interactiveshell.pyc in enable_gui(gui, app)
    305         # Deferred import
    306         from IPython.lib.inputhook import enable_gui as real_enable_gui
--> 307         return real_enable_gui(gui, app)
    308 
    309     def __init__(self, config=None, ipython_dir=None, profile_dir=None,

/home/pi/code/ipython/IPython/lib/inputhook.pyc in enable_gui(gui, app)
    524     except KeyError:
    525         e = "Invalid GUI request %r, valid ones are:%s" % (gui, guis.keys())
--> 526         raise ValueError(e)
    527     return gui_hook(app)
    528 

ValueError: Invalid GUI request u'inline', valid ones are:['osx', 'qt4', 'glut', 'gtk3', 'pyglet', 'wx', 'none', 'qt', 'gtk', 'tk', None]
```



Discussion:

Resolving patch:
diff --git a/IPython/kernel/zmq/eventloops.py b/IPython/kernel/zmq/eventloops.py
--- a/IPython/kernel/zmq/eventloops.py
+++ b/IPython/kernel/zmq/eventloops.py
@@ -209,7 +209,8 @@ def doi():
 def enable_gui(gui, kernel=None):
     """Enable integration with a given GUI"""
     if gui not in loop_map:
-        raise ValueError("GUI %r not supported" % gui)
+        e = "Invalid GUI request %r, valid ones are:%s" % (gui, loop_map.keys())
+        raise ValueError(e)
     if kernel is None:
         if Application.initialized():
             kernel = getattr(Application.instance(), 'kernel', None)
diff --git a/IPython/kernel/zmq/zmqshell.py b/IPython/kernel/zmq/zmqshell.py
--- a/IPython/kernel/zmq/zmqshell.py
+++ b/IPython/kernel/zmq/zmqshell.py
@@ -503,8 +503,13 @@ def _exit_now_changed(self, name, old, new):
 
     # Over ZeroMQ, GUI control isn't done with PyOS_InputHook as there is no
     # interactive input being read; we provide event loop support in ipkernel
-    from .eventloops import enable_gui
-    enable_gui = staticmethod(enable_gui)
+    @staticmethod
+    def enable_gui(gui):
+        from .eventloops import enable_gui as real_enable_gui
+        try:
+            real_enable_gui(gui)
+        except ValueError as e:
+            raise UsageError("%s" % e)
 
     def init_environment(self):
         """Configure the user's environment.
diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py
--- a/IPython/terminal/interactiveshell.py
+++ b/IPython/terminal/interactiveshell.py
@@ -304,7 +304,10 @@ def enable_gui(gui=None, app=None):
         """
         # Deferred import
         from IPython.lib.inputhook import enable_gui as real_enable_gui
-        return real_enable_gui(gui, app)
+        try:
+            return real_enable_gui(gui, app)
+        except ValueError as e:
+            raise UsageError("%s" % e)
     
     def __init__(self, config=None, ipython_dir=None, profile_dir=None,
                  user_ns=None, user_module=None, custom_exceptions=((),None),


Test patch: