0

I have a GUI that has 4 widgets which are user inputs (file in/out and directory in/out). I am trying to make a button that will do two things.

  1. I want to button when clicked to send the four user set parameters to another imported function.

        self.btn.clicked.connect(lambda: self.sendData(self.rawName, self.outName, self.directoryIn, self.directoryOut))
    

I was using something like this. Where send data looks like this:

def sendData(self, rawName, outName, directoryIn, directoryOut):
    try:
        foo.main(rawName, outName, directoryIn, directoryOut)
    except TypeError:
        pass

In this case foo.main is the imported function. The user input method looks like this:

   def setInputDirectory(self):
       options = QtGui.QFileDialog.DontResolveSymlinks | QtGui.QFileDialog.ShowDirsOnly
       directoryIn = QtGui.QFileDialog.getExistingDirectory(self,
                                                       "Some Directory",
                                                       self.directoryLabelIn.text(), options)
       if directoryIn:
           self.directoryLabelIn.setText(directoryIn)

Finally, I want to have the button (btn) be clickable only when all four values are entered in the gui.

1 Answer 1

1
self.rawName = ""
self.outName = ""
self.directoryIn = ""
self.directoryOut = ""
...
self.btn.clicked.connect(self.sendData)
self.btn.setEnabled(False) # disable button here, enable it later

so you can simply send those parameters directly:

def sendData(self):
    try:
        foo.main(self.rawName, self.outName, self.directoryIn, self.directoryOut)
    except TypeError:
        pass

also after every input, check if all four values are entered and if so enable button:

def areAllFourValuesEntered(self):
    if (self.rawName!="" and self.outName!="" and self.directoryIn!="" and self.directoryOut!=""):
        self.btn.setEnabled(True)
Sign up to request clarification or add additional context in comments.

2 Comments

Hmm, I does not seem to pass the values. Do I need to change the setInputDirectory method? It seems like the self.whatever is still = ""
oh, you need to pass it to SELF.whatever, like this: self.directoryIn = QtGui.QFileDialog.getExistingDirectory..... In your case directoryIn is local attribute in method setInputDirectory and it is destroyed at the exit of method scope. On the other side, any attribute that has self.attName is visible anywhere in class scope.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.