Permalink
Browse files

Support v2 PyQt4 APIs and PySide in kernel's GUI support.

Closes gh-8.
  • Loading branch information...
1 parent 4850497 commit cea5ae0c6fb9d29bbf84a12acc65a2237d6a0cfe epatters committed Jul 1, 2011
Showing with 17 additions and 4 deletions.
  1. +12 −0 IPython/external/qt_for_kernel.py
  2. +1 −1 IPython/lib/guisupport.py
  3. +3 −2 IPython/lib/inputhook.py
  4. +1 −1 IPython/zmq/ipkernel.py
@@ -0,0 +1,12 @@
+""" Import Qt in a manner suitable for an IPython kernel.
+"""
+
+import sys
+
+# Older versions of matplotlib do not support PyQt4 v2 APIs or PySide, so we
+# cannot go through the preferred mechanism.
+matplotlib = sys.modules.get('matplotlib')
+if matplotlib and matplotlib.__version__ <= '1.0.1':
+ from PyQt4 import QtCore, QtGui
+else:
+ from IPython.external.qt import QtCore, QtGui
@@ -109,7 +109,7 @@ def start_event_loop_wx(app=None):
def get_app_qt4(*args, **kwargs):
"""Create a new qt4 app or return an existing one."""
- from PyQt4 import QtGui
+ from IPython.external.qt_for_kernel import QtGui
app = QtGui.QApplication.instance()
if app is None:
if not args:
View
@@ -181,7 +181,8 @@ def enable_qt4(self):
But, we first check to see if an application has already been
created. If so, we simply return that instance.
"""
- from PyQt4 import QtCore
+ from IPython.external.qt_for_kernel import QtCore, QtGui
+
# 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
@@ -190,8 +191,8 @@ def enable_qt4(self):
QtCore.pyqtRestoreInputHook()
except AttributeError:
pass
+
self._current_gui = GUI_QT4
- from PyQt4 import QtGui
app = QtCore.QCoreApplication.instance()
if app is None:
app = QtGui.QApplication([" "])
View
@@ -465,7 +465,7 @@ class QtKernel(Kernel):
def start(self):
"""Start a kernel with QtPy4 event loop integration."""
- from PyQt4 import QtCore
+ from IPython.external.qt_for_kernel import QtCore
from IPython.lib.guisupport import get_app_qt4, start_event_loop_qt4
self.app = get_app_qt4([" "])

0 comments on commit cea5ae0

Please sign in to comment.