Calling a python function from C++ to update a progress display widget

Let's say I have the following in a Python file called progress.py: pbar = gtk.ProgressBar() def updateBar(): pbar.puls() In C++: for ( int i = 0; i < 10; i++ ) // Call the python method updateBar() which is not a member of any class in progress.py How do I do it? I'm aware of the following 2 functions in boost: call<ResultType>(callable_object, a1, a2... aN); call_method<ResultType>(self_object, "method-name", a1, a2... aN); Can I see an example on how to use them? My goal is to display the progress bar widget live while the for loop is counting from 0 to 9.

"Thierry Lam" <lam@pcigeomatics.com> writes: Hi Thierry, In the future, a better place for Boost.Python questions is http://www.boost.org/more/mailing_lists.htm#cplussig
Let's say I have the following in a Python file called progress.py:
pbar = gtk.ProgressBar()
def updateBar():
pbar.puls()
In C++:
// Call the python method updateBar() which is not a member of any class in progress.py
How do I do it?
You need to get ahold of the progress module: python::object progress(( python::handle<>( python::borrowed(PyImport_AddModule("progress"))))); Then you can get the updateBar method: python::object updateBar = progress.attr("updateBar"); Then you can call that: updateBar(); That's the "slick, modern approach." No need to mess around with call<...> and friends. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Thierry Lam