[wxPython] Unhandled Exceptions During Startup

After looking at demo code from somewhere or other, I wrote the attached code to start my application. It works fine, but is causing me an annoying debugging problem.

   If there is an unhandled exception in the constructor for ManagerFrame, then I am left in a state where my python process is busy running the MainLoop, but there is no associated frame or window to close.

   This means I have to kill my python process by hand. This isn't a total loss, but it is a pain since I have to reload the assorted modules I'm testing, lose command history, lose my train of thought, etc.

   If I ditch the spash screen, I can do a blanket catch in OnInit() and return false to show the application should exit. I might suggest that whoever is calling the OnInit should do the same at a higher level. IE: treat any exception thrown from OnInit as a false return value.

   I tried doing a blanket catch of all exceptions and then calling wxExit, but wxExit doesn't seem to be defined.

   This is obviously not critical, but since I'm trying to learn more about how wxPython works, I thought it would be interesting to learn how to handle this situation better. Thanks for any help!

class ManagerApp(wxApp):
     def OnInit(self):
         self.splash = SplashScreen(None, bitmapfile='img/splash.png',
                                    duration=4000, callback=self.AfterSplash)
         self.splash.Show()
         return true

     def AfterSplash(self):
         self.splash.Close(true)

         frame = ManagerFrame()
         frame.Show(true)
         self.SetTopWindow(frame)

···

--
Don Garrett http://www.bgb.cc/garrett/
BGB Consulting garrett@bgb.cc

How about doing this in your AfterSplash?

import traceback

     def AfterSplash(self):
         try:
                 self.splash.Close(true)

                 frame = ManagerFrame()
                 frame.Show(true)
                 self.SetTopWindow(frame)
         except:
          traceback.print_exc()
           self.ExitMainLoop()

HTH,
Mike

Don Garrett wrote:

···

  After looking at demo code from somewhere or other, I wrote the attached code to start my application. It works fine, but is causing me an annoying debugging problem.

  If there is an unhandled exception in the constructor for ManagerFrame, then I am left in a state where my python process is busy running the MainLoop, but there is no associated frame or window to close.

  This means I have to kill my python process by hand. This isn't a total loss, but it is a pain since I have to reload the assorted modules I'm testing, lose command history, lose my train of thought, etc.

  If I ditch the spash screen, I can do a blanket catch in OnInit() and return false to show the application should exit. I might suggest that whoever is calling the OnInit should do the same at a higher level. IE: treat any exception thrown from OnInit as a false return value.

  I tried doing a blanket catch of all exceptions and then calling wxExit, but wxExit doesn't seem to be defined.

  This is obviously not critical, but since I'm trying to learn more about how wxPython works, I thought it would be interesting to learn how to handle this situation better. Thanks for any help!

class ManagerApp(wxApp):
    def OnInit(self):
        self.splash = SplashScreen(None, bitmapfile='img/splash.png',
                                   duration=4000, callback=self.AfterSplash)
        self.splash.Show()
        return true

    def AfterSplash(self):
        self.splash.Close(true)

        frame = ManagerFrame()
        frame.Show(true)
        self.SetTopWindow(frame)

--
_______________________________________
   Mike C. Fletcher
   http://members.rogers.com/mcfletch/

This looks perfect! Somehow I failed to find the function to make it work. Thanks!

Mike C. Fletcher wrote:

···

How about doing this in your AfterSplash?

import traceback

    def AfterSplash(self):
        try:
                self.splash.Close(true)

                frame = ManagerFrame()
                frame.Show(true)
                self.SetTopWindow(frame)
        except:
            traceback.print_exc()
            self.ExitMainLoop()

HTH,
Mike

--
Don Garrett http://www.bgb.cc/garrett/
BGB Consulting garrett@bgb.cc