[PyQt] Protected methods in unwraped instances
phil at riverbankcomputing.com
Thu Dec 30 14:51:56 GMT 2010
On Thu, 30 Dec 2010 11:38:22 -0300, Nahuel Defossé
<nahuel.defosse at gmail.com> wrote:
> 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
> be something more clever.
> For example:
> tw = QTabWidget() # Is a PyQt object
> te = QTextEdit()
> sw = tw.parent() # -> <PyQt4.QtGui.QStackedWidget object at 0x93546ec>
> 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 ):
> 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
That's probably the only way to do it at the moment. I could implement
sip.isderived() easily enough.
More information about the PyQt