[PyQt] Protected methods in unwraped instances

Nahuel Defossé nahuel.defosse at gmail.com
Thu Dec 30 14:38:22 GMT 2010


Hi,

is there some way to detect weather a widget has been created from
Python (I belive through sip in the internals) and when it's been
created in C++.
I've come up with a very nasty solution that consists in checking for
a protected method and catching the RuntimeError. But I belive there
must
be something more clever.

For example:
tw = QTabWidget() # Is a PyQt object
te = QTextEdit()
tw.addWidget(te)
sw = tw.parent() # -> <PyQt4.QtGui.QStackedWidget object at 0x93546ec>
sw.receivers(SIGNAL('x()'))

RuntimeError: no access to protected functions or signals for objects
not created from Python

So, we came up with this code:
def is_sip_wrapped( foo ):
    try:
        foo.sender()
    except RunitmeError:
        return False
    return True

And do not feel comfortable with it at all, but it works. I guess
someone there could add some extra information about this detection.

Though I can perfectly call receivers for any other widget created in Python.


Thanks


More information about the PyQt mailing list