[wxpython-users] Access wxWidgets C++ application from embedded
Python shell
Robin Dunn
robin at alldunn.com
Mon Mar 24 10:59:30 PDT 2008
Christoph Schmidt-Hieber wrote:
> 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,
Yes, this is the correct approach to take although writing the extension
module code by hand would be possible too.
> 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. As far as Python is concerned there will be no difference
between that and a normal import. SWIG will also generate a .py file
that your other python code can import, so you just need to make sure
that it can be found on the sys.path.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list