Listening to changes in a C++ variable from python

Jeremy Bowers jerf at jerf.org
Sat May 7 00:45:41 EDT 2005


On Fri, 06 May 2005 19:56:34 -0700, lamthierry wrote:

> Let's say I have the following source code in C++:
> 
> // The following is in a .cpp file
> 
> int val = 0;
> for ( int i = 0; i < 10; i++ )
>    val = i;
> 
> 
> // Now I'm in a python GUI, glade or GTK
> Is it possible from the GUI side to listen to changes in the val
> variable? Once I notice a change in the variable, I will update a
> widget(for example a display progress bar from glade). Any advice or
> solutions?

It is not possible to "listen" to something that is not "emitting" change
notifications. Your variable "val" isn't "talking".

Some languages let you listen to every variable, but that is because
behind the scenes it is emitting every variable change as an event.

In C++, in keeping with its general philosophy, it is not going to be
possible to listen to an "int". You must either poll it, or wrap that int
in something that *will* emit change messages in some fashion that
satisfies you. Given the circumstance of updating a progress bar, I'd poll
it about every quarter to half second.

The correct answer changes depending on what you are doing with the info
and the level of control you exert over the source C++.




More information about the Python-list mailing list