[PySide] Binding unbound signals (need __get__)

Blair Zajac blair at orcaware.com
Fri May 11 03:06:17 CEST 2012

We have some Python decorators that takes signals and we'd like to be 
able to convert a unbound signal into a bound signal.  I don't see a way 
to do this in PySide, as in PyQt4 __get__ works to bind an unbound 
signal.  From my reading, normal python usage lets you bind any method 
using __get__:

class Bar(object):
     def method(self):

bar = Bar()
unbound_method = Bar.method
bound_method = Bar.method.__get__(bar)

Without __get__, the following doesn't work.  Is there a way to do this 
in PySide?


from PyQt4 import QtCore
QtCore.Signal = QtCore.pyqtSignal
QtCore.Slot = QtCore.pyqtSlot

def emit_upon_success(signal):
     def f_(f):
         def f__(self):
             result = f(self)
             s = signal.__get__(self)
             return result
         return f__
     return f_

class Foo(QtCore.QObject):
     SIG = QtCore.Signal()

     def do_something(self):

foo = Foo()

More information about the PySide mailing list