From d6eb2f64daadedf36a8ad850e867e555b7c5f4b0 2016-02-23 22:55:34 From: Matthias Bussonnier Date: 2016-02-23 22:55:34 Subject: [PATCH] Merge pull request #9268 from takluyver/i9264 Better error message for unknown input hook --- diff --git a/IPython/terminal/pt_inputhooks/__init__.py b/IPython/terminal/pt_inputhooks/__init__.py index 94709ec..7030ec5 100644 --- a/IPython/terminal/pt_inputhooks/__init__.py +++ b/IPython/terminal/pt_inputhooks/__init__.py @@ -3,14 +3,36 @@ import os aliases = { 'qt4': 'qt', + 'gtk2': 'gtk', } +backends = [ + 'qt', 'qt4', 'qt5', + 'gtk', 'gtk2', 'gtk3', + 'tk', + 'wx', + 'pyglet', 'glut', +] + +class UnknownBackend(KeyError): + def __init__(self, name): + self.name = name + + def __str__(self): + return ("No event loop integration for {!r}. " + "Supported event loops are: {}").format(self.name, + ', '.join(backends)) + def get_inputhook_func(gui): + if gui not in backends: + raise UnknownBackend(gui) + if gui in aliases: return get_inputhook_func(aliases[gui]) if gui == 'qt5': os.environ['QT_API'] = 'pyqt5' + gui = 'qt' mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui) return mod.inputhook