Exiting panda3d through wxPython problems

In my code, I run the entire panda3d loop within a try except statement. This means that, in the panda3d window, if I call self.finalizeExit() it raises a systemExit exception which I can catch back in that try except statement. What this does is, in the ‘except’ statement, I re-create a menu, effectively allowing me to close Panda3d and automatically go back to the original menu I launched the 3d window from. Now this normally works when I have clicked on the 3d window and press the key binded to my exit function, however this causes glitches with mouse movement. So, I’ve put a button in a frame using wx.python, and binded the button to the same exit function. However, when I click this button, instead of raising a SystemExit error that I can catch, it just fully exits the application. I wonder if its to do with the fact I’m clicking a button in a different tab to the panda3d window? How do I get it to properly work? Any help appreciated ty :slight_smile:

My code:
Code within original menu that runs panda3d object (OrbitalWindow)

    try:
          self.Sim = OrbitalWindow()
          self.Sim.run()
    except SystemExit as e:
          self.windowInit()
          self.initImage()
          self.titleCard.SetLabel("")

My finalise exit function within my panda3d class OrbitalWindow:

    def exitApp(self, event=None):
        self.props.set_mouse_mode(0)
        self.mFrame.Destroy()
        self.destroy()
        self.finalizeExit()
        raise SystemExit

Hmm… I wonder: What "self’ is the wx button passing to “exitApp”? If it’s not the relevant Panda object, then those commands that use the “self” parameter–including “self.destroy”–might be applied not to the Panda object, but to something else. This might be causing your application to shut down.

However, this is a bit of a guess–I’m not familiar with wx, myself. I’d suggest checking what object you’re getting in “self” when you call the “exitApp” method from your wx button.

Since this all takes place within my OrbitalWindow class which extends from the ShowBase class, the self should be the ShowBase object I’m fairly sure. Still not sure what is causing the problem, but thank you for the suggestion though.

1 Like

Well, in that case I suggest putting together a minimal program that demonstrates the problem: that way we can perhaps investigate more easily. (And it’s always possible that attempting to replicate the issue in a simple manner will reveal its cause, for that matter.)