##// END OF EJS Templates
RF: Clean up wxphoenix input hook.
Paul McCarthy -
Show More
@@ -9,8 +9,12 b' import wx'
9 9
10 10
11 11 def ignore_keyboardinterrupts(func):
12 """Decorator which causes KeyboardInterrupt exceptions to be
13 ignored during execution of the decorated function.
12 """Decorator which causes KeyboardInterrupt exceptions to be ignored during
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 19 def wrapper(*args, **kwargs):
16 20 try:
@@ -159,34 +163,34 b' def inputhook_wxphoenix(context):'
159 163 if app is None:
160 164 return
161 165
162 # Wx uses milliseconds
166 if context.input_is_ready():
167 return
168
169 assert wx.IsMainThread()
170
171 # Wx uses milliseconds
163 172 poll_interval = 100
164 173
165 # This function gets polled periodically; when
166 # input is ready, the wx main loop is stopped.
167 def wake():
174 # We have to create a dummy wx.Frame, otherwise wx.App.MainLoop will know
175 # that it has nothing to do, and will return immediately.
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 184 if context.input_is_ready():
169 185 app.ExitMainLoop()
170 186
171 # We have to put the wx.Timer in a wx.Frame for it to fire properly.
172 # We make the Frame hidden when we create it in the main app below.
173 class TimerFrame(wx.Frame):
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
181 def on_timer(self, event):
182 self.func()
183
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.
187 timer = wx.Timer()
188 timer.Start(poll_interval)
189 timer.Bind(wx.EVT_TIMER, poll)
190
191 # The import of wx on Linux sets the handler for signal.SIGINT to 0. This
192 # is a bug in wx or gtk. We fix by just setting it back to the Python
193 # default.
190 194 if not callable(signal.getsignal(signal.SIGINT)):
191 195 signal.signal(signal.SIGINT, signal.default_int_handler)
192 196
@@ -195,6 +199,7 b' def inputhook_wxphoenix(context):'
195 199
196 200 # Get the major wx version number to figure out what input hook we should use.
197 201 major_version = 3
202
198 203 try:
199 204 major_version = int(wx.__version__[0])
200 205 except Exception:
General Comments 0
You need to be logged in to leave comments. Login now