Created
May 6, 2016 12:31
-
-
Save vxgmichel/8e8297fdaab09166f309892b5dd5a814 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt4 import Qt | |
def Signal(name, *args): | |
def get_signal(self): | |
if not hasattr(self, '_signallers'): | |
self._signallers = {} | |
if (name, args) not in self._signallers: | |
signal = Qt.pyqtSignal(*args, name=name) | |
signaller_type = type('Signaller', (Qt.QObject,), {name: signal}) | |
self._signallers[name, args] = signaller_type() | |
signaller = self._signallers[name, args] | |
return getattr(signaller, name) | |
return property(get_signal) | |
class Base(object): | |
test = Signal('test', int) | |
class MyWidget(Qt.QLabel, Base): | |
def __init__(self): | |
Qt.QLabel.__init__(self, 'testing signal') | |
self.test.connect(self.onSignal) | |
self.test.emit(3) | |
def onSignal(self, arg): | |
print "Got:", arg | |
app=Qt.QApplication([]) | |
w = MyWidget() | |
w.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment