Ejemplo n.º 1
0
class SerialDialog(QDialog):
    def __init__(self,serialPort,parent):
        QDialog.__init__(self,parent)
        self.ui=Ui_SerialDialog()
        self.ui.setupUi(self)
        self.serialPort=serialPort
        self.serialMonitor=SerialMonitor(self,self.serialPort)
        self.serialMonitor.newMessage.connect(self.addMessage)
        self.serialMonitor.start()
        self.ui.sendBtn.clicked.connect(self.sendMessage)
        self.ui.sendEdit.returnPressed.connect(self.sendMessage)
        
    @pyqtSlot(str)
    def addMessage(self,msg):
        self.ui.serialEdit.textCursor().insertText(msg)
        c = self.ui.serialEdit.textCursor();
        c.movePosition(QTextCursor.End);
        self.ui.serialEdit.setTextCursor(c);
    
    @pyqtSlot()
    def sendMessage(self):
        self.serialMonitor.sendMessage(self.ui.sendEdit.text())
        self.ui.sendEdit.clear()
    
    def closeEvent(self, *args, **kwargs):
        if (self.serialMonitor!=None and self.serialMonitor.isRunning()):
            self.serialMonitor.stop()
            self.serialMonitor.terminate()
            self.addMessage("Serial Process terminating...")
            while (not self.serialMonitor.wait()):
                pass
            print ("serialMonitor terminated")
        return QDialog.closeEvent(self, *args, **kwargs)
Ejemplo n.º 2
0
 def __init__(self,serialPort,parent):
     QDialog.__init__(self,parent)
     self.ui=Ui_SerialDialog()
     self.ui.setupUi(self)
     self.serialPort=serialPort
     self.serialMonitor=SerialMonitor(self,self.serialPort)
     self.serialMonitor.newMessage.connect(self.addMessage)
     self.serialMonitor.start()
     self.ui.sendBtn.clicked.connect(self.sendMessage)
     self.ui.sendEdit.returnPressed.connect(self.sendMessage)