bind wxWidgets with python

I want to add a new window in my existing wxWidgets project that will
bind with python.
I know about wxPython, but i want the opposite way:
Window in wxWidgets that will send it's user input to python and will
show the python's output back to user.
Is it possible? and how do i bind?

If you want to do this the hard way see the following docs to get you
started :

    "Extending C++ Classes with Python"
    http://www.python.org/workshops/1995-12/papers/ahlstrom1.html

    "Extending and Embedding the Python Interpreter"
    Extending and Embedding the Python Interpreter — Python 3.13.0 documentation

However, in a simple situation like yours you could, instead :

a) Kick off a Python script from your wxPython C++ app and have the
script write its results to a file;

b) Have your wxPython C++ poll, via timer, the existence of that data
file and immediately stop the poll timer when it's detected. Read the
contents of the file and then delete it. This is a "poor man's
messaging system" that avoids a great deal of complexity.

Ray

···

On Nov 1, 11:43 am, IceSpy <dns...@gmail.com> wrote:

I want to add a new window in my existing wxWidgets project that will
bind with python.
I know about wxPython, but i want the opposite way:
Window in wxWidgets that will send it's user input to python and will
show the python's output back to user.
Is it possible? and how do i bind?

If you want to do this the hard way see the following docs to get you
started :

     "Extending C++ Classes with Python"
     http://www.python.org/workshops/1995-12/papers/ahlstrom1.html

     "Extending and Embedding the Python Interpreter"
     Extending and Embedding the Python Interpreter — Python 3.13.0 documentation

That's the way to do it you want full-featured scripting.

However, in a simple situation like yours you could, instead :

a) Kick off a Python script from your wxPython C++ app and have the
script write its results to a file;

b) Have your wxPython C++ poll, via timer, the existence of that data
file and immediately stop the poll timer when it's detected. Read the
contents of the file and then delete it. This is a "poor man's
messaging system" that avoids a great deal of complexity.

Or something in between -- kick of a separate python process, and communicate with via sockets or the like. Python has lots of nifty stuff for that kind of thing. A simple http server on localhost might suffice,for instance.

-Chris

···

On 11/1/10 5:18 PM, Ray Pasco wrote:

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

You use Python's C API to have the interpreter run bits of Python code. If you want that code to also have a UI, or to interact with your C++ wx objects then you can have it use wxPython if you make sure that they are both using the same instance of the wxWidgets DLL or shared library. There is an example of this in the wxPython source tree, at wxPython/samples/embedded.

If you don't need the Python code to have a UI then it will be much simpler. You just use Python's API to execute code and fetch the results.

···

On 11/1/10 8:43 AM, IceSpy wrote:

I want to add a new window in my existing wxWidgets project that will
bind with python.
I know about wxPython, but i want the opposite way:
Window in wxWidgets that will send it's user input to python and will
show the python's output back to user.
Is it possible? and how do i bind?

--
Robin Dunn
Software Craftsman