[PyQt] sip: Can I map a C++ namespace to another name in the
python bindings?
Phil Thompson
phil at riverbankcomputing.com
Fri Jul 3 16:21:08 BST 2009
On Wed, 1 Jul 2009 11:31:21 +0200, "Jakob Simon-Gaarde" <sip at skolesys.dk>
wrote:
> I have a large C++ library where all classes are implemented under one
> namespace called CAPA. I ask sip to generate bindings for these classes
> under
> a single module called pycapa. So when I generate my bindings the
resulting
>
> classes will be defined under pycapa.CAPA.SomeClass.
>
> I would like to split the C++ namespace up into several python
namespaces.
> so
> that I can group the classes and in the same module with multiple python
> namespaces. ie.
>
> C++ class | python mapped class
> ------------------------------------------------
> CAPA::Session | pycapa.session.Session
> CAPA::LoginParam | pycapa.session.LoginParam
> CAPA::LoginResult | pycapa.session.LoginResult
> ... etc
>
> C++ class | python mapped class
> ------------------------------------------------
> CAPA::UserService | pycapa.userservice.UserService
> CAPA::CreateUserParam | pycapa.userservice.CreateUserParam
> CAPA::CreateUserResult | pycapa.userservice.CreateUserResult
> ... etc
>
> There are some problems with this approach, cause python namespaces
resolve
> to
> python classes, so I can't write: from pycapa.session import *, or like
it
> is
> now with no namespace mapping:
>
>>>> from pycapa.CAPA import *
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ImportError: No module named CAPA
>
> Alternatively I'd like to remove the namespace in the resulting python
> bindings and then make several modules like, pycapa_session
> pycapa_userservice
> etc.
I think the easiest thing to do is to create a set of wrapper Python
modules that import the SIP generated classes into the structure you want.
You should be able to automate the creation of the wrappers.
Phil
More information about the PyQt
mailing list