[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Protected methods in unwraped instances
From:       Phil Thompson <phil () riverbankcomputing ! com>
Date:       2010-12-30 14:51:56
Message-ID: de4f2909c39a19be489658e0ce9ddb63 () localhost
[Download RAW message or body]

On Thu, 30 Dec 2010 11:38:22 -0300, Nahuel Defossé
<nahuel.defosse@gmail.com> wrote:
> 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.

That's probably the only way to do it at the moment. I could implement
sip.isderived() easily enough.

Phil
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic