一个简单的python信号槽实现

【如有错误,欢迎指正,拒绝嘴臭】

# -*- coding: utf-8 -*-

class CSignal():
    def __init__(self):
        self.slot = []
    def emit(self, *arg, **kw):
        for pFunc in self.slot:
            pFunc(*arg, **kw)
    def connect(self, cbfunc):
        self.slot.append(cbfunc)

class FuncObj():
    def __init__(self):
        pass
    def test(self, *arg, **kw):
        print 'i am FuncObj!'

def test(*arg, **kw):
    print "i am test", arg, kw

if __name__ == "__main__":
    testSignal = CSignal()
    testSignal.connect(test)

    testOb = FuncObj()
    testSignal.connect(testOb.test)

    testSignal.emit()

 

你可能感兴趣的:(PyQt5,python,qt)