[QGIS-Developer] How to open a QGIS prococessing algorithm dialog in python?

Nyall Dawson nyall.dawson at gmail.com
Sun Jan 26 22:34:12 PST 2020


On Sat, 25 Jan 2020 at 01:43, Enrico Ferreguti <enricofer at gmail.com> wrote:
>
> Hi QGIS developers,
>
> I would like to programmatically show a processing algoritm dialog from python. I gived a look to processing toolbox and I found that this is possible importing and instantiating the class AlgorithmDialog [gui/processingToolbox.py][1]
>
>     from processing.gui.AlgorithmDialog import AlgorithmDialog
>     from qgis.core import QgsApplication
>
>     alg = QgsApplication.processingRegistry().algorithmById('qgis:extractbyattribute')
>     dlg = AlgorithmDialog(alg, False, iface.mainWindow())
>     dlg.show()
>     dlg.exec_()
>
> This opens algorithm dialog and let me perform processing computations but once closed the dialog window QGIS become instable and crash without any message interacting with the user interface.
>
> What am I doing wrong? Is there a method to do this in other way?

Yep - there's a built in method which does this for you.

You want either

from qgis.processing import createAlgorithmDialog
dlg = createAlgorithmDialog('qgis:extractbyattribute', parameters={})
dlg.exec_()

OR

from qgis.processing import execAlgorithmDialog
results = execAlgorithmDialog('qgis:extractbyattribute', parameters={})

(check the docs for each for the full details)

In general, try to avoid any "from processing.* " imports -- those are
all internal details and not considered stable API. Anything in
"qgis.processing" IS stable and is public API, designed for external
use.

Nyall


>
> I just posted the question on StackExchange: https://gis.stackexchange.com/questions/348542/open-qgis-prococessing-algorithm-dialog-with-python
>
> Thanks in advance.
> Enrico Ferreguti.
>
>   [1]: https://github.com/qgis/QGIS/blob/276a31439eb95f9cdb1053a6ae2dba3f19fbcece/python/plugins/processing/gui/ProcessingToolbox.py#L262
> _______________________________________________
> 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


More information about the QGIS-Developer mailing list