Run python script whit QProcess and show into textEdit the result in realtime

33 Views Asked by At

I wolud print the result during my script run via Qprocess but nothing happen. I thinking I wrote wrong the args into process start but im not sure. Some one has an idea? Below my code

class TotalopenstationDialog(QtWidgets.QDialog, FORM_CLASS):    

    def __init__(self, parent=None):
        """Constructor."""
        super(TotalopenstationDialog, self).__init__(parent)        
        self.setupUi(self)

    def dataReady(self):
        cursor = self.textEdit.textCursor()
        cursor.movePosition(cursor.End)
        cursor.insertText(str(self.process.readAll()))
        self.textEdit.ensureCursorVisible()

    def callProgram(self):
        # run the process
        # `start` takes the exec and a list of arguments
        python_path = sys.exec_prefix
        python_version = sys.version[:3]
        p = '{}\python'.format(python_path)
        b=QgsApplication.qgisSettingsDirPath().replace("/","\\")#this one works for windows path
        cmd = os.path.join(os.sep, b, 'python', 'plugins', 'totalopenstationToQgis', 
        'scripts', 'totalopenstation-cli-parser.py')        
        self.process = QProcess(self)
        # QProcess emits `readyRead` when there is data to be read
        self.process.readyRead.connect(self.dataReady)        
        self.process.start(p, [cmd, '-i',str(self.lineEdit_input.text()),'-o',str(self.lineEdit_output.text()),'-f',self.comboBox_format.currentText(),'-t',self.comboBox_format2.currentText(),'--overwrite'])

    def on_pushButton_connect_pressed(self):
        self.callProgram()
0

There are 0 best solutions below