[PyKDE] Blocking signals

Boudewijn Rempt bsarempt at xs4all.nl
Mon May 14 22:13:02 BST 2001


Is it possible to use QObject.blockSignals() for Python signals? I can't
really figure out whether blockSignals is meant to block outgoing or
incoming signals, but whatever I try, nothing happens. Has anyone ever
used blockSignals usefully? (Or disconnect() for that matter?)


This is an adapted version of my previous script:

#
# qobject.py = connect, disconnect and block signals
#
import sys
from qt import *

class EmittingObject(QObject):

    def __init__(self, *args):
        apply(QObject.__init__, (self, ) + args)
        self.counter=0
        self.timer = self.startTimer(100)
        
    def timerEvent(self, ev):
        self.counter+=1
        self.emit(PYSIGNAL("timeSignal"), (self.counter,))

        if self.counter == 20:
            self.blockSignals(1)

        if self.counter == 25:
            self.blockSignals(0)

        if self.counter == 30:
            self.killTimer(self.timer)

    def disconnectNotify(self, signal):
       print "disconnected: ", signal

    def connectNotify(self, signal):
        print "something connected to", signal

class ReceivingObject(QObject):

    def __init__(self, *args):
        apply(QObject.__init__, (self, ) + args)

    def slotTimeSignal(self, count):
        print count
        if count == 10:
            self.blockSignals(1)
            
        if count == 20:
            self.emit(PYSIGNAL("timeUp"), ())
            
            
class AppObject(QApplication):

    def __init__(self, *args):
        apply(QApplication.__init__, (self, ) + args)
        
        self.emitter=EmittingObject(self)
        self.receiver=ReceivingObject(self)

        QObject.connect(self.emitter, PYSIGNAL("timeSignal"),
self.receiver.slotTimeSignal)
        QObject.connect(self.receiver, PYSIGNAL("timeUp"),
self.slotDisconnect)

        QObject.connect(self.receiver, SIGNAL("destroyed()"), self,
SLOT("quit()"))
        QObject.disconnect(self.receiver, SIGNAL("destroyed()"), self,
SLOT("quit()"))

    def slotDisconnect(self):
        self.disconnect(self.emitter,
                        PYSIGNAL("timeSignal"),
                        self.receiver,
                        self.receiver.slotTimeSignal)

def main(args):
    app=AppObject(args)
    app.exec_loop()


if __name__=="__main__":
    main(sys.argv)







More information about the PyQt mailing list