[QGIS-Developer] Run python script whit QProcess and show into textEdit the result in realtime

Germán Carrillo carrillo.german at gmail.com
Sun Sep 26 13:16:00 PDT 2021


Hi,

it might be useful for you to have a look at how QgisModelBaker does it:

https://github.com/opengisch/QgisModelBaker/blob/master/QgisModelBaker/libili2db/iliexecutable.py#L139-L185

Regards,

Germán


El dom, 26 sept 2021 a las 5:28, Enzo Cocca (<enzo.ccc at gmail.com>) escribió:

> 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()
>
>
> --
> Enzo Cocca PhD
> in "Science and Technology for Archaeology and Cultural Heritage"
>
> ISMEO
> International Association of Mediterranean and Oriental Studies
>
>
> mail: enzo.ccc at gmail.com
> cell: +393495087014
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>


-- 
-----------
  |\__
(:>__)(
   |/
Soluciones Geoinformáticas Libres
http://geotux.tuxfamily.org/
https://twitter.com/GeoTux2 <http://twitter.com/GeoTux2>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210926/05c787e2/attachment.html>


More information about the QGIS-Developer mailing list