##// END OF EJS Templates
Replaced deprecated raise call
Replaced deprecated raise call

File last commit:

r4810:81308e3b
r4810:81308e3b
Show More
inputhook.py
522 lines | 18.5 KiB | text/x-python | PythonLexer
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 # coding: utf-8
Brian Granger
First draft of full inputhook management.
r2066 """
Inputhook management for GUI event loop integration.
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2009 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import ctypes
Brian Granger
Work on the user focused GUI event loop interface....
r2195 import sys
MinRK
runtime warning for possible inputhook collision between pyreadline and qt...
r4150 import warnings
Brian Granger
First draft of full inputhook management.
r2066
#-----------------------------------------------------------------------------
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 # Constants
#-----------------------------------------------------------------------------
# Constants for identifying the GUI toolkits.
GUI_WX = 'wx'
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 GUI_QT = 'qt'
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 GUI_QT4 = 'qt4'
GUI_GTK = 'gtk'
GUI_TK = 'tk'
MinRK
add 'osx' to known pylab backends, fix pylab mode with MacOSX backend...
r3462 GUI_OSX = 'osx'
Nicolas Rougier
Added code for the GLUT interactive session
r4806 GUI_GLUT = 'glut'
Nicolas Rougier
Missing files added
r4692 GUI_PYGLET = 'pyglet'
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214
#-----------------------------------------------------------------------------
# Utility classes
Brian Granger
First draft of full inputhook management.
r2066 #-----------------------------------------------------------------------------
Fernando Perez
In-progress work on trying to get a robust inputhook setup....
r2213
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 #-----------------------------------------------------------------------------
# Main InputHookManager class
#-----------------------------------------------------------------------------
Brian Granger
Fixed a few bugs and added spin_qt4 and spin_wx.
r2210
Brian Granger
First draft of full inputhook management.
r2066 class InputHookManager(object):
Brian Granger
General work on inputhook and the docs....
r2197 """Manage PyOS_InputHook for different GUI toolkits.
This class installs various hooks under ``PyOSInputHook`` to handle
GUI event loop integration.
"""
Brian Granger
First draft of full inputhook management.
r2066
def __init__(self):
self.PYFUNC = ctypes.PYFUNCTYPE(ctypes.c_int)
Brian Granger
Work on inputhook....
r2208 self._apps = {}
Brian Granger
First draft of full inputhook management.
r2066 self._reset()
def _reset(self):
self._callback_pyfunctype = None
self._callback = None
self._installed = False
Brian Granger
General work on inputhook and the docs....
r2197 self._current_gui = None
Brian Granger
First draft of full inputhook management.
r2066
def get_pyos_inputhook(self):
Brian Granger
Adding more documentation of inputhook.py
r2209 """Return the current PyOS_InputHook as a ctypes.c_void_p."""
Brian Granger
First draft of full inputhook management.
r2066 return ctypes.c_void_p.in_dll(ctypes.pythonapi,"PyOS_InputHook")
def get_pyos_inputhook_as_func(self):
Brian Granger
Adding more documentation of inputhook.py
r2209 """Return the current PyOS_InputHook as a ctypes.PYFUNCYPE."""
Brian Granger
First draft of full inputhook management.
r2066 return self.PYFUNC.in_dll(ctypes.pythonapi,"PyOS_InputHook")
Brian Granger
More testing and docstrings added for inputhook.py
r2069 def set_inputhook(self, callback):
Brian Granger
Adding more documentation of inputhook.py
r2209 """Set PyOS_InputHook to callback and return the previous one."""
Brian Granger
First draft of full inputhook management.
r2066 self._callback = callback
self._callback_pyfunctype = self.PYFUNC(callback)
pyos_inputhook_ptr = self.get_pyos_inputhook()
original = self.get_pyos_inputhook_as_func()
pyos_inputhook_ptr.value = \
ctypes.cast(self._callback_pyfunctype, ctypes.c_void_p).value
self._installed = True
return original
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 def clear_inputhook(self, 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 :meth:`enable_gui`."""
Brian Granger
First draft of full inputhook management.
r2066 pyos_inputhook_ptr = self.get_pyos_inputhook()
original = self.get_pyos_inputhook_as_func()
pyos_inputhook_ptr.value = ctypes.c_void_p(None).value
self._reset()
return original
Brian Granger
Work on inputhook....
r2208 def clear_app_refs(self, gui=None):
"""Clear IPython's internal reference to an application instance.
Brian Granger
Adding more documentation of inputhook.py
r2209 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.
Brian Granger
Work on inputhook....
r2208 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.
"""
if gui is None:
self._apps = {}
elif self._apps.has_key(gui):
del self._apps[gui]
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 def enable_wx(self, app=None):
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """Enable event loop integration with wxPython.
Brian Granger
General work on inputhook and the docs....
r2197
Parameters
----------
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 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.
Brian Granger
General work on inputhook and the docs....
r2197
Notes
-----
Brian Granger
Adding more documentation of inputhook.py
r2209 This methods sets the ``PyOS_InputHook`` for wxPython, which allows
Brian Granger
More testing and docstrings added for inputhook.py
r2069 the wxPython to integrate with terminal based applications like
IPython.
Brian Granger
Adding more documentation of inputhook.py
r2209
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 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 :class:`wx.App` as
follows::
Brian Granger
Adding more documentation of inputhook.py
r2209
import wx
app = wx.App(redirect=False, clearSigInt=False)
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """
Brian Granger
Fixed import statements for inputhook.
r2068 from IPython.lib.inputhookwx import inputhook_wx
Brian Granger
First draft of full inputhook management.
r2066 self.set_inputhook(inputhook_wx)
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 self._current_gui = GUI_WX
Brian Granger
Updating terminal GUI support to use guisupport.py for qt4/wx.
r2918 import wx
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 if app is None:
app = wx.GetApp()
Brian Granger
Updating terminal GUI support to use guisupport.py for qt4/wx.
r2918 if app is None:
app = wx.App(redirect=False, clearSigInt=False)
app._in_event_loop = True
self._apps[GUI_WX] = app
return app
Brian Granger
First draft of full inputhook management.
r2066
def disable_wx(self):
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """Disable event loop integration with wxPython.
Brian Granger
Adding more documentation of inputhook.py
r2209
Brian Granger
More testing and docstrings added for inputhook.py
r2069 This merely sets PyOS_InputHook to NULL.
"""
Brian Granger
Updating terminal GUI support to use guisupport.py for qt4/wx.
r2918 if self._apps.has_key(GUI_WX):
self._apps[GUI_WX]._in_event_loop = False
Brian Granger
First draft of full inputhook management.
r2066 self.clear_inputhook()
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 def enable_qt4(self, app=None):
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """Enable event loop integration with PyQt4.
Brian Granger
General work on inputhook and the docs....
r2197 Parameters
----------
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 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.
Brian Granger
General work on inputhook and the docs....
r2197
Notes
-----
Brian Granger
Adding more documentation of inputhook.py
r2209 This methods sets the PyOS_InputHook for PyQt4, which allows
Brian Granger
More testing and docstrings added for inputhook.py
r2069 the PyQt4 to integrate with terminal based applications like
IPython.
Brian Granger
Adding more documentation of inputhook.py
r2209
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 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 :class:`QApplication`
as follows::
Brian Granger
Adding more documentation of inputhook.py
r2209
from PyQt4 import QtCore
app = QtGui.QApplication(sys.argv)
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """
epatters
Support v2 PyQt4 APIs and PySide in kernel's GUI support....
r4149 from IPython.external.qt_for_kernel import QtCore, QtGui
MinRK
runtime warning for possible inputhook collision between pyreadline and qt...
r4150 if 'pyreadline' in sys.modules:
# see IPython GitHub Issue #281 for more info on this issue
# Similar intermittent behavior has been reported on OSX,
# but not consistently reproducible
warnings.warn("""PyReadline's inputhook can conflict with Qt, causing delays
in interactive input. If you do see this issue, we recommend using another GUI
toolkit if you can, or disable readline with the configuration option
'TerminalInteractiveShell.readline_use=False', specified in a config file or
at the command-line""",
RuntimeWarning)
Brian Granger
First draft of full inputhook management.
r2066 # PyQt4 has had this since 4.3.1. In version 4.2, PyOS_InputHook
# was set when QtCore was imported, but if it ever got removed,
# you couldn't reset it. For earlier versions we can
# probably implement a ctypes version.
try:
QtCore.pyqtRestoreInputHook()
except AttributeError:
pass
epatters
Support v2 PyQt4 APIs and PySide in kernel's GUI support....
r4149
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 self._current_gui = GUI_QT4
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 if app is None:
app = QtCore.QCoreApplication.instance()
Brian Granger
Updating terminal GUI support to use guisupport.py for qt4/wx.
r2918 if app is None:
app = QtGui.QApplication([" "])
app._in_event_loop = True
self._apps[GUI_QT4] = app
return app
Brian Granger
First draft of full inputhook management.
r2066
def disable_qt4(self):
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """Disable event loop integration with PyQt4.
Brian Granger
Adding more documentation of inputhook.py
r2209
Brian Granger
More testing and docstrings added for inputhook.py
r2069 This merely sets PyOS_InputHook to NULL.
"""
Brian Granger
Updating terminal GUI support to use guisupport.py for qt4/wx.
r2918 if self._apps.has_key(GUI_QT4):
self._apps[GUI_QT4]._in_event_loop = False
Brian Granger
First draft of full inputhook management.
r2066 self.clear_inputhook()
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 def enable_gtk(self, app=None):
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """Enable event loop integration with PyGTK.
Brian Granger
General work on inputhook and the docs....
r2197
Parameters
----------
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 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.
Brian Granger
General work on inputhook and the docs....
r2197
Notes
-----
Brian Granger
More testing and docstrings added for inputhook.py
r2069 This methods sets the PyOS_InputHook for PyGTK, which allows
the PyGTK to integrate with terminal based applications like
IPython.
"""
Brian Granger
First draft of full inputhook management.
r2066 import gtk
try:
gtk.set_interactive(True)
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 self._current_gui = GUI_GTK
Brian Granger
First draft of full inputhook management.
r2066 except AttributeError:
# For older versions of gtk, use our own ctypes version
Brian Granger
Fixed import statements for inputhook.
r2068 from IPython.lib.inputhookgtk import inputhook_gtk
Brian Granger
Fixed two bugs in inputhook.
r2207 self.set_inputhook(inputhook_gtk)
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 self._current_gui = GUI_GTK
Brian Granger
First draft of full inputhook management.
r2066
def disable_gtk(self):
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """Disable event loop integration with PyGTK.
This merely sets PyOS_InputHook to NULL.
"""
Brian Granger
First draft of full inputhook management.
r2066 self.clear_inputhook()
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 def enable_tk(self, app=None):
Brian Granger
General work on inputhook and the docs....
r2197 """Enable event loop integration with Tk.
Parameters
----------
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 app : toplevel :class:`Tkinter.Tk` widget, optional.
Fernando Perez
Small fix to docstring and qt example.
r4421 Running toplevel widget to use. If not given, we probe Tk for an
existing one, and create a new one if none is found.
Brian Granger
General work on inputhook and the docs....
r2197
Notes
-----
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 If you have already created a :class:`Tkinter.Tk` object, the only
thing done by this method is to register with the
:class:`InputHookManager`, since creating that object automatically
Brian Granger
General work on inputhook and the docs....
r2197 sets ``PyOS_InputHook``.
"""
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 self._current_gui = GUI_TK
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 if app is None:
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 import Tkinter
app = Tkinter.Tk()
app.withdraw()
self._apps[GUI_TK] = app
return app
Brian Granger
First draft of full inputhook management.
r2066
def disable_tk(self):
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """Disable event loop integration with Tkinter.
This merely sets PyOS_InputHook to NULL.
"""
Brian Granger
First draft of full inputhook management.
r2066 self.clear_inputhook()
Nicolas Rougier
Missing files added
r4692
Nicolas Rougier
Added code for the GLUT interactive session
r4806 <<<<<<< HEAD
Nicolas Rougier
Missing files added
r4692
def enable_pyglet(self, app=None):
"""Enable event loop integration with pyglet.
Nicolas Rougier
Added code for the GLUT interactive session
r4806 =======
def enable_glut(self, app=None):
"""Enable event loop integration with GLUT.
>>>>>>> Added code for the GLUT interactive session
Nicolas Rougier
Missing files added
r4692
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
-----
Nicolas Rougier
Added code for the GLUT interactive session
r4806 <<<<<<< HEAD
Nicolas Rougier
Removed wx reference in comment
r4802 This methods sets the ``PyOS_InputHook`` for pyglet, which allows
Nicolas Rougier
Missing files added
r4692 pyglet to integrate with terminal based applications like
IPython.
"""
import pyglet
from IPython.lib.inputhookpyglet import inputhook_pyglet
self.set_inputhook(inputhook_pyglet)
self._current_gui = GUI_PYGLET
return app
def disable_pyglet(self):
"""Disable event loop integration with pyglet.
This merely sets PyOS_InputHook to NULL.
"""
Nicolas Rougier
Added code for the GLUT interactive session
r4806 =======
This methods sets the PyOS_InputHook for GLUT, which allows
the GLUT to integrate with terminal based applications like
IPython.
Nicolas Rougier
Canceled window reshape to 1x1 since the idea is now for the user to use this window as the main one because of weird seg-faults problem after user creates its own window (any subsequent gl error would lead to a segfault, even a simple one line requiring a non existent function
r4808 GLUT is quite an old library and it is difficult to ensure proper
Nicolas Rougier
Added code for the GLUT interactive session
r4806 integration within IPython since original GLUT does not allow to handle
events one by one. Instead, it requires for the mainloop to be entered
Nicolas Rougier
Fixed typos in comments
r4809 and never returned (there is not even a function to exit he
Nicolas Rougier
Added code for the GLUT interactive session
r4806 mainloop). Fortunately, there are alternatives such as freeglut
Nicolas Rougier
Canceled window reshape to 1x1 since the idea is now for the user to use this window as the main one because of weird seg-faults problem after user creates its own window (any subsequent gl error would lead to a segfault, even a simple one line requiring a non existent function
r4808 (available for linux and windows) and the OSX implementation gives
Nicolas Rougier
Added code for the GLUT interactive session
r4806 access to a glutCheckLoop() function that blocks itself until a new
event is received. This means we have to setup a default timer to
Nicolas Rougier
Canceled window reshape to 1x1 since the idea is now for the user to use this window as the main one because of weird seg-faults problem after user creates its own window (any subsequent gl error would lead to a segfault, even a simple one line requiring a non existent function
r4808 ensure we got at least one event that will unblock the function. We set
a default timer of 60fps.
Nicolas Rougier
Added code for the GLUT interactive session
r4806
Nicolas Rougier
Canceled window reshape to 1x1 since the idea is now for the user to use this window as the main one because of weird seg-faults problem after user creates its own window (any subsequent gl error would lead to a segfault, even a simple one line requiring a non existent function
r4808 Furthermore, it is not possible to install these handlers without a
window being first created. We choose to make this window invisible and
Nicolas Rougier
Fixed typos in comments
r4809 the user is supposed to make it visible when needed (see gui-glut.py in
Nicolas Rougier
Canceled window reshape to 1x1 since the idea is now for the user to use this window as the main one because of weird seg-faults problem after user creates its own window (any subsequent gl error would lead to a segfault, even a simple one line requiring a non existent function
r4808 the docs/examples/lib directory). This means that display mode options
Nicolas Rougier
Fixed typos in comments
r4809 are set at this level and user won't be able to change them later
Nicolas Rougier
Canceled window reshape to 1x1 since the idea is now for the user to use this window as the main one because of weird seg-faults problem after user creates its own window (any subsequent gl error would lead to a segfault, even a simple one line requiring a non existent function
r4808 without modifying the code. This should probably be made available via
IPython options system.
Nicolas Rougier
Added code for the GLUT interactive session
r4806
Script integration
------------------
if glut.glutGetWindow() > 0:
interactive = True
Nicolas Rougier
Canceled window reshape to 1x1 since the idea is now for the user to use this window as the main one because of weird seg-faults problem after user creates its own window (any subsequent gl error would lead to a segfault, even a simple one line requiring a non existent function
r4808 glut.glutShowWindow()
Nicolas Rougier
Added code for the GLUT interactive session
r4806 else:
Nicolas Rougier
Canceled window reshape to 1x1 since the idea is now for the user to use this window as the main one because of weird seg-faults problem after user creates its own window (any subsequent gl error would lead to a segfault, even a simple one line requiring a non existent function
r4808 interactive = False
Nicolas Rougier
Added code for the GLUT interactive session
r4806 glut.glutInit(sys.argv)
glut.glutInitDisplayMode( glut.GLUT_DOUBLE |
glut.GLUT_RGBA |
glut.GLUT_DEPTH )
...
if not interactive:
glut.glutMainLoop()
"""
import OpenGL.GLUT as glut
import OpenGL.platform as platform
def timer_none(fps):
''' Dummy timer function '''
pass
def display():
''' Dummy display function '''
pass
def timer(fps):
# We should normally set the active window to 1 and post a
# redisplay for each window. The problem is that we do not know
# how much active windows we have and there is no function in glut
# to get that number.
# glut.glutSetWindow(1)
glut.glutTimerFunc( int(1000.0/fps), timer, fps)
glut.glutPostRedisplay()
glutMainLoopEvent = None
if sys.platform == 'darwin':
try:
glutCheckLoop = platform.createBaseFunction(
'glutCheckLoop', dll=platform.GLUT, resultType=None,
argTypes=[],
doc='glutCheckLoop( ) -> None',
argNames=(),
)
except AttributeError:
Nicolas Rougier
Replaced deprecated raise call
r4810 raise RuntimeError(
'''Your glut implementation does not allow interactive sessions'''
'''Consider installing freeglut.''')
Nicolas Rougier
Added code for the GLUT interactive session
r4806 glutMainLoopEvent = glutCheckLoop
elif glut.HAVE_FREEGLUT:
glutMainLoopEvent = glut.glutMainLoopEvent
else:
Nicolas Rougier
Replaced deprecated raise call
r4810 raise RuntimeError(
'''Your glut implementation does not allow interactive sessions. '''
'''Consider installing freeglut.''')
Nicolas Rougier
Added code for the GLUT interactive session
r4806
def inputhook_glut():
""" Process pending GLUT events only. """
# We need to protect against a user pressing Control-C when IPython is
# idle and this is running. We trap KeyboardInterrupt and pass.
try:
glutMainLoopEvent()
except KeyboardInterrupt:
pass
return 0
# Frame per second : 60
# Should be probably an IPython option
fps = 60
if not self._apps.has_key(GUI_GLUT):
glut.glutInit(sys.argv)
# Display mode shoudl be also an Ipython option since user won't be able
# to change it later
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH)
glut.glutCreateWindow(sys.argv[0])
Nicolas Rougier
Canceled window reshape to 1x1 since the idea is now for the user to use this window as the main one because of weird seg-faults problem after user creates its own window (any subsequent gl error would lead to a segfault, even a simple one line requiring a non existent function
r4808 # glut.glutReshapeWindow(1,1)
Nicolas Rougier
Added code for the GLUT interactive session
r4806 glut.glutHideWindow()
glut.glutDisplayFunc(display)
glut.glutTimerFunc( int(1000.0/fps), timer, fps)
else:
glut.glutDisplayFunc(display)
glut.glutTimerFunc( int(1000.0/fps), timer, fps)
self.set_inputhook(inputhook_glut)
self._current_gui = GUI_GLUT
self._apps[GUI_GLUT] = True
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.
"""
glut.HideWindow()
glut.glutTimerFunc( sys.maxint-1, null_timer_none, 0)
>>>>>>> Added code for the GLUT interactive session
Nicolas Rougier
Missing files added
r4692 self.clear_inputhook()
Brian Granger
General work on inputhook and the docs....
r2197 def current_gui(self):
"""Return a string indicating the currently active GUI or None."""
return self._current_gui
Brian Granger
First draft of full inputhook management.
r2066 inputhook_manager = InputHookManager()
enable_wx = inputhook_manager.enable_wx
disable_wx = inputhook_manager.disable_wx
enable_qt4 = inputhook_manager.enable_qt4
disable_qt4 = inputhook_manager.disable_qt4
enable_gtk = inputhook_manager.enable_gtk
disable_gtk = inputhook_manager.disable_gtk
Brian Granger
Fixed import statements for inputhook.
r2068 enable_tk = inputhook_manager.enable_tk
Brian Granger
More testing and docstrings added for inputhook.py
r2069 disable_tk = inputhook_manager.disable_tk
Nicolas Rougier
Added code for the GLUT interactive session
r4806 <<<<<<< HEAD
Nicolas Rougier
Missing files added
r4692 enable_pyglet = inputhook_manager.enable_pyglet
disable_pyglet = inputhook_manager.disable_pyglet
Nicolas Rougier
Added code for the GLUT interactive session
r4806 =======
enable_glut = inputhook_manager.enable_glut
disable_glut = inputhook_manager.disable_glut
>>>>>>> Added code for the GLUT interactive session
Brian Granger
More testing and docstrings added for inputhook.py
r2069 clear_inputhook = inputhook_manager.clear_inputhook
Brian Granger
General work on inputhook and the docs....
r2197 set_inputhook = inputhook_manager.set_inputhook
Brian Granger
Work on inputhook....
r2208 current_gui = inputhook_manager.current_gui
clear_app_refs = inputhook_manager.clear_app_refs
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363
# Convenience function to switch amongst them
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 def enable_gui(gui=None, app=None):
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 """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, clears input hook, otherwise it must be one of the recognized
GUI names (see ``GUI_*`` constants in module).
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 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.
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363
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.
"""
guis = {None: clear_inputhook,
MinRK
add 'osx' to known pylab backends, fix pylab mode with MacOSX backend...
r3462 GUI_OSX: lambda app=False: None,
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 GUI_TK: enable_tk,
GUI_GTK: enable_gtk,
GUI_WX: enable_wx,
GUI_QT: enable_qt4, # qt3 not supported
Nicolas Rougier
Missing files added
r4692 GUI_QT4: enable_qt4,
Nicolas Rougier
Added code for the GLUT interactive session
r4806 <<<<<<< HEAD
Nicolas Rougier
Missing files added
r4692 GUI_PYGLET: enable_pyglet,
}
Nicolas Rougier
Added code for the GLUT interactive session
r4806 =======
GUI_GLUT: enable_glut}
>>>>>>> Added code for the GLUT interactive session
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 try:
gui_hook = guis[gui]
except KeyError:
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 e = "Invalid GUI request %r, valid ones are:%s" % (gui, guis.keys())
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 raise ValueError(e)
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 return gui_hook(app)
Brian Granger
Updating terminal GUI support to use guisupport.py for qt4/wx.
r2918