PyQt4: Wait on modeless dialog

112 views Asked by At

Is there a way of waiting on closure of a modeless dialog?

Here is an example application: I start some program which needs to do some startup stuff and also needs the user to log-in. Since the user logging in takes some time, I'd like to have the login box be modeless, so that I can continue doing my other startup stuff in the background. But at some point I am not going to be able to continue until the login process is completed. So ideally I'd like to be able to call something like dialog.wait_until_complete() when I get to that point and have it then act like a modal dialog, only continuing once the user accepts/rejects the dialog.

1

There are 1 answers

0
ekhumoro On BEST ANSWER

Connect to the dialog's finished signal:

    self.login.finished.connect(self.handleLoginFinished)
    ...

def handleLoginFinished(self, result):
    if result == QDialog.Accepted:
        # register login...
    else:
        # deal with cancelled login...

To prevent user interaction, you could just hide() the main window until the login is completed. Otherwise, to change the dialog's modality, you need to do something like:

    self.login.hide()
    self.login.setModal(True)
    self.login.show()