简体   繁体   中英

wxPython MessageDialog - How to query status?

I'm running a wxTimer that I would like to stop, before opening a MessageDialog, and restart, when the MessageDialog has been closed.

How would I accomplish that? I didn't find any method that would tell me whether or not the dialog has been closed or not.

At the moment the timer basically just continues ticking and more and more windows are opened at every tick :(

Hope you can help me. Thanks!

wxPython doesn't really have any mechanism for determining whether a MessageDialog is open. What you can do instead is manually keep track of whether a dialog is open.

If you open the MessageDialog using ShowModal , then the ShowModal call will return when the dialog is closed. You could use a flag which is set to True before the call to ShowModal and False afterwards, ie something like:

self.is_dialog_open = True
dialog.ShowModal()
self.is_dialog_open = False

The method called by your wx.Timer can then use self.is_dialog_open to determine whether the dialog is open.

Depending on how your application is structured, you might want to store this flag in some other object instead of self .

(I'm not making any guarantee that this code isn't prone to race conditions. If your timer happens to check whether a dialog is open just after ShowModal() returns but before self.is_dialog_open is set back to False , then your timer will think that the dialog is open when it in fact has just been closed. Hopefully this won't be a serious problem for you.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM