The answer is:<br>Just read carefully about QEvent and QCoreApplication.postEvent and you've know that there is no need to use QWaitCondition at all in this case.<br><br><div class="gmail_quote">On Tue, Dec 1, 2009 at 10:15 PM, Ruslan Popov <span dir="ltr"><<a href="mailto:ruslan.popov@gmail.com">ruslan.popov@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi, all.<br><br>I am working on a part of application, the app needs to read RFID id from label, RFID reader is accessible via COM port (I've used pyserial for that).<br>
<br>I have tried to do so:<br><br>[main code]<br>
class MainWindow(QMainWindow):<br><br>Â Â Â def __init__(self, parent=None):<br>Â Â Â Â Â Â Â QMainWindow.__init__(self, parent)<br><br>Â Â Â Â Â Â Â self.rfidReader = QWaitCondition()<br>Â Â Â Â Â Â Â self.rfidWaiter = QWaitCondition()<br>
       self.rfidMutex = QMutex()<br>
       self.callback = self.readedRFID<br>       self.reader = WaitingRFID(self)<br>       self.reader.start()<br><br>..<br><br>   def waitingRFID(self):<br>       self.rfidReader.wakeAll()<br><br>       self.dlg = DlgWaitingRFID()<br>
       self.dlg.setModal(True)<br>       self.dlg.exec_()<br><br>       #self.rfidMutex.lock()<br>       #self.rfidWaiter.wait(self.rfidMutex)<br>       #self.rfidMutex.unlock()<br><br>   def readedRFID(self, rfid):<br>
       self.rfid_id = rfid<br>       print 'readedRFID:', rfid<br>       #self.rfidWaiter.wakeAll()<br>       self.dlg.close()<br><br>[Thread code]<br>class WaitingRFID(QThread):<br>   def __init__(self, parent):<br>
       self.callback = parent.callback<br>       self.mutex = parent.rfidMutex<br>       self.condition = parent.rfidReader<br>       QThread.__init__(self)<br><br>   def hex(self, symbol):<br>       return '%02X' % ord(symbol)<br>
<br>Â Â Â def run(self):<br>Â Â Â Â Â Â Â while True:<br>Â Â Â Â Â Â Â Â Â Â Â port = serial.Serial(PORT['name'], PORT['rate'],<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â bytesize = PORT['bits_in_byte'],<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â parity = PORT['parity'],<br>
                                stopbits = PORT['stop_bits']<br>                                )<br>           port.setDTR(True)<br>           port.setRTS(True)<br><br>           self.mutex.lock()<br>           self.condition.wait(self.mutex)<br>
<br>Â Â Â Â Â Â Â Â Â Â Â buffer = []<br>Â Â Â Â Â Â Â Â Â Â Â while True:<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â symbol = port.read(1)<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if not self.hex(symbol) == '0D':<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â buffer.append(symbol)<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else:<br>
                   if '0A' == self.hex(port.read(1)):<br>                       if len(buffer) == 9:<br>                           rfid_code = ''.join(buffer[1:]) # see manager.py<br>                           break<br>
                       buffer = []<br><br>           self.callback(rfid_code)<br>           self.mutex.unlock()<br><br>           port.close()<br><br>Thread code works well. The problem is in showing dialog.<br>I need to show dialog with a label 'Put RFID label on the reader.' and run thread's loop. The loop reads RFID id and use callback function. At this point I need to close the dialog window. Tell me the right way to do it.<br>
<br>Any help appreciated,<br clear="all"><font color="#888888">-- <br>Ruslan Popov<br>phone: +7 916 926 1205<br><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Ruslan Popov<br>phone: +7 916 926 1205<br><br>