Listening to changes in a C++ variable from python

2005-05-06 Thread lamthierry
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?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Listening to changes in a C++ variable from python

2005-05-07 Thread lamthierry
Is there some python method which can do the polling you are talking
about? Or can you send me a link to some existing example?

> 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++.

-- 
http://mail.python.org/mailman/listinfo/python-list


Calling a python function from C++

2005-05-08 Thread lamthierry
Let's say I have a python function do some math like the following:

def doMath(self):
   self.val = self.val + 1


How can I call this python function from C++? Assuming I have some sort
of Python wrapper around my C++ codes.

-- 
http://mail.python.org/mailman/listinfo/python-list


Declaring self in PyObject_CallMethod

2005-05-08 Thread lamthierry
Calling a python method from C++ has the following signature:

PyObject *
PyObject_CallMethod(PyObject *self, char *method_name,
char *arg_format, ...);

I'm having trouble figuring out how to declare self.

Let's say my python file is called stuff.py and is like the following,
doMath() is defined in stuff.py and is not part of any class:

#stuff.py

def doMath():
   val = val + 1


In C++, I think my codes should be like the following:

PyObject *resultObj = PyObject_CallMethod( self, "doMath", "");

What do I put for self? Any help please?

-- 
http://mail.python.org/mailman/listinfo/python-list


GTK progress bar not working properly with pulse()

2005-05-09 Thread lamthierry
My python file(progressbar.py) looks like the following:

pbar = gtk.ProgressBar()

def updateBar(percentage):
print percentage
pbar.pulse()

class ProgressBar:
def __init__(self):
# other gui codes

align.add(pbar)
pbar.show()

My C++ codes look like the following:

for ( int percent = 0; percent < 100; percent++ )
{
PyObject* importModule = PyImport_ImportModule("progressbar");

if ( importModule == NULL )
printf("not good\n");
PyObject* callResult = PyObject_CallMethod(importModule,
"updateBar", "i", percent, NULL);
if ( callResult == NULL )
printf("not good enough\n");

Py_XDECREF(importModule);
}

I run the above C++ code from python by clicking a button. The problem
is that when I print the percentage from the python side, it works
fine, but when I call the pulse() method for ProgressBar, nothing gets
updated on my GUI. Do I have to do anything else with the pbar object
to make it display properly?

-- 
http://mail.python.org/mailman/listinfo/python-list