diff --git a/IPython/lib/__init__.py b/IPython/lib/__init__.py index c631c01..482dcea 100644 --- a/IPython/lib/__init__.py +++ b/IPython/lib/__init__.py @@ -21,6 +21,7 @@ from IPython.lib.inputhook import ( enable_tk, disable_tk, enable_glut, disable_glut, enable_pyglet, disable_pyglet, + enable_gtk3, disable_gtk3, set_inputhook, clear_inputhook, current_gui ) diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py index 54d4ae7..898e69d 100644 --- a/IPython/lib/inputhook.py +++ b/IPython/lib/inputhook.py @@ -36,6 +36,7 @@ GUI_TK = 'tk' GUI_OSX = 'osx' GUI_GLUT = 'glut' GUI_PYGLET = 'pyglet' +GUI_GTK3 = 'gtk3' GUI_NONE = 'none' # i.e. disable #----------------------------------------------------------------------------- @@ -100,7 +101,7 @@ class InputHookManager(object): This class installs various hooks under ``PyOSInputHook`` to handle GUI event loop integration. """ - + def __init__(self): if ctypes is None: warn("IPython GUI event loop requires ctypes, %gui will not be available\n") @@ -222,7 +223,7 @@ class InputHookManager(object): def enable_qt4(self, app=None): """Enable event loop integration with PyQt4. - + Parameters ---------- app : Qt Application, optional. @@ -288,7 +289,7 @@ class InputHookManager(object): def disable_gtk(self): """Disable event loop integration with PyGTK. - + This merely sets PyOS_InputHook to NULL. """ self.clear_inputhook() @@ -319,7 +320,7 @@ class InputHookManager(object): def disable_tk(self): """Disable event loop integration with Tkinter. - + This merely sets PyOS_InputHook to NULL. """ self.clear_inputhook() @@ -345,7 +346,7 @@ class InputHookManager(object): 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 """ @@ -379,7 +380,7 @@ class InputHookManager(object): def disable_glut(self): """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. @@ -421,6 +422,33 @@ class InputHookManager(object): """ self.clear_inputhook() + def enable_gtk3(self, app=None): + """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. + """ + from IPython.lib.inputhookgtk3 import inputhook_gtk3 + self.set_inputhook(inputhook_gtk3) + self._current_gui = GUI_GTK + + def disable_gtk3(self): + """Disable event loop integration with PyGTK. + + This merely sets PyOS_InputHook to NULL. + """ + self.clear_inputhook() + def current_gui(self): """Return a string indicating the currently active GUI or None.""" return self._current_gui @@ -439,6 +467,8 @@ enable_glut = inputhook_manager.enable_glut disable_glut = inputhook_manager.disable_glut enable_pyglet = inputhook_manager.enable_pyglet disable_pyglet = inputhook_manager.disable_pyglet +enable_gtk3 = inputhook_manager.enable_gtk3 +disable_gtk3 = inputhook_manager.disable_gtk3 clear_inputhook = inputhook_manager.clear_inputhook set_inputhook = inputhook_manager.set_inputhook current_gui = inputhook_manager.current_gui @@ -480,6 +510,7 @@ def enable_gui(gui=None, app=None): GUI_QT4: enable_qt4, GUI_GLUT: enable_glut, GUI_PYGLET: enable_pyglet, + GUI_GTK3: enable_gtk3, } try: gui_hook = guis[gui]