### Navigation

- index
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »

# lib.inputhook

## Module: `lib.inputhook`

Inheritance diagram for `IPython.lib.inputhook`:

Inputhook management for GUI event loop integration.

## `InputHookManager`

class `IPython.lib.inputhook.``InputHookManager`

  Bases: `object`

  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)

    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)

    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`()

    Return a string indicating the currently active GUI or None.

  `disable_glut`()

    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.

  `disable_gtk`()

    Disable event loop integration with PyGTK.

    This merely sets PyOS_InputHook to NULL.

  `disable_pyglet`()

    Disable event loop integration with pyglet.

    This merely sets PyOS_InputHook to NULL.

  `disable_qt4`()

    Disable event loop integration with PyQt4.

    This merely sets PyOS_InputHook to NULL.

  `disable_tk`()

    Disable event loop integration with Tkinter.

    This merely sets PyOS_InputHook to NULL.

  `disable_wx`()

    Disable event loop integration with wxPython.

    This merely sets PyOS_InputHook to NULL.

  `enable_glut`(app=None)

    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

  `enable_gtk`(app=None)

    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.

  `enable_pyglet`(app=None)

    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.

  `enable_qt4`(app=None)

    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)

  `enable_tk`(app=None)

    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`.

  `enable_wx`(app=None)

    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)

  `get_pyos_inputhook`()

    Return the current PyOS_InputHook as a ctypes.c_void_p.

  `get_pyos_inputhook_as_func`()

    Return the current PyOS_InputHook as a ctypes.PYFUNCYPE.

  `set_inputhook`(callback)

    Set PyOS_InputHook to callback and return the previous one.

`IPython.lib.inputhook.``enable_gui`(gui=None, app=None)

  Switch amongst GUI input hooks by name.

  This is just a utility wrapper around the methods of the InputHookManager object.

  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. :

### Navigation

- index
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »