[C++-sig] Opening up a main window asynchronously

Gazihan Alankus gazihan at cse.wustl.edu
Thu Sep 20 11:49:12 CEST 2007


I'm about to create python extensions (or whatever I should be calling it)
in my simulation application for ease of use, for eliminating the
edit-compile-run killer loop. I know in the worst case I could embed python
in my application and run it by giving it a script file, but I could really
use an interactive approach where I do things step by step on the python
interpreter and immediately see results and continue.

I once used the mex interface in matlab and I remember it used to handle
everything itself. It would make my application(library) think that it is
running by itself while at the same time letting me call its functions. It
would be great if I could do something like that with Boost.Python.

At this point I could really use some feedback for my design. Here is what I
want in the end and I don't know if it is possible at all:

* run python
* import the python module that I made using Boost.Python
* run open_mainwindow()
-> this should open a main window that is constantly redrawn and interactive
-> but the call to open_mainwindow() should return in the python interprener
* make many different calls that adds-removes-manipulates the things in the
* have python objects that resemble the things in the simulation. I should
be able to use those python objects to manipulate things in the simulation.

If I could do this straight by exposing classes with Boost.Python, that
would be lovely. However, I realize that the window needs to have a main
loop - or at least something that frequently calls its process_events()
function. Now I'm speculating that there can be a couple of ways this might
be done:

1. make the open_mainwindow() call spawn a thread in c++ for the mainwindow
main loop:
I don't know how nice this would be, I'm afraid of losing grip of the thread
somehow. And I don't know if python will be happy with that thread possibly
changing the python objects about the simulation entities that python

2. make a python thread: 
I don't know how to use them yet, I heard they are not what I expect. Maybe
that python thread could keep calling my window's process_events() and
everyone would be happy. or not, because maybe it will slow down the

3. call things like process_events() from the python interpreter myself.
make the python interpreter block while really doing something on the main
window. something like window.take_control(), and click on something on the
window to give it back to the interpreter.

4. make only an interface library with Boost.Python, make the real
application a separate process and make the interface talk to it via
sockets or something. 

I know that 4 would work for sure and 3 will probably work, but I really
would love a solution like 1, or maybe 2. Any eperienced C++/Python hybrid
developers that can lead me in the right direction? 

Thank you.


More information about the Cplusplus-sig mailing list