[C++-sig] pyplusplus tutorials & GUI wizard

Matthias Baas baas at ira.uka.de
Mon Feb 13 15:18:18 CET 2006


Roman Yakovenko wrote:
>> The spam() method returns a float value that is stored inside the class.
>> For the Python bindings I'd like to ignore the first version that
>> returns the reference. What is the recommended way to do this?
> 
> pygccxml.declarations package has type traits. Their functionality is
> very similar to
> boost.type_traits.
> 
> #f is declaration of function spam
> 
> if pygccxml.declarations.is_reference( f.return_type ):
>     if pygccxml.declarations.is_floating_point( f.return_type.base ):
>         pass#do your things
> 
> [...]
> 
>> Is there a convenience function that can easily check if a declaration
>> actually represents a method "float& Foo::spam(int)" or do I really have
>> to inspect every little detail myself (i.e. check if the name of the
>> [...]
> 
> There is no such convenience method :-(. But you don't have to check
> every little detail. [...]

The above 'if' statements are already what I meant by "checking every 
detail". ;) But meanwhile I had a closer look at pygccxml and now I have 
my own convenience functions based on using the decl_string attribute as 
I found it much more convenient to specify these things via strings. For 
example, in my script it would now look like this:

   Foo = Class("Foo")
   ignore( find_method(Foo, "spam", retval="float &") )

>> Then I have two more questions:
>>
>> - How do you add new methods to a (Python) class? In my case, I want to
>> wrap a class whose Python version should have an additional static
>> method (which I'd like to implement as a C++ function).
> 
> Best way is to use custom_text_t code creator. Just put it somewhere
> within relevant code creator. Take a look on boost.date_time
> pyplusplus example. I use it there.

I saw that custom_text_t classes are used in that example, but it seems 
I'd have to inspect the pyplusplus sources before I'll understand all of 
that...

Currently, I have wrapped about 170 classes, but now I've also a problem 
with the registration order which means I cannot use the bindings for 
the moment. I've seen in another thread that this has been an issue for 
another project as well. But I haven't yet seen how I can change the 
order of the registrations. By the way, are you still trying to figure 
out a working order automatically or are you going to provide a back 
door for the user to influence the order manually?

- Matthias -




More information about the Cplusplus-sig mailing list