diff --git a/IPython/lib/guisupport.py b/IPython/lib/guisupport.py index 9a0503d..9a8e3df 100644 --- a/IPython/lib/guisupport.py +++ b/IPython/lib/guisupport.py @@ -47,6 +47,9 @@ we proposed the following informal protocol: to see if ``_in_event_loop`` attribute has been set. If it is set, you *must* use its value. If it has not been set, you can query the toolkit in the normal manner. +* If you want GUI support and no one else has created an application or + started the event loop you *must* do this. We don't want projects to + attempt to defer these things to someone else if they themselves need it. The functions below implement this logic for each GUI toolkit. If you need to create custom application subclasses, you will likely have to modify this diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index 5cf3d37..1df405c 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -302,13 +302,15 @@ class QtKernel(Kernel): """Start a kernel with QtPy4 event loop integration.""" from PyQt4 import QtGui, QtCore - self.app = QtGui.QApplication([]) - self.app.setQuitOnLastWindowClosed (False) + from IPython.lib.guisupport import ( + get_app_qt4, start_event_loop_qt4 + ) + self.app = get_app_qt4([" "]) + self.app.setQuitOnLastWindowClosed(False) self.timer = QtCore.QTimer() self.timer.timeout.connect(self.do_one_iteration) self.timer.start(50) - self.app.exec_() - + start_event_loop_qt4(self.app) class WxKernel(Kernel): """A Kernel subclass with Wx support.""" @@ -317,6 +319,7 @@ class WxKernel(Kernel): """Start a kernel with wx event loop support.""" import wx + from IPython.lib.guisupport import start_event_loop_wx doi = self.do_one_iteration # We have to put the wx.Timer in a wx.Frame for it to fire properly. @@ -342,7 +345,7 @@ class WxKernel(Kernel): # The redirect=False here makes sure that wx doesn't replace # sys.stdout/stderr with its own classes. self.app = IPWxApp(redirect=False) - self.app.MainLoop() + start_event_loop_wx(self.app) class TkKernel(Kernel):