##// END OF EJS Templates
Address comments,...
Address comments, Remove inverse, Deselect instead of unselect, Add separator.

File last commit:

r18504:29a0deb4
r20321:cdda1efa
Show More
inputhook.py
584 lines | 19.7 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.
"""
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2008-2011 The IPython Development Team
Brian Granger
First draft of full inputhook management.
r2066 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Bradley M. Froehle
Remove hard dependecy on ctypes....
r6100 try:
import ctypes
except ImportError:
ctypes = None
Doug Blank
Summary of changes:...
r15208 except SystemError: # IronPython issue, 2/8/2014
Doug Blank
Minimal changes to import IPython from IronPython
r15154 ctypes = None
Christian Boos
inputhook: make stdin_ready() function reusable...
r4913 import os
Brian Granger
Work on the user focused GUI event loop interface....
r2195 import sys
MinRK
check wxPython version in inputhook...
r7688 from distutils.version import LooseVersion as V
Bradley M. Froehle
Remove hard dependecy on ctypes....
r6100
from IPython.utils.warn import warn
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'
Thomi Richards
Gtk3 integration with ipython works.
r6459 GUI_GTK3 = 'gtk3'
Christian Boos
inputhook: use '%gui none' for disabling the input hook.
r4943 GUI_NONE = 'none' # i.e. disable
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214
#-----------------------------------------------------------------------------
Christian Boos
inputhook: make stdin_ready() function reusable...
r4913 # Utilities
Brian Granger
First draft of full inputhook management.
r2066 #-----------------------------------------------------------------------------
Christian Boos
inputhook: further cleanups for stdin_ready()...
r4930 def _stdin_ready_posix():
"""Return True if there's something to read on stdin (posix version)."""
infds, outfds, erfds = select.select([sys.stdin],[],[],0)
return bool(infds)
def _stdin_ready_nt():
"""Return True if there's something to read on stdin (nt version)."""
return msvcrt.kbhit()
def _stdin_ready_other():
"""Return True, assuming there's something to read on stdin."""
return True #
Christian Boos
inputhook: disable CTRL+C when a hook is active....
r4944
def _ignore_CTRL_C_posix():
"""Ignore CTRL+C (SIGINT)."""
signal.signal(signal.SIGINT, signal.SIG_IGN)
def _allow_CTRL_C_posix():
"""Take CTRL+C into account (SIGINT)."""
signal.signal(signal.SIGINT, signal.default_int_handler)
def _ignore_CTRL_C_other():
"""Ignore CTRL+C (not implemented)."""
pass
def _allow_CTRL_C_other():
"""Take CTRL+C into account (not implemented)."""
pass
Christian Boos
inputhook: further cleanups for stdin_ready()...
r4930 if os.name == 'posix':
import select
Christian Boos
inputhook: disable CTRL+C when a hook is active....
r4944 import signal
Christian Boos
inputhook: further cleanups for stdin_ready()...
r4930 stdin_ready = _stdin_ready_posix
Christian Boos
inputhook: disable CTRL+C when a hook is active....
r4944 ignore_CTRL_C = _ignore_CTRL_C_posix
allow_CTRL_C = _allow_CTRL_C_posix
Christian Boos
inputhook: further cleanups for stdin_ready()...
r4930 elif os.name == 'nt':
import msvcrt
stdin_ready = _stdin_ready_nt
Christian Boos
inputhook: disable CTRL+C when a hook is active....
r4944 ignore_CTRL_C = _ignore_CTRL_C_other
allow_CTRL_C = _allow_CTRL_C_other
Christian Boos
inputhook: further cleanups for stdin_ready()...
r4930 else:
stdin_ready = _stdin_ready_other
Christian Boos
inputhook: disable CTRL+C when a hook is active....
r4944 ignore_CTRL_C = _ignore_CTRL_C_other
allow_CTRL_C = _allow_CTRL_C_other
Christian Boos
inputhook: make stdin_ready() function reusable...
r4913
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.
"""
Thomi Richards
Reverting whitespace changes to inputhook.py.
r6467
Brian Granger
First draft of full inputhook management.
r2066 def __init__(self):
Bradley M. Froehle
Remove hard dependecy on ctypes....
r6100 if ctypes is None:
Thomas Kluyver
Fix IPython.utils.warn API so messages are automatically displayed followed by a newline.
r8223 warn("IPython GUI event loop requires ctypes, %gui will not be available")
Bradley M. Froehle
Remove hard dependecy on ctypes....
r6100 return
Brian Granger
First draft of full inputhook management.
r2066 self.PYFUNC = ctypes.PYFUNCTYPE(ctypes.c_int)
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 self.guihooks = {}
self.aliases = {}
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."""
Christian Boos
inputhook: disable CTRL+C when a hook is active....
r4944 # On platforms with 'readline' support, it's all too likely to
# have a KeyboardInterrupt signal delivered *even before* an
# initial ``try:`` clause in the callback can be executed, so
# we need to disable CTRL+C in this situation.
ignore_CTRL_C()
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
Christian Boos
inputhook: disable CTRL+C when a hook is active....
r4944 allow_CTRL_C()
Brian Granger
First draft of full inputhook management.
r2066 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:
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 self.apps = {}
elif gui in self.apps:
del self.apps[gui]
Brian Granger
Work on inputhook....
r2208
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 def register(self, toolkitname, *aliases):
"""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 :class:`InputHookBase`.
Thomas Kluyver
Add docs about extending GUI integration
r17893 ::
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889
Thomas Kluyver
Add docs about extending GUI integration
r17893 @inputhook_manager.register('qt')
class QtInputHook(InputHookBase):
def enable(self, app=None):
...
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 """
def decorator(cls):
inst = cls(self)
self.guihooks[toolkitname] = inst
for a in aliases:
self.aliases[a] = toolkitname
return cls
return decorator
def current_gui(self):
"""Return a string indicating the currently active GUI or None."""
return self._current_gui
def enable_gui(self, gui=None, app=None):
"""Switch amongst GUI input hooks by name.
This is a higher level method than :meth:`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.
"""
if gui in (None, GUI_NONE):
return self.disable_gui()
if gui in self.aliases:
return self.enable_gui(self.aliases[gui], app)
try:
gui_hook = self.guihooks[gui]
except KeyError:
e = "Invalid GUI request {!r}, valid ones are: {}"
raise ValueError(e.format(gui, ', '.join(self.guihooks)))
self._current_gui = gui
Thomas Kluyver
Move app caching into InputHookManager...
r17906
app = gui_hook.enable(app)
if app is not None:
app._in_event_loop = True
self.apps[gui] = app
return app
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889
def disable_gui(self):
"""Disable GUI event loop integration.
If an application was registered, this sets its ``_in_event_loop``
attribute to False. It then calls :meth:`clear_inputhook`.
"""
gui = self._current_gui
if gui in self.apps:
self.apps[gui]._in_event_loop = False
return self.clear_inputhook()
class InputHookBase(object):
"""Base class for input hooks for specific toolkits.
Subclasses should define an :meth:`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 :meth:`disable` method with no arguments.
"""
def __init__(self, manager):
self.manager = manager
def disable(self):
pass
inputhook_manager = InputHookManager()
MinRK
put back null gui hook for osx...
r18011 @inputhook_manager.register('osx')
class NullInputHook(InputHookBase):
"""A null inputhook that doesn't need to do anything"""
def enable(self, app=None):
pass
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 @inputhook_manager.register('wx')
class WxInputHook(InputHookBase):
def enable(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 """
MinRK
check wxPython version in inputhook...
r7688 import wx
wx_version = V(wx.__version__).version
if wx_version < [2, 8]:
raise ValueError("requires wxPython >= 2.8, but you have %s" % wx.__version__)
Brian Granger
Fixed import statements for inputhook.
r2068 from IPython.lib.inputhookwx import inputhook_wx
Eric Firing
Use appnope in qt and wx gui support from the terminal; closes #6189...
r17669 from IPython.external.appnope import nope
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 self.manager.set_inputhook(inputhook_wx)
Eric Firing
Use appnope in qt and wx gui support from the terminal; closes #6189...
r17669 nope()
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889
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)
Thomas Kluyver
Move app caching into InputHookManager...
r17906
Brian Granger
Updating terminal GUI support to use guisupport.py for qt4/wx.
r2918 return app
Brian Granger
First draft of full inputhook management.
r2066
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 def disable(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
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 This restores appnapp on OS X
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """
Eric Firing
Use appnope in qt and wx gui support from the terminal; closes #6189...
r17669 from IPython.external.appnope import nap
nap()
Brian Granger
First draft of full inputhook management.
r2066
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 @inputhook_manager.register('qt', 'qt4')
class Qt4InputHook(InputHookBase):
def enable(self, app=None):
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """Enable event loop integration with PyQt4.
Thomi Richards
Reverting whitespace changes to inputhook.py.
r6467
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 """
Christian Boos
inputhook: move inputhook_qt4 related code in own file
r4931 from IPython.lib.inputhookqt4 import create_inputhook_qt4
Eric Firing
Use appnope in qt and wx gui support from the terminal; closes #6189...
r17669 from IPython.external.appnope import nope
Thomas Kluyver
Fix Qt inputhook...
r18504 app, inputhook_qt4 = create_inputhook_qt4(self.manager, app)
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 self.manager.set_inputhook(inputhook_qt4)
Eric Firing
Use appnope in qt and wx gui support from the terminal; closes #6189...
r17669 nope()
Christian Boos
inputhook: make PyQt4 plays nicer with pyreadline...
r4915
Brian Granger
Updating terminal GUI support to use guisupport.py for qt4/wx.
r2918 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
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 This restores appnapp on OS X
Brian Granger
More testing and docstrings added for inputhook.py
r2069 """
Eric Firing
Use appnope in qt and wx gui support from the terminal; closes #6189...
r17669 from IPython.external.appnope import nap
nap()
Brian Granger
First draft of full inputhook management.
r2066
Stefan Zimmermann
%gui qt5
r17904
@inputhook_manager.register('qt5')
class Qt5InputHook(Qt4InputHook):
def enable(self, app=None):
os.environ['QT_API'] = 'pyqt5'
return Qt4InputHook.enable(self, app)
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 @inputhook_manager.register('gtk')
class GtkInputHook(InputHookBase):
def enable(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)
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
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 self.manager.set_inputhook(inputhook_gtk)
Brian Granger
First draft of full inputhook management.
r2066
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 @inputhook_manager.register('tk')
class TkInputHook(InputHookBase):
def enable(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``.
"""
Fernando Perez
Make gui support code and examples uniform and all working correctly....
r4419 if app is None:
Thomas Kluyver
Fix tests for IPython.lib
r13376 try:
from tkinter import Tk # Py 3
except ImportError:
from Tkinter import Tk # Py 2
app = Tk()
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 app.withdraw()
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 self.manager.apps[GUI_TK] = app
Brian Granger
Finishing up the wx, qt4 and tk support. Still have to do gtk.
r2214 return app
Brian Granger
First draft of full inputhook management.
r2066
Nicolas Rougier
Factorized glut code into glut_support.py
r4819
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 @inputhook_manager.register('glut')
class GlutInputHook(InputHookBase):
def enable(self, app=None):
"""Enable event loop integration with GLUT.
Nicolas Rougier
Missing files added
r4692
Parameters
----------
Nicolas Rougier
Factorized glut code into glut_support.py
r4819
Nicolas Rougier
Missing files added
r4692 app : ignored
Nicolas Rougier
Factorized glut code into glut_support.py
r4819 Ignored, it's only a placeholder to keep the call signature of all
gui activation methods consistent, which simplifies the logic of
supporting magics.
Nicolas Rougier
Missing files added
r4692
Notes
-----
Nicolas Rougier
Tried to fix the CTRL-C problem (https://github.com/ipython/ipython/pull/742) and take other comments/typos into account
r4812 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.
Thomi Richards
Reverting whitespace changes to inputhook.py.
r6467
Nicolas Rougier
Tried to fix the CTRL-C problem (https://github.com/ipython/ipython/pull/742) and take other comments/typos into account
r4812 The default screen mode is set to:
Nicolas Rougier
Factorized glut code into glut_support.py
r4819 glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH
Nicolas Rougier
Added code for the GLUT interactive session
r4806 """
Nicolas Rougier
Tried to fix the CTRL-C problem (https://github.com/ipython/ipython/pull/742) and take other comments/typos into account
r4812
Nicolas Rougier
Removed the timer callback in favor of the idle one and re-use wx waiting time after an event is processed. This make things more reactive. Also, the created window is now made insivisible and is not supposed to be ever show or detroyed. Finally, fixed the bug in window closing for linux platform using the glutSetOption available on Freeglut.
r4831 import OpenGL.GLUT as glut
Nicolas Rougier
Remove the import * and specified what to import specifically instead
r4834 from IPython.lib.inputhookglut import glut_display_mode, \
glut_close, glut_display, \
glut_idle, inputhook_glut
Nicolas Rougier
Added code for the GLUT interactive session
r4806
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 if GUI_GLUT not in self.manager.apps:
Nicolas Rougier
Remove the import * and specified what to import specifically instead
r4834 glut.glutInit( sys.argv )
glut.glutInitDisplayMode( glut_display_mode )
Nicolas Rougier
Removed the timer callback in favor of the idle one and re-use wx waiting time after an event is processed. This make things more reactive. Also, the created window is now made insivisible and is not supposed to be ever show or detroyed. Finally, fixed the bug in window closing for linux platform using the glutSetOption available on Freeglut.
r4831 # This is specific to freeglut
if bool(glut.glutSetOption):
Nicolas Rougier
Remove the import * and specified what to import specifically instead
r4834 glut.glutSetOption( glut.GLUT_ACTION_ON_WINDOW_CLOSE,
glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS )
glut.glutCreateWindow( sys.argv[0] )
Nicolas Rougier
Removed the timer callback in favor of the idle one and re-use wx waiting time after an event is processed. This make things more reactive. Also, the created window is now made insivisible and is not supposed to be ever show or detroyed. Finally, fixed the bug in window closing for linux platform using the glutSetOption available on Freeglut.
r4831 glut.glutReshapeWindow( 1, 1 )
Nicolas Rougier
Remove the import * and specified what to import specifically instead
r4834 glut.glutHideWindow( )
glut.glutWMCloseFunc( glut_close )
glut.glutDisplayFunc( glut_display )
glut.glutIdleFunc( glut_idle )
Nicolas Rougier
Added code for the GLUT interactive session
r4806 else:
Nicolas Rougier
Remove the import * and specified what to import specifically instead
r4834 glut.glutWMCloseFunc( glut_close )
glut.glutDisplayFunc( glut_display )
Nicolas Rougier
Removed the timer callback in favor of the idle one and re-use wx waiting time after an event is processed. This make things more reactive. Also, the created window is now made insivisible and is not supposed to be ever show or detroyed. Finally, fixed the bug in window closing for linux platform using the glutSetOption available on Freeglut.
r4831 glut.glutIdleFunc( glut_idle)
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 self.manager.set_inputhook( inputhook_glut )
Nicolas Rougier
Added code for the GLUT interactive session
r4806
Nicolas Rougier
Factorized glut code into glut_support.py
r4819
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 def disable(self):
Nicolas Rougier
Added code for the GLUT interactive session
r4806 """Disable event loop integration with glut.
Thomi Richards
Reverting whitespace changes to inputhook.py.
r6467
Nicolas Rougier
Added code for the GLUT interactive session
r4806 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.
"""
Nicolas Rougier
Remove the import * and specified what to import specifically instead
r4834 import OpenGL.GLUT as glut
from glut_support import glutMainLoopEvent
Nicolas Rougier
Tried to fix the CTRL-C problem (https://github.com/ipython/ipython/pull/742) and take other comments/typos into account
r4812
glut.glutHideWindow() # This is an event to be processed below
glutMainLoopEvent()
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 super(GlutInputHook, self).disable()
Nicolas Rougier
Tried to fix the CTRL-C problem (https://github.com/ipython/ipython/pull/742) and take other comments/typos into account
r4812
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 @inputhook_manager.register('pyglet')
class PygletInputHook(InputHookBase):
def enable(self, app=None):
Nicolas Rougier
Tried to fix the CTRL-C problem (https://github.com/ipython/ipython/pull/742) and take other comments/typos into account
r4812 """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.
Nicolas Rougier
Missing files added
r4692
Nicolas Rougier
Tried to fix the CTRL-C problem (https://github.com/ipython/ipython/pull/742) and take other comments/typos into account
r4812 Notes
-----
This methods sets the ``PyOS_InputHook`` for pyglet, which allows
pyglet to integrate with terminal based applications like
IPython.
"""
from IPython.lib.inputhookpyglet import inputhook_pyglet
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 self.manager.set_inputhook(inputhook_pyglet)
Nicolas Rougier
Tried to fix the CTRL-C problem (https://github.com/ipython/ipython/pull/742) and take other comments/typos into account
r4812 return app
Nicolas Rougier
Missing files added
r4692
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 @inputhook_manager.register('gtk3')
class Gtk3InputHook(InputHookBase):
def enable(self, app=None):
Thomi Richards
Gtk3 integration with ipython works.
r6459 """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
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 self.manager.set_inputhook(inputhook_gtk3)
Thomi Richards
Gtk3 integration with ipython works.
r6459
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
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 enable_gui = inputhook_manager.enable_gui
disable_gui = inputhook_manager.disable_gui
Thomas Kluyver
Add module-level access to register method
r17890 register = inputhook_manager.register
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 guis = inputhook_manager.guihooks
# Deprecated methods: kept for backwards compatibility, do not use in new code
Thomas Kluyver
Deprecation warnings for enable_* functions in inputhook...
r17899 def _make_deprecated_enable(name):
def enable_toolkit(app=None):
warn("This function is deprecated - use enable_gui(%r) instead" % name)
inputhook_manager.enable_gui(name, app)
MinRK
put back null gui hook for osx...
r18011 enable_osx = _make_deprecated_enable('osx')
Thomas Kluyver
Deprecation warnings for enable_* functions in inputhook...
r17899 enable_wx = _make_deprecated_enable('wx')
enable_qt4 = _make_deprecated_enable('qt4')
enable_gtk = _make_deprecated_enable('gtk')
enable_tk = _make_deprecated_enable('tk')
enable_glut = _make_deprecated_enable('glut')
enable_pyglet = _make_deprecated_enable('pyglet')
enable_gtk3 = _make_deprecated_enable('gtk3')
def _deprecated_disable():
warn("This function is deprecated: use disable_gui() instead")
inputhook_manager.disable_gui()
Thomas Kluyver
Refactor inputhook to allow easy extension.
r17889 disable_wx = disable_qt4 = disable_gtk = disable_gtk3 = disable_glut = \
MinRK
put back null gui hook for osx...
r18011 disable_pyglet = disable_osx = _deprecated_disable