4

QGIS Processing class has a method execAlgorithmDialog() that opens the dialogue window of any processing algorithm.

I am writing a Plugin that has a processing algorithm Run Analysis, I also need to include another tool Load Analysis in my plugin suite, that takes a JSON file, which will consist of input parameters for Run Analysis, and using these parameters load the window of Run Analysis. I have been able to achieve this by using execAlgorithmDialog() and postProcessAlgorithm() but with one caveat, the Load Analysis window continues to run in the background until I close the newly popped up Run Analysis window. This is something I want to avoid. I am looking for a way to open new window and close the previous one at the same time.

Here is how my code looks like

from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (QgsProcessingAlgorithm, QgsProcessingParameterFile)
from qgis import processing

class LoadAnalysis(QgsProcessingAlgorithm):
    load_parameters = {}

    def createInstance(self):
        return LoadAnalysis()

    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFile('Previousrunfile', 'Previous run file', behavior=QgsProcessingParameterFile.File, fileFilter='JSON Files (*.json)', defaultValue=None))


    def processAlgorithm(self, parameters, context, feedback):
        # load json file dict into python object
        # and save it in self.load_parameters
        return {}


    def postProcessAlgorithm(self, context, feedback):
        processing.execAlgorithmDialog("native:dropgeometries", self.load_parameters)
        return {}

In this screenshot, I have replicated the behaviour using Drop Geometries algorithm inplace of Run Analysis. You can see that Load Analysis is running in the background.

enter image description here

2
  • Is this a problem? Nov 27, 2021 at 18:56
  • Yes it is. I want it to terminate after making that call. Nov 27, 2021 at 20:44

1 Answer 1

2

Most likely this is because feedback instance is terminated after postProcessAlgorithm method. The progress bar shows a busy indicator instead of a percentage of steps, since the first window does not know how long the second process opened by execAlgorithmDialog will take.

2
  • I understand. Is there a way to avoid this, is there another way to make execAlgorithmDialog call and terminate the previous window? Can threads be used to achieve this? Nov 27, 2021 at 20:49
  • I have no idea for now. Dec 18, 2021 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.