displaying MessageBox on startup

I'm trying to figure out the right place in my code to display a wxMessageDialog (or call wxMessageBox) on startup. I've found that on MS Windows, you can call wxMessageBox to display a dialog box before starting calling app.MainLoop, and the dialog will still respond to the mouse/keyboard. However, I'm not sure whether this is the right approach in general, particularly cross-platform, or whether it would be more reliable to use wxCallAfter to show the dialog as soon as the loop starts.

To give you more background:

I have a program which stores configuration data in a file, and reads it again on startup. The program may encounters an error while trying to read the configuration file, caused by a corrupted file, or a bug in the routine to read old versions of the file. In that case, it must exit. Before exiting, it renames the file, so that the user can re-run the program without encountering the same problem again. However, unless the file is repaired and renamed back, the user's persistent data will be lost, so I need to put up a message box to warn the user that the file has been renamed.

I'm using wxPython 2.4.0.2, Python 2.2 on Win98SE.

Thanks in advance,
David

Hello !

In my opinion, you should put the configuration reading and message dialog
code in the OnInit method of the wxApp class.

Guillaume

-----Message d'origine-----

···

De : David C. Fox [mailto:davidcfox@post.harvard.edu]
Envoye : lundi 23 juin 2003 18:06
A : wxPython Users List
Objet : [wxPython-users] displaying MessageBox on startup

I'm trying to figure out the right place in my code to display a
wxMessageDialog (or call wxMessageBox) on startup. I've found that on
MS Windows, you can call wxMessageBox to display a dialog box before
starting calling app.MainLoop, and the dialog will still respond to the
mouse/keyboard. However, I'm not sure whether this is the right
approach in general, particularly cross-platform, or whether it would be
more reliable to use wxCallAfter to show the dialog as soon as the loop
starts.

To give you more background:

I have a program which stores configuration data in a file, and reads it
again on startup. The program may encounters an error while trying to
read the configuration file, caused by a corrupted file, or a bug in the
routine to read old versions of the file. In that case, it must exit.
Before exiting, it renames the file, so that the user can re-run the
program without encountering the same problem again. However, unless
the file is repaired and renamed back, the user's persistent data will
be lost, so I need to put up a message box to warn the user that the
file has been renamed.

I'm using wxPython 2.4.0.2, Python 2.2 on Win98SE.

Thanks in advance,
David

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

David C. Fox wrote:

I'm trying to figure out the right place in my code to display a wxMessageDialog (or call wxMessageBox) on startup. I've found that on MS Windows, you can call wxMessageBox to display a dialog box before starting calling app.MainLoop, and the dialog will still respond to the mouse/keyboard. However, I'm not sure whether this is the right approach in general, particularly cross-platform, or whether it would be more reliable to use wxCallAfter to show the dialog as soon as the loop starts.

It is safe to use dialogs from the app's OnInit method. Or, if you are just using wxPySimpleApp and not deriving your own app object, then you can do it after the app is created but before MainLoop is called if you like. This is because showing a modal dialog starts another "main loop" that lasts until the ShowModal returns.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!