From a711787105924c157c5423a9fabf1d269fcaef89 2016-02-23 17:48:04 From: Thomas Kluyver Date: 2016-02-23 17:48:04 Subject: [PATCH] Better error message for unknown input hook Closes gh-9264 --- 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