##// END OF EJS Templates
In-progress work on trying to get a robust inputhook setup....
Fernando Perez -
Show More
@@ -0,0 +1,57 b''
1 """Test the new %gui command. Run this in ipython as
2
3 %run switchgui [backend]
4
5 where the optional backend can be one of: qt4, gtk, tk, wx.
6 """
7
8 import sys
9 import time
10
11 import IPython.core.ipapi as ipapi
12 ip = ipapi.get()
13
14 from IPython.lib import inputhook
15
16 try:
17 backend = sys.argv[1]
18 #a = ip.magic('gui -a %s' % backend)
19 #a = ip.magic('gui %s' % backend)
20 except IndexError:
21 backend = 'qt'
22
23 backends = dict(wx='wxagg', qt='qt4agg', gtk='gtkagg', tk='tkagg')
24
25 import matplotlib
26 matplotlib.use(backends[backend])
27 #matplotlib.interactive(True)
28
29 import matplotlib
30 from matplotlib import pyplot as plt, mlab, pylab
31 import numpy as np
32
33 from numpy import *
34 from matplotlib.pyplot import *
35
36 x = np.linspace(0,pi,100)
37
38 print "A plot has been created"
39 line, = plot(x,sin(2*x))
40 plt.show()
41 inputhook.spin_qt4()
42
43 #raw_input("Press Enter to continue")
44
45 print "I will now count until 10, please hit Ctrl-C before I'm done..."
46 print "IPython should stop counting and return to the prompt without crashing."
47 print
48 line_x = line.get_data()[0]
49 for i in range(1,51):
50 print i,
51 sys.stdout.flush()
52 line.set_data(line_x,sin(x*i))
53 plt.title('i=%d' % i)
54 #plt.show()
55 plt.draw()
56 inputhook.spin_qt4()
57 #time.sleep(0.04)
@@ -22,6 +22,18 b' import sys'
22 # Code
22 # Code
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24
24
25 def appstart_qt4():
26 from PyQt4 import QtCore, QtGui
27
28 app = QtCore.QCoreApplication.instance()
29 print 'qtapp:', app
30 if app is not None:
31 if current_gui() == 'qt4':
32 pass
33 else:
34 app.exec_()
35
36
25 class _DummyMainloop(object):
37 class _DummyMainloop(object):
26 """A special manager to hijack GUI mainloops that is mostly a no-op.
38 """A special manager to hijack GUI mainloops that is mostly a no-op.
27
39
@@ -34,6 +46,12 b' class _DummyMainloop(object):'
34
46
35
47
36 def __call__(self, *args, **kw):
48 def __call__(self, *args, **kw):
49 force = kw.pop('force', False)
50 force = False
51 if force:
52 #print 'forced spin' # dbg
53 self.ml(*args, **kw)
54
37 if self.ihm.current_gui() == self.gui_type:
55 if self.ihm.current_gui() == self.gui_type:
38 pass
56 pass
39 else:
57 else:
@@ -45,14 +63,15 b' def spin_qt4():'
45
63
46 app = QtCore.QCoreApplication.instance()
64 app = QtCore.QCoreApplication.instance()
47 if (app is not None) and (app.thread() == QtCore.QThread.currentThread()):
65 if (app is not None) and (app.thread() == QtCore.QThread.currentThread()):
48 timer = QtCore.QTimer()
66 ## timer = QtCore.QTimer()
49 QtCore.QObject.connect(timer,
67 ## QtCore.QObject.connect(timer,
50 QtCore.SIGNAL('timeout()'),
68 ## QtCore.SIGNAL('timeout()'),
51 app,
69 ## app,
52 QtCore.SLOT('quit()'))
70 ## QtCore.SLOT('quit()'))
53 timer.start(100)
71 ## timer.start(100)
54 QtCore.QCoreApplication.exec_()
72 #QtCore.QCoreApplication.exec_(force=True)
55 timer.stop()
73 QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
74 ##timer.stop()
56
75
57
76
58 def spin_wx():
77 def spin_wx():
@@ -241,7 +260,7 b' class InputHookManager(object):'
241 except AttributeError:
260 except AttributeError:
242 pass
261 pass
243 self._current_gui = 'qt4'
262 self._current_gui = 'qt4'
244 self._hijack_qt4()
263 #self._hijack_qt4()
245 if app:
264 if app:
246 from PyQt4 import QtGui
265 from PyQt4 import QtGui
247 app = QtCore.QCoreApplication.instance()
266 app = QtCore.QCoreApplication.instance()
@@ -34,4 +34,9 b" if __name__ == '__main__':"
34 sw = SimpleWindow()
34 sw = SimpleWindow()
35 sw.show()
35 sw.show()
36
36
37 app.exec_()
37 try:
38 import IPython.lib.inputhook as i; i.appstart_qt4()
39 except ImportError:
40 app.exec_()
41
42 #import time; time.sleep(10)
General Comments 0
You need to be logged in to leave comments. Login now