Hi,
I've embbeded a python shell (wx.py.shell.Shell) in my wxWidgets C++ application according to the suggestions in the "embedded" sample. I'm now wondering if it's possible to directly access some of the C++ application's functions from this embedded shell. As an example, would it be possible to call MyFrame::OnAbout (or any other function) from the python shell in the "embedded" sample application? I was thinking to expose the C++ interface to python with swig and to import the resulting module from the embedded shell, but I would then need to somehow "attach" the running application to this module.
Any help and suggestions would be greatly appreciated,
Christoph
Robin Dunn wrote:
Christoph Schmidt-Hieber wrote:
I was thinking to expose the C++ interface to python with swig and to import the resulting module from the embedded shell,
Yes, this is the correct approach to take although writing the extension module code by hand would be possible too.
I'm profoundly distrusting my reference counting skills, so I'd largely prefer swig does this job.
but I would then need to somehow "attach" the running application to this module.
Instead of making it a standalone extension module you can just link it into your application, and then after you've initialized Python you can just call the module's init function, and that will do the initial import.
Thank you very much, works perfectly. You saved me a lot of work. Seems embarassingly easy to do, now that you explained it. In return, I would be happy to provide an example for the embedded sample if you think this might be of use to to other people.
Christoph