##// END OF EJS Templates
Added an improved mainloop manager....
Fernando Perez -
Show More
@@ -22,20 +22,35 b' import sys'
22 # Code
22 # Code
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24
24
25 def _dummy_mainloop(*args, **kw):
25 class _DummyMainloop(object):
26 pass
26 """A special manager to hijack GUI mainloops that is mostly a no-op.
27
28 This does have, however, special logic.
29 """
30 def __init__(self, ml, ihm, gui_type):
31 self.ml = ml
32 self.ihm = ihm
33 self.gui_type = gui_type
34
35
36 def __call__(self, *args, **kw):
37 if self.ihm.current_gui() == self.gui_type:
38 pass
39 else:
40 self.ml(*args, **kw)
27
41
28
42
29 def spin_qt4():
43 def spin_qt4():
30 from PyQt4 import QtCore, QtGui
44 from PyQt4 import QtCore, QtGui
31
45
32 app = QtCore.QCoreApplication.instance()
46 app = QtCore.QCoreApplication.instance()
33 if app is not None and app.thread == QtCore.QThread.currentThread():
47 if (app is not None) and (app.thread() == QtCore.QThread.currentThread()):
34 timer = QtCore.QTimer()
48 timer = QtCore.QTimer()
35 QtCore.QObject.connect(timer,
49 QtCore.QObject.connect(timer,
36 QtCore.SIGNAL('timeout()'),
50 QtCore.SIGNAL('timeout()'),
51 app,
37 QtCore.SLOT('quit()'))
52 QtCore.SLOT('quit()'))
38 self.timer.start(100)
53 timer.start(100)
39 QtCore.QCoreApplication.exec_()
54 QtCore.QCoreApplication.exec_()
40 timer.stop()
55 timer.stop()
41
56
@@ -76,31 +91,32 b' class InputHookManager(object):'
76 elif hasattr(wx, '_core'): core = getattr(wx, '_core')
91 elif hasattr(wx, '_core'): core = getattr(wx, '_core')
77 else: raise AttributeError('Could not find wx core module')
92 else: raise AttributeError('Could not find wx core module')
78 orig_mainloop = core.PyApp_MainLoop
93 orig_mainloop = core.PyApp_MainLoop
79 core.PyApp_MainLoop = _dummy_mainloop
94 core.PyApp_MainLoop = _DummyMainloop
80 return orig_mainloop
95 return orig_mainloop
81
96
82 def _hijack_qt4(self):
97 def _hijack_qt4(self):
83 """Hijack the qt4 mainloop so a user calling it won't cause badness."""
98 """Hijack the qt4 mainloop so a user calling it won't cause badness."""
84 from PyQt4 import QtGui, QtCore
99 from PyQt4 import QtGui, QtCore
85 orig_mainloop = QtGui.qApp.exec_
100 orig_mainloop = QtGui.qApp.exec_
86 QtGui.qApp.exec_ = _dummy_mainloop
101 dumb_ml = _DummyMainloop(orig_mainloop, self, 'qt4')
87 QtGui.QApplication.exec_ = _dummy_mainloop
102 QtGui.qApp.exec_ = dumb_ml
88 QtCore.QCoreApplication.exec_ = _dummy_mainloop
103 QtGui.QApplication.exec_ = dumb_ml
104 QtCore.QCoreApplication.exec_ = dumb_ml
89 return orig_mainloop
105 return orig_mainloop
90
106
91 def _hijack_gtk(self):
107 def _hijack_gtk(self):
92 """Hijack the gtk mainloop so a user calling it won't cause badness."""
108 """Hijack the gtk mainloop so a user calling it won't cause badness."""
93 import gtk
109 import gtk
94 orig_mainloop = gtk.main
110 orig_mainloop = gtk.main
95 gtk.mainloop = _dummy_mainloop
111 gtk.mainloop = _DummyMainloop
96 gtk.main = _dummy_mainloop
112 gtk.main = _DummyMainloop
97 return orig_mainloop
113 return orig_mainloop
98
114
99 def _hijack_tk(self):
115 def _hijack_tk(self):
100 """Hijack the tk mainloop so a user calling it won't cause badness."""
116 """Hijack the tk mainloop so a user calling it won't cause badness."""
101 import Tkinter
117 import Tkinter
102 Tkinter.Misc.mainloop = _dummy_mainloop
118 Tkinter.Misc.mainloop = _DummyMainloop
103 Tkinter.mainloop = _dummy_mainloop
119 Tkinter.mainloop = _DummyMainloop
104
120
105 def get_pyos_inputhook(self):
121 def get_pyos_inputhook(self):
106 """Return the current PyOS_InputHook as a ctypes.c_void_p."""
122 """Return the current PyOS_InputHook as a ctypes.c_void_p."""
General Comments 0
You need to be logged in to leave comments. Login now