I have a series of shutdown hooks that I want to call when the
application terminates. I evaluate the return value of these hooks to
determine if an error occurred. If an error *does* occur, I would
like to notify the user with a dialog box, if it is safe.
I was able to pop up a dialog in wxApp::OnExit, with no fuss. I just
don't know if it is safe to do it there (cross-platform).
I had contemplated putting the code in my wx.Frame's wx.EVT_CLOSE
handler, but it wasn't orthogonal. I'm dealing with two sets of hook
functions, app_begin and app_end. I already had app_begin hooks being
called in wxApp::OnInit...
Thanks,
jw
···
On Fri, 24 Sep 2004 18:38:36 +0300, Peter Damoc <pdamoc@gmx.net> wrote:
> Is it safe to create a dialog in OnExit?
>
> I have a series of shutdown hooks that I want to call when the
> application terminates. I evaluate the return value of these hooks to
> determine if an error occurred. If an error *does* occur, I would
> like to notify the user with a dialog box, if it is safe.
excerpt from wx docs:
"OnExit is called after destroying all application windows and controls"
so if you want to do those checkings bind the wx.EVT_CLOSE of the main
frame to an event handler and in that event handler skip the event only if
everything is ok.
attached is a small sample
in that sample on the first attempt to close the frame the OkToExit method
switches a flag and says is not ok to exit but on the second attempt
returns true and the frame/app gets destroyed.
> I was able to pop up a dialog in wxApp::OnExit, with no fuss. I just
> don't know if it is safe to do it there (cross-platform).
>
> I had contemplated putting the code in my wx.Frame's wx.EVT_CLOSE
> handler, but it wasn't orthogonal. I'm dealing with two sets of hook
> functions, app_begin and app_end. I already had app_begin hooks being
> called in wxApp::OnInit...
If orthogonality is what you want... move the app_begin code in the
MainFrame's __init__
You're old enought to appreciate all that and young enough to still be able to change
You do remember the story about the mighty oak and the flexible willow.
I have a series of shutdown hooks that I want to call when the
application terminates. I evaluate the return value of these hooks to
determine if an error occurred. If an error *does* occur, I would
like to notify the user with a dialog box, if it is safe.
Yes, that's what an event handler like OnExit is for; so you can save your work or popup a little notification asking if the user really wants to exit.
I have a series of shutdown hooks that I want to call when the
application terminates. I evaluate the return value of these hooks to
determine if an error occurred. If an error *does* occur, I would
like to notify the user with a dialog box, if it is safe.
I think it should be okay, but it may vary by platform...
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
I have a series of shutdown hooks that I want to call when the
application terminates. I evaluate the return value of these hooks to
determine if an error occurred. If an error *does* occur, I would
like to notify the user with a dialog box, if it is safe.
Yes, that's what an event handler like OnExit is for; so you can save your work or popup a little notification asking if the user really wants to exit.
At the time that OnExit is called it is too late to prevent the app from exiting. If you want to prevent exiting then you need to veto the EVT_CLOSE event on the Frame(s)
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
At the time that OnExit is called it is too late to prevent the app from exiting. If you want to prevent exiting then you need to veto the EVT_CLOSE event on the Frame(s)
As long as OnExit doesn't call self.Destroy(), you can stop the program from exiting. At least, this is what I do, and I've had no problems.