##// END OF EJS Templates
Added an improved mainloop manager....
Fernando Perez -
Show More
@@ -22,20 +22,35 b' import sys'
22 22 # Code
23 23 #-----------------------------------------------------------------------------
24 24
25 def _dummy_mainloop(*args, **kw):
26 pass
25 class _DummyMainloop(object):
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 43 def spin_qt4():
30 44 from PyQt4 import QtCore, QtGui
31 45
32 app = QtCore.QCoreApplication.instance()
33 if app is not None and app.thread == QtCore.QThread.currentThread():
46 app = QtCore.QCoreApplication.instance()
47 if (app is not None) and (app.thread() == QtCore.QThread.currentThread()):
34 48 timer = QtCore.QTimer()
35 49 QtCore.QObject.connect(timer,
36 50 QtCore.SIGNAL('timeout()'),
51 app,
37 52 QtCore.SLOT('quit()'))
38 self.timer.start(100)
53 timer.start(100)
39 54 QtCore.QCoreApplication.exec_()
40 55 timer.stop()
41 56
@@ -76,31 +91,32 b' class InputHookManager(object):'
76 91 elif hasattr(wx, '_core'): core = getattr(wx, '_core')
77 92 else: raise AttributeError('Could not find wx core module')
78 93 orig_mainloop = core.PyApp_MainLoop
79 core.PyApp_MainLoop = _dummy_mainloop
94 core.PyApp_MainLoop = _DummyMainloop
80 95 return orig_mainloop
81 96
82 97 def _hijack_qt4(self):
83 98 """Hijack the qt4 mainloop so a user calling it won't cause badness."""
84 99 from PyQt4 import QtGui, QtCore
85 100 orig_mainloop = QtGui.qApp.exec_
86 QtGui.qApp.exec_ = _dummy_mainloop
87 QtGui.QApplication.exec_ = _dummy_mainloop
88 QtCore.QCoreApplication.exec_ = _dummy_mainloop
101 dumb_ml = _DummyMainloop(orig_mainloop, self, 'qt4')
102 QtGui.qApp.exec_ = dumb_ml
103 QtGui.QApplication.exec_ = dumb_ml
104 QtCore.QCoreApplication.exec_ = dumb_ml
89 105 return orig_mainloop
90 106
91 107 def _hijack_gtk(self):
92 108 """Hijack the gtk mainloop so a user calling it won't cause badness."""
93 109 import gtk
94 110 orig_mainloop = gtk.main
95 gtk.mainloop = _dummy_mainloop
96 gtk.main = _dummy_mainloop
111 gtk.mainloop = _DummyMainloop
112 gtk.main = _DummyMainloop
97 113 return orig_mainloop
98 114
99 115 def _hijack_tk(self):
100 116 """Hijack the tk mainloop so a user calling it won't cause badness."""
101 117 import Tkinter
102 Tkinter.Misc.mainloop = _dummy_mainloop
103 Tkinter.mainloop = _dummy_mainloop
118 Tkinter.Misc.mainloop = _DummyMainloop
119 Tkinter.mainloop = _DummyMainloop
104 120
105 121 def get_pyos_inputhook(self):
106 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