Linux-Signal VS QT
Phil Thompson
phil at riverbankcomputing.co.uk
Thu Feb 8 10:35:33 EST 2007
On Thursday 08 February 2007 3:08 pm, Marco wrote:
> Can I use LinuX signal as a tool for commuction with a QT(PyQt4) programme?
>
> The follow code didNOT work...
>
>
> from PyQt4 import QtCore,QtGui
> import signal
> import sys
> import os
>
> try:
> import psyco
> psyco.full()
> except:
> pass
>
> class Main(QtGui.QWidget):
> def __init__(self):
> QtGui.QWidget.__init__(self)
>
> self.frame = QtGui.QFrame(self)
> self.label = QtGui.QLabel(str(os.getpid()), self.frame)
> signal.signal(15, self.sig_handler)
> print signal.getsignal(15)
>
> def sig_handler(self, signum, sframe):
> print 'received!'
> self.label.setText('haha')
> self.show()
>
> ########################
> # main routine #
> ########################
> if __name__ == '__main__':
> app = QtGui.QApplication(sys.argv)
>
> main = Main()
> main.show()
> app.exec_()
The problem is that Python only delivers the signal when the interpreter is
running but your program is sat in the Qt event loop. You need to force Qt to
hand back to the interpreter from time to time.
The easiest way is to use the object timer. Add "self.startTimer(500)" to your
__init__() method and add the following dummy timer event handler...
def timerEvent(self, e):
pass
Phil
More information about the Python-list
mailing list