Open AndySomogyi opened 5 years ago
I'm currently digging through the both the Python 3.7 and ipython source.
It looks like PyOS_InputHook
is only called from the readline
module, and nowhere else.
IPython, as of version 5.? no longer uses readline
, rather, it uses it's own prompt_toolkit
which does NOT call PyOS_InputHook
.
Newer version is python now have their own input hook
system, and a number of input hook backends in pt_inputhooks
package.
I'm currently studying these to see how they work.
It looks like I could write a module (in C) that calls the various glfw poll / dispatch events functions I need, and expose them as python methods, that I could then call from a my own input hook backend.
ipykernel also has some integration with the mac eventloop, which you can call via ctypes if your interactions are simple enough. Calling objc from Python via ctypes isn't the simplest, though!
I'm writing a library (C++ with Python API) that needs to open OpenGL windows, and display interactive content there.
I want users to be able to invoke this lib directly from the ipython interactive console, have it open a few windows, return AND then continue listening for user input at the console. Effectively, I want the user experience to be like:
I've just started reading up on the
C
PyOS_InputHook
routine, and this looks like the PERFECT way to hook up my own GUI event processing. Is there any issues using this with ipython interactive terminal?But it looks like the
IPython.lib.inputhook
module has been deprecated. What has replaced this? Could you point me to some examples / docs where interactive GUI toolkits have installed their own message loop, preferably via theC
PyOS_InputHook
routine.https://ipython.readthedocs.io/en/stable/api/generated/IPython.lib.inputhook.html
On Mac OSX, the message loop MUST BE ON THE MAIN THREAD. I've written a Mac message loop, looks something like:
What I could do, is on the
C
side, create some Python wrapper functions for the[NSApplication ... nextEventMatchingMask
and[NSApplication sendEvent:event]
calls, and then tie these into a custom main loop in python that combines the existing ipython interactive terminal with these window handling message calls.So, my question is how can I integrate the Mac window GUI message loop with the ipython interactive terminal main loop? Is is possible to override the ipython interactive terminal main loop? Could you point me towards the source where it's at?
Ideally, I'd like to do so method like this:
Then my installHooks method would find the ipython interactive terminal main loop, either hook into it override it with with my own loop which invokes the two Cocoa GUI message handling routines.