Important

This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

Module: lib.inputhook

Deprecated since IPython 5.0

Inputhook management for GUI event loop integration.

11 Classes

class IPython.lib.inputhook.InputHookManager

Bases: object

DEPRECATED since IPython 5.0

Manage PyOS_InputHook for different GUI toolkits.

This class installs various hooks under PyOSInputHook to handle GUI event loop integration.

__init__()
clear_app_refs(gui=None)

DEPRECATED since IPython 5.0

Clear IPython’s internal reference to an application instance.

Whenever we create an app for a user on qt4 or wx, we hold a reference to the app. This is needed because in some cases bad things can happen if a user doesn’t hold a reference themselves. This method is provided to clear the references we are holding.

Parameters:gui (None or str) – If None, clear all app references. If (‘wx’, ‘qt4’) clear the app for that toolkit. References are not held for gtk or tk as those toolkits don’t have the notion of an app.
clear_inputhook(app=None)

DEPRECATED since IPython 5.0

Set PyOS_InputHook to NULL and return the previous one.

Parameters:app (optional, ignored) – This parameter is allowed only so that clear_inputhook() can be called with a similar interface as all the enable_* methods. But the actual value of the parameter is ignored. This uniform interface makes it easier to have user-level entry points in the main IPython app like enable_gui().
current_gui()

DEPRECATED since IPython 5.0

Return a string indicating the currently active GUI or None.

disable_gui()

DEPRECATED since IPython 5.0

Disable GUI event loop integration.

If an application was registered, this sets its _in_event_loop attribute to False. It then calls clear_inputhook().

enable_gui(gui=None, app=None)

DEPRECATED since IPython 5.0

Switch amongst GUI input hooks by name.

This is a higher level method than set_inputhook() - it uses the GUI name to look up a registered object which enables the input hook for that GUI.

Parameters:
  • gui (optional, string or None) – If None (or ‘none’), clears input hook, otherwise it must be one of the recognized GUI names (see GUI_* constants in module).
  • app (optional, existing application object.) – For toolkits that have the concept of a global app, you can supply an existing one. If not given, the toolkit will be probed for one, and if none is found, a new one will be created. Note that GTK does not have this concept, and passing an app if gui=="GTK" will raise an error.
Returns:

  • The output of the underlying gui switch routine, typically the actual
  • PyOS_InputHook wrapper object or the GUI toolkit app created, if there was
  • one.

get_pyos_inputhook()

DEPRECATED since IPython 5.0

Return the current PyOS_InputHook as a ctypes.c_void_p.

get_pyos_inputhook_as_func()

DEPRECATED since IPython 5.0

Return the current PyOS_InputHook as a ctypes.PYFUNCYPE.

register(toolkitname, *aliases)

DEPRECATED since IPython 5.0

Register a class to provide the event loop for a given GUI.

This is intended to be used as a class decorator. It should be passed the names with which to register this GUI integration. The classes themselves should subclass InputHookBase.

@inputhook_manager.register('qt')
class QtInputHook(InputHookBase):
    def enable(self, app=None):
        ...
set_inputhook(callback)

DEPRECATED since IPython 5.0

Set PyOS_InputHook to callback and return the previous one.

class IPython.lib.inputhook.InputHookBase(manager)

Bases: object

DEPRECATED since IPython 5.0

Base class for input hooks for specific toolkits.

Subclasses should define an enable() method with one argument, app, which will either be an instance of the toolkit’s application class, or None. They may also define a disable() method with no arguments.

__init__(manager)
class IPython.lib.inputhook.NullInputHook(manager)

Bases: IPython.lib.inputhook.InputHookBase

DEPRECATED since IPython 5.0

A null inputhook that doesn’t need to do anything

class IPython.lib.inputhook.WxInputHook(manager)

Bases: IPython.lib.inputhook.InputHookBase

disable()

DEPRECATED since IPython 5.0

Disable event loop integration with wxPython.

This restores appnapp on OS X

enable(app=None)

DEPRECATED since IPython 5.0

Enable event loop integration with wxPython.

Parameters:app (WX Application, optional.) – Running application to use. If not given, we probe WX for an existing application object, and create a new one if none is found.

Notes

This methods sets the PyOS_InputHook for wxPython, which allows the wxPython to integrate with terminal based applications like IPython.

If app is not given we probe for an existing one, and return it if found. If no existing app is found, we create an wx.App as follows:

import wx
app = wx.App(redirect=False, clearSigInt=False)
class IPython.lib.inputhook.Qt4InputHook(manager)

Bases: IPython.lib.inputhook.InputHookBase

disable_qt4()

DEPRECATED since IPython 5.0

Disable event loop integration with PyQt4.

This restores appnapp on OS X

enable(app=None)

DEPRECATED since IPython 5.0

Enable event loop integration with PyQt4.

Parameters:app (Qt Application, optional.) – Running application to use. If not given, we probe Qt for an existing application object, and create a new one if none is found.

Notes

This methods sets the PyOS_InputHook for PyQt4, which allows the PyQt4 to integrate with terminal based applications like IPython.

If app is not given we probe for an existing one, and return it if found. If no existing app is found, we create an QApplication as follows:

from PyQt4 import QtCore
app = QtGui.QApplication(sys.argv)
class IPython.lib.inputhook.Qt5InputHook(manager)

Bases: IPython.lib.inputhook.Qt4InputHook

class IPython.lib.inputhook.GtkInputHook(manager)

Bases: IPython.lib.inputhook.InputHookBase

enable(app=None)

DEPRECATED since IPython 5.0

Enable event loop integration with PyGTK.

Parameters:app (ignored) – Ignored, it’s only a placeholder to keep the call signature of all gui activation methods consistent, which simplifies the logic of supporting magics.

Notes

This methods sets the PyOS_InputHook for PyGTK, which allows the PyGTK to integrate with terminal based applications like IPython.

class IPython.lib.inputhook.TkInputHook(manager)

Bases: IPython.lib.inputhook.InputHookBase

enable(app=None)

DEPRECATED since IPython 5.0

Enable event loop integration with Tk.

Parameters:app (toplevel Tkinter.Tk widget, optional.) – Running toplevel widget to use. If not given, we probe Tk for an existing one, and create a new one if none is found.

Notes

If you have already created a Tkinter.Tk object, the only thing done by this method is to register with the InputHookManager, since creating that object automatically sets PyOS_InputHook.

class IPython.lib.inputhook.GlutInputHook(manager)

Bases: IPython.lib.inputhook.InputHookBase

disable()

DEPRECATED since IPython 5.0

Disable event loop integration with glut.

This sets PyOS_InputHook to NULL and set the display function to a dummy one and set the timer to a dummy timer that will be triggered very far in the future.

enable(app=None)

DEPRECATED since IPython 5.0

Enable event loop integration with GLUT.

Parameters:app (ignored) – Ignored, it’s only a placeholder to keep the call signature of all gui activation methods consistent, which simplifies the logic of supporting magics.

Notes

This methods sets the PyOS_InputHook for GLUT, which allows the GLUT to integrate with terminal based applications like IPython. Due to GLUT limitations, it is currently not possible to start the event loop without first creating a window. You should thus not create another window but use instead the created one. See ‘gui-glut.py’ in the docs/examples/lib directory.

The default screen mode is set to: glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH

class IPython.lib.inputhook.PygletInputHook(manager)

Bases: IPython.lib.inputhook.InputHookBase

enable(app=None)

DEPRECATED since IPython 5.0

Enable event loop integration with pyglet.

Parameters:app (ignored) – Ignored, it’s only a placeholder to keep the call signature of all gui activation methods consistent, which simplifies the logic of supporting magics.

Notes

This methods sets the PyOS_InputHook for pyglet, which allows pyglet to integrate with terminal based applications like IPython.

class IPython.lib.inputhook.Gtk3InputHook(manager)

Bases: IPython.lib.inputhook.InputHookBase

enable(app=None)

DEPRECATED since IPython 5.0

Enable event loop integration with Gtk3 (gir bindings).

Parameters:app (ignored) – Ignored, it’s only a placeholder to keep the call signature of all gui activation methods consistent, which simplifies the logic of supporting magics.

Notes

This methods sets the PyOS_InputHook for Gtk3, which allows the Gtk3 to integrate with terminal based applications like IPython.