[PyQt] how to close a dialog during initialisation
Mirage Web Studio
miragewebstudio12 at yahoo.com
Sun Apr 5 17:32:10 BST 2015
On 2015-04-05 8:37 PM, David Cortesi wrote:
>
> I want to close a Qdialog during its initialisation i.e. inside def
> __init__. I do some computing during the initialisation of a dialog.
> if they don't return a particular value i wish to close the dialog
> inside the init statement is it possible or is there a way i can
> achieve it.
>
> One way would be to raise an exception inside __init__().
>
> class myOddDialog(QDialog):
> def __init__(parent):
> if something_is_wrong :
> raise ValueError
>
> And then create it inside a try:
>
> try:
> odd_dialog = myOddDialog(self)
> response = odd_dialog.exec_()
> except:
> response = failure_value
>
> But this is very peculiar. Anything that the dialog could figure out
> during __init__(), the parent code could also figure out before it
> creates the dialog or shows the dialog. So I would just test for the
> bad condition in the main code and only display the dialog (call its
> .exec_() method) when the condition was good.
>
> Also be aware of the nice "canned" dialogs available as static methods
> of QMessageBox, such as question(), warning() and so on. Read the doc
> for QMessageBox, it can save you a lot of effort.
>
>
Thank you.
Your solution works for me.
I agree with your statement, but i am trying to build multi dialog
application without a MDI, it just so seems fit to do computations
regarding a problem within the concerned dialog. And if no permissible
results exit just stop the dialog and return. Thinking of other
solutions like taking the initial computation outside the dialog init i
think is too much coding and tracking for errors so just trying to keep
the related bunch together.
George
---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150405/5c76b677/attachment.html>
More information about the PyQt
mailing list