Run the wx event loop until the user provides more input. This input hook is suitable for use with wxPython >= 4 (a.k.a. Phoenix). It uses the same approach to that used in ipykernel.eventloops.loop_wx. The wx.MainLoop is executed, and a wx.Timer is used to periodically poll the co
(context)
| 152 | |
| 153 | @ignore_keyboardinterrupts |
| 154 | def inputhook_wxphoenix(context): |
| 155 | """Run the wx event loop until the user provides more input. |
| 156 | |
| 157 | This input hook is suitable for use with wxPython >= 4 (a.k.a. Phoenix). |
| 158 | |
| 159 | It uses the same approach to that used in |
| 160 | ipykernel.eventloops.loop_wx. The wx.MainLoop is executed, and a wx.Timer |
| 161 | is used to periodically poll the context for input. As soon as input is |
| 162 | ready, the wx.MainLoop is stopped. |
| 163 | """ |
| 164 | |
| 165 | app = wx.GetApp() |
| 166 | |
| 167 | if app is None: |
| 168 | return |
| 169 | |
| 170 | if context.input_is_ready(): |
| 171 | return |
| 172 | |
| 173 | assert wx.IsMainThread() |
| 174 | |
| 175 | # Wx uses milliseconds |
| 176 | poll_interval = 100 |
| 177 | |
| 178 | # Use a wx.Timer to periodically check whether input is ready - as soon as |
| 179 | # it is, we exit the main loop |
| 180 | timer = wx.Timer() |
| 181 | |
| 182 | def poll(ev): |
| 183 | if context.input_is_ready(): |
| 184 | timer.Stop() |
| 185 | app.ExitMainLoop() |
| 186 | |
| 187 | timer.Start(poll_interval) |
| 188 | timer.Bind(wx.EVT_TIMER, poll) |
| 189 | |
| 190 | # The import of wx on Linux sets the handler for signal.SIGINT to 0. This |
| 191 | # is a bug in wx or gtk. We fix by just setting it back to the Python |
| 192 | # default. |
| 193 | if not callable(signal.getsignal(signal.SIGINT)): |
| 194 | signal.signal(signal.SIGINT, signal.default_int_handler) |
| 195 | |
| 196 | # The SetExitOnFrameDelete call allows us to run the wx mainloop without |
| 197 | # having a frame open. |
| 198 | app.SetExitOnFrameDelete(False) |
| 199 | app.MainLoop() |
| 200 | |
| 201 | |
| 202 | # Get the major wx version number to figure out what input hook we should use. |
nothing calls this directly
no outgoing calls
no test coverage detected