We were using Python2.3 and wxPython V2.4.2.4 in our project. And it was working fine. Now we are upgrading it to Python2.7 and wxPython2.8.12.1. Our project is compiled fine with new version. But in our project at one stage in the code we destroy the current window and then create & open new window again. And I have noticed that our code after creating new window does not execute. While in the old version it was executing.
In the following code. It is displaying the message “doRead 1” then open the window. But it does not display the message “doRead 2”. While in old Python version it was displaying the message “do Read 2” means it was executing the code after that.
I found that, it does not come out from the line “self.MainLoop()” in OnInit(…) function in new project. But it was coming out and thus executing the next line in old project.
-----------------------------------------
Here is the code:
#Close existing window.
self.Destroy()
print 'doRead 1'
#create new window
app = App()
print 'doRead 2'
app.frame.saveContents()
------------------------------------
class App(wx.App):
"""Application class.
"""
def OnInit(self):
wx.InitAllImageHandlers()
resetOptions()
setOptions()
self.frame = pdtpFrame()
self.frame.SetTitle(std.getTitle())
self.frame.Show()
self.SetTopWindow(self.frame)
self.MainLoop()
return True
def main():
""" Start up the pdtp main window application.
"""
app = App()
if __name__ == '__main__':
main()
Your trouble (as far as I can tell) is that you have your MainLoop inside of your OnInit function, which is halting your program flow. I can’t speak for how it worked like that before, to be honest, because you shouldn’t be able to enter the MainLoop for an App until it’s OnInit has returned
True. The OnInit could returnFalsein which case the App didn’t fully initialize (common if you’re doing single instance apps with a lock file, for example). A more common approach (pseudo-code) would look like this:It won’t execute more code until after all Top Level Windows are closed from the prior App instance, or something else calls
wx.GetApp().ExitMainLoop().