Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use appnope in qt and wx gui support from the terminal; closes #6189 #6321

Merged
merged 1 commit into from Aug 17, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 17 additions & 9 deletions IPython/lib/inputhook.py
Expand Up @@ -104,7 +104,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")
Expand Down Expand Up @@ -204,14 +204,16 @@ def enable_wx(self, app=None):
app = wx.App(redirect=False, clearSigInt=False)
"""
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__)

from IPython.lib.inputhookwx import inputhook_wx
from IPython.external.appnope import nope
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this wants to be wrapped in a check for OS X 10.9, as in loop_wx (skip the kernel._ part, since that doesn't apply in inputhook).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is already included in appnap.init; nope() and nap() are dummied out if not in OS X 10.9.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I forgot I had done that.

self.set_inputhook(inputhook_wx)
nope()
self._current_gui = GUI_WX
import wx
if app is None:
Expand All @@ -227,13 +229,15 @@ def disable_wx(self):

This merely sets PyOS_InputHook to NULL.
"""
from IPython.external.appnope import nap
if GUI_WX in self._apps:
self._apps[GUI_WX]._in_event_loop = False
self.clear_inputhook()
nap()

def enable_qt4(self, app=None):
"""Enable event loop integration with PyQt4.

Parameters
----------
app : Qt Application, optional.
Expand All @@ -254,8 +258,10 @@ def enable_qt4(self, app=None):
app = QtGui.QApplication(sys.argv)
"""
from IPython.lib.inputhookqt4 import create_inputhook_qt4
from IPython.external.appnope import nope
app, inputhook_qt4 = create_inputhook_qt4(self, app)
self.set_inputhook(inputhook_qt4)
nope()

self._current_gui = GUI_QT4
app._in_event_loop = True
Expand All @@ -267,9 +273,11 @@ def disable_qt4(self):

This merely sets PyOS_InputHook to NULL.
"""
from IPython.external.appnope import nap
if GUI_QT4 in self._apps:
self._apps[GUI_QT4]._in_event_loop = False
self.clear_inputhook()
nap()

def enable_gtk(self, app=None):
"""Enable event loop integration with PyGTK.
Expand Down Expand Up @@ -299,7 +307,7 @@ def enable_gtk(self, app=None):

def disable_gtk(self):
"""Disable event loop integration with PyGTK.

This merely sets PyOS_InputHook to NULL.
"""
self.clear_inputhook()
Expand Down Expand Up @@ -333,7 +341,7 @@ def enable_tk(self, app=None):

def disable_tk(self):
"""Disable event loop integration with Tkinter.

This merely sets PyOS_InputHook to NULL.
"""
self.clear_inputhook()
Expand All @@ -359,7 +367,7 @@ def enable_glut(self, app=None):
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
"""
Expand Down Expand Up @@ -393,7 +401,7 @@ def enable_glut(self, app=None):

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.
Expand Down