[PyQt] QxtSignalWaiter

Jason Hihn jason at eyemaginations.com
Sun Jul 29 19:40:58 BST 2007


Not completely 100% compatible,  but here you all go.

 

------

from PyQt4.Qt import * 

 

class QxtSignalWaiter(QObject):

            def __init__(self, sender, signal):

                        apply(QObject.__init__, (self, ) + ())

                        self.connect(sender, SIGNAL(signal),
self.signalCaught)

                        

            def waitFor(self, sender, signal, msec):

                        '''Returns True if the signal was caught, returns
False if the wait timed out'''

                        w=QxtSignalWaiter(sender, signal)

                        return w.waitUpTo(msec)

 

            def waitUpTo(self, msec):

                        ''' Returns True if the signal was caught, returns
False if the wait timed out'''

                        if(msec < -1): 

                                    return False

                        

                        if(msec != -1): 

                                    self.timerID = self.startTimer(msec)

                        

                        self.ready = self.timeout = False

                        while(self.ready==False and self.timeout==False):

 
QCoreApplication.processEvents(QEventLoop.WaitForMoreEvents)

                        

                        self.killTimer(self.timerID)

                        return self.ready or self.timeout

                        

            def signalCaught(self):                

                        self.ready = True

 

            def timerEvent(self, event):

                        self.killTimer(self.timerID)

                        self.timeout = True

 

 

if __name__=='__main__':

            def done(int):

                        print 'done(%s)' % int

            import sys

            a=QApplication(sys.argv)

            http=QHttp('google.com')

            w=QxtSignalWaiter(http, 'done(bool)')                  

            QObject.connect(http, SIGNAL('done(bool)'), done)


            http.get("/")

            w.waitUpTo(5000)

            

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20070729/2a2a4c8b/attachment.html


More information about the PyQt mailing list