2

I've read many threads on this but I'm not able to figure out the solution (I'm a beginner to the plugin creation...).

What I what to do is to close the dialog window when the algorithm has finished its job.

That's the piece of code of the alg.dialog.py:

    class CreateModelDialog(QDialog, FORM_CLASS):
        def __init__(self, iface):
            QDialog.__init__(self)
            self.iface = iface
            self.setupUi(self)
            self.buttonBox.rejected.connect(self.reject)
            self.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.createModel)

            self.manageGui()

........

    def createModel(self):
        modelName = self.bxDBname.text()
        modelType = self.cmbBxModelType.currentText()
        lengthString = self.cmbBxLengthUnit.currentText()
        timeString = self.cmbBxTimeUnit.currentText()
        workingDir = self.OutFilePath
        print 'Direttori recuperata ..... ' , workingDir
        isChild = 1.0
        createModel(modelName, workingDir, modelType, isChild, lengthString, timeString)

So self.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.createModel), when clicked runs the createModel method.

But the dialog remains opended, where should I edit the code?


This is the __init__ function:

def __init__(self, iface):
    QDialog.__init__(self)
    self.iface = iface
    self.setupUi(self)
    self.buttonBox.rejected.connect(self.reject)
    self.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.createModel)

    self.manageGui()

This is the function in the main plugin.py file:

def runCreateModel(self):
    """Run method that performs all the real work"""
    # Create the dialog (after translation) and keep reference
    self.dlgMD = mdDialog.CreateModelDialog(self.iface)
    # show the dialog
    self.dlgMD.show()
    # Run the dialog event loop
    self.dlgMD.exec_()

1 Answer 1

4

In your __init__ function in plugin implementation find a line where your dialog was created.

Probably it will be:

self.dlg = CreateModelDialog()

Then if you want to close dialog window you have to execute:

self.dlg.close()

Put this line into the function with your algorithm at the end of code.

Example structure of your plugin.py:

class CreateModel:
    def __init__(self, iface):
        ...
        self.dlg = CreateModelDialog()
        ...
        # connections
        self.dlg.button.clicked.connect(self.function)

    def function(self):
        # some code for your algorithm
        self.dlg.close()

    ...
    def run(self):
        ...
7
  • mm.. nope.. I don't have any self.dlg = CreateModelDialog() in the init function. I edited the question adding the __init__ function..
    – matteo
    Commented Aug 25, 2015 at 12:43
  • Have you used plugin builder?
    – dmh126
    Commented Aug 25, 2015 at 12:54
  • Yes.. The plugis is quite complicated with many dialogs.. but we started it with the plugin builder
    – matteo
    Commented Aug 25, 2015 at 13:07
  • So you have got there two .py files among the others: pluginname_dialog.py and pluginname.py. Check out the second file. There should be an implementation class (CreateModel I guess...).
    – dmh126
    Commented Aug 25, 2015 at 13:14
  • Yep.. So, I looked into the plugin.py and I found the functions that call the dialogs (I have many of them in the plugin).. See EDIT2 (sorry for being so bothering..).. I tried to add self.dlgMD.close() but is doesn't work...
    – matteo
    Commented Aug 25, 2015 at 13:36

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.