From 64ae0c3f4742730a9cbef9ff85fc320ddd1326e9 2009-08-22 21:04:36 From: Brian Granger Date: 2009-08-22 21:04:36 Subject: [PATCH] Fixed a few bugs and added spin_qt4 and spin_wx. --- diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 9c109a8..539656c 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -3550,11 +3550,11 @@ Defaulting color scheme to 'NoColor'""" interrupts should work without any problems. The following toolkits are supports: wxPython, PyQt4, PyGTK, and Tk:: - %gui wx # enable wxPython event loop integration - %gui qt4 # enable PyQt4 event loop integration - %gui gtk # enable PyGTK event loop integration - %gui tk # enable Tk event loop integration - %gui # disable all event loop integration + %gui wx # enable wxPython event loop integration + %gui qt4|qt # enable PyQt4 event loop integration + %gui gtk # enable PyGTK event loop integration + %gui tk # enable Tk event loop integration + %gui # disable all event loop integration WARNING: after any of these has been called you can simply create an application object, but DO NOT start the event loop yourself, as @@ -3576,7 +3576,7 @@ Defaulting color scheme to 'NoColor'""" inputhook.clear_inputhook() elif 'wx' in parameter_s: return inputhook.enable_wx(app) - elif 'qt4' in parameter_s: + elif ('qt4' in parameter_s) or ('qt' in parameter_s): return inputhook.enable_qt4(app) elif 'gtk' in parameter_s: return inputhook.enable_gtk(app) diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py index f7144c7..d2603a0 100644 --- a/IPython/lib/inputhook.py +++ b/IPython/lib/inputhook.py @@ -26,6 +26,31 @@ def _dummy_mainloop(*args, **kw): pass +def spin_qt4(): + from PyQt4 import QtCore, QtGui + + app = QtCore.QCoreApplication.instance() + if app is not None and app.thread == QtCore.QThread.currentThread(): + timer = QtCore.QTimer() + QtCore.QObject.connect(timer, + QtCore.SIGNAL('timeout()'), + QtCore.SLOT('quit()')) + self.timer.start(100) + QtCore.QCoreApplication.exec_() + timer.stop() + + +def spin_wx(): + app = wx.GetApp() + if app is not None and wx.Thread_IsMain(): + evtloop = wx.EventLoop() + ea = wx.EventLoopActivator(evtloop) + while evtloop.Pending(): + evtloop.Dispatch() + app.ProcessIdle() + del ea + + class InputHookManager(object): """Manage PyOS_InputHook for different GUI toolkits. @@ -203,7 +228,7 @@ class InputHookManager(object): self._hijack_qt4() if app: from PyQt4 import QtGui - app = QtGui.QApplication.instance() + app = QtCore.QCoreApplication.instance() if app is None: app = QtGui.QApplication(sys.argv) self._apps['qt4'] = app