[PyQt] sip fails with "[CLASSNAME] has not been defined"

Phil Thompson phil at riverbankcomputing.com
Tue May 1 21:37:25 BST 2012


On Tue, 01 May 2012 09:57:38 +0200, tuxor1337 at web.de wrote:
> I think, I can answer my own question. But only with respect to the 
> _reason_ for this behaviour. I have to admit, that I don't like this 
> behaviour:
> 
> The problem is the "namespace ui". Because OnyxDialog is defined in that

> namespace, it has to be referred to as ui::OnyxDialog in 
> "message_dialog.sip", even though it's being referred to in the very 
> same namespace.
> 
> What I don't like about that revelation: It seems like there is no way 
> to teach SIP to cut off the "ui" from the namespace. In Python, I will 
> always have to refer to the classes via PyOnyx.ui.ui.MessageDialog. Of 
> course, that alone is not the problem. But the problem is, that I can do

> things like "from PyOnyx.ui import ui", but not something like "from 
> PyOnyx.ui.ui import *". And later, when I have a namespace called "sys",

> this is even going to conflict with the Python module of the same name.
> 
> I would love to have a module called "PyOnyx.ui" and the classes 
> "MessageDialog" and "OnyxDialog" as direct parts of that module. Is 
> there any possibility to achieve this with SIP 4.12.2?

You use SIP to describe the bindings you want to create - this is not
necessarily the same as the API of the underlying library. In other words
you don't teach SIP to cut off the "ui" from the namespace, just don't tell
it about it in the first place. The issue then is to make sure that the
generated code compiles - probably by including appropriate "using"
statements in the right places. Take a look at the use of the
%UnitPostIncludeCode directive in the PyQtMobility bindings.

Phil


More information about the PyQt mailing list