Show More
@@ -9,8 +9,12 b' import wx' | |||||
9 |
|
9 | |||
10 |
|
10 | |||
11 | def ignore_keyboardinterrupts(func): |
|
11 | def ignore_keyboardinterrupts(func): | |
12 | """Decorator which causes KeyboardInterrupt exceptions to be |
|
12 | """Decorator which causes KeyboardInterrupt exceptions to be ignored during | |
13 |
|
|
13 | execution of the decorated function. | |
|
14 | ||||
|
15 | This is used by the inputhook functions to handle the event where the user | |||
|
16 | presses CTRL+C while IPython is idle, and the inputhook loop is running. In | |||
|
17 | this case, we want to ignore interrupts. | |||
14 | """ |
|
18 | """ | |
15 | def wrapper(*args, **kwargs): |
|
19 | def wrapper(*args, **kwargs): | |
16 | try: |
|
20 | try: | |
@@ -159,34 +163,34 b' def inputhook_wxphoenix(context):' | |||||
159 | if app is None: |
|
163 | if app is None: | |
160 | return |
|
164 | return | |
161 |
|
165 | |||
|
166 | if context.input_is_ready(): | |||
|
167 | return | |||
|
168 | ||||
|
169 | assert wx.IsMainThread() | |||
|
170 | ||||
162 |
|
|
171 | # Wx uses milliseconds | |
163 | poll_interval = 100 |
|
172 | poll_interval = 100 | |
164 |
|
173 | |||
165 | # This function gets polled periodically; when |
|
174 | # We have to create a dummy wx.Frame, otherwise wx.App.MainLoop will know | |
166 | # input is ready, the wx main loop is stopped. |
|
175 | # that it has nothing to do, and will return immediately. | |
167 | def wake(): |
|
176 | frame = getattr(inputhook_wxphoenix, '_frame', None) | |
|
177 | if frame is None: | |||
|
178 | inputhook_wxphoenix._frame = frame = wx.Frame(None) | |||
|
179 | frame.Show(False) | |||
|
180 | ||||
|
181 | # Use a wx.Timer to periodically check whether input is ready - as soon as | |||
|
182 | # it is, we exit the main loop | |||
|
183 | def poll(ev): | |||
168 | if context.input_is_ready(): |
|
184 | if context.input_is_ready(): | |
169 | app.ExitMainLoop() |
|
185 | app.ExitMainLoop() | |
170 |
|
186 | |||
171 | # We have to put the wx.Timer in a wx.Frame for it to fire properly. |
|
187 | timer = wx.Timer() | |
172 | # We make the Frame hidden when we create it in the main app below. |
|
188 | timer.Start(poll_interval) | |
173 | class TimerFrame(wx.Frame): |
|
189 | timer.Bind(wx.EVT_TIMER, poll) | |
174 | def __init__(self, func): |
|
|||
175 | wx.Frame.__init__(self, None, -1) |
|
|||
176 | self.timer = wx.Timer(self) |
|
|||
177 | self.timer.Start(poll_interval) |
|
|||
178 | self.Bind(wx.EVT_TIMER, self.on_timer) |
|
|||
179 | self.func = func |
|
|||
180 |
|
190 | |||
181 | def on_timer(self, event): |
|
191 | # The import of wx on Linux sets the handler for signal.SIGINT to 0. This | |
182 | self.func() |
|
192 | # is a bug in wx or gtk. We fix by just setting it back to the Python | |
183 |
|
193 | # default. | ||
184 | frame = TimerFrame(wake) |
|
|||
185 | frame.Show(False) |
|
|||
186 |
|
||||
187 | # The import of wx on Linux sets the handler for signal.SIGINT |
|
|||
188 | # to 0. This is a bug in wx or gtk. We fix by just setting it |
|
|||
189 | # back to the Python default. |
|
|||
190 | if not callable(signal.getsignal(signal.SIGINT)): |
|
194 | if not callable(signal.getsignal(signal.SIGINT)): | |
191 | signal.signal(signal.SIGINT, signal.default_int_handler) |
|
195 | signal.signal(signal.SIGINT, signal.default_int_handler) | |
192 |
|
196 | |||
@@ -195,6 +199,7 b' def inputhook_wxphoenix(context):' | |||||
195 |
|
199 | |||
196 | # Get the major wx version number to figure out what input hook we should use. |
|
200 | # Get the major wx version number to figure out what input hook we should use. | |
197 | major_version = 3 |
|
201 | major_version = 3 | |
|
202 | ||||
198 | try: |
|
203 | try: | |
199 | major_version = int(wx.__version__[0]) |
|
204 | major_version = int(wx.__version__[0]) | |
200 | except Exception: |
|
205 | except Exception: |
General Comments 0
You need to be logged in to leave comments.
Login now