Show More
@@ -137,11 +137,66 b' def inputhook_wx3(context):' | |||
|
137 | 137 | pass |
|
138 | 138 | return 0 |
|
139 | 139 | |
|
140 | ||
|
141 | def inputhook_wxphoenix(context): | |
|
142 | """Run the wx event loop by processing pending events only. | |
|
143 | ||
|
144 | This is equivalent to inputhook_wx3, but has been updated to work with | |
|
145 | wxPython Phoenix. | |
|
146 | """ | |
|
147 | ||
|
148 | # See inputhook_wx3 for in-line comments. | |
|
149 | try: | |
|
150 | app = wx.GetApp() | |
|
151 | if app is not None: | |
|
152 | assert wx.IsMainThread() | |
|
153 | ||
|
154 | if not callable(signal.getsignal(signal.SIGINT)): | |
|
155 | signal.signal(signal.SIGINT, signal.default_int_handler) | |
|
156 | ||
|
157 | evtloop = wx.GUIEventLoop() | |
|
158 | ea = wx.EventLoopActivator(evtloop) | |
|
159 | t = clock() | |
|
160 | while not context.input_is_ready(): | |
|
161 | while evtloop.Pending(): | |
|
162 | t = clock() | |
|
163 | evtloop.Dispatch() | |
|
164 | ||
|
165 | # Not all events will be procesed by Dispatch - | |
|
166 | # we have to call ProcessPendingEvents as well | |
|
167 | # to ensure that all events get processed. | |
|
168 | app.ProcessPendingEvents() | |
|
169 | evtloop.ProcessIdle() | |
|
170 | ||
|
171 | used_time = clock() - t | |
|
172 | ||
|
173 | if used_time > 10.0: | |
|
174 | time.sleep(1.0) | |
|
175 | elif used_time > 0.1: | |
|
176 | time.sleep(0.05) | |
|
177 | else: | |
|
178 | time.sleep(0.001) | |
|
179 | del ea | |
|
180 | except KeyboardInterrupt: | |
|
181 | pass | |
|
182 | return 0 | |
|
183 | ||
|
184 | ||
|
140 | 185 | if sys.platform == 'darwin': |
|
141 | 186 | # On OSX, evtloop.Pending() always returns True, regardless of there being |
|
142 | 187 | # any events pending. As such we can't use implementations 1 or 3 of the |
|
143 | 188 | # inputhook as those depend on a pending/dispatch loop. |
|
144 | 189 | inputhook = inputhook_wx2 |
|
145 | 190 | else: |
|
146 | # This is our default implementation | |
|
147 | inputhook = inputhook_wx3 | |
|
191 | ||
|
192 | # Get the major wx version number | |
|
193 | if hasattr(wx, '__version__'): | |
|
194 | major_version = wx.__version__[0] | |
|
195 | else: | |
|
196 | major_version = '3' | |
|
197 | ||
|
198 | # Use the phoenix hook for wxpython >= 4 | |
|
199 | if int(major_version) >= 4: | |
|
200 | inputhook = inputhook_wxphoenix | |
|
201 | else: | |
|
202 | inputhook = inputhook_wx3 |
General Comments 0
You need to be logged in to leave comments.
Login now