
July 5th, 2004, 04:35 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
I do not know anything about the ogg API, but I presume there is a function to stop the audio. So the problem is how to call this function when the user exits your program. There are basically two ways to do this in wxPython:
1) You can associate a function with the close event of the main Frame, using EVT_CLOSE.
2_ Alternatively you could override the OnExit method of the class you derive from wxApp, to do the cleanup when the application exits.
I think the first option is preferable. If you trap the close event then you must call the Frame's Destroy method to actually close the window.
Here is a simple example:
Code:
#!/usr/bin/env python
import wx
class Frame(wx.Frame):
def __init__(self, parent=None, id=-1,
pos=wx.DefaultPosition, title='Close Me'):
wx.Frame.__init__(self, parent, id, title, pos)
wx.EVT_CLOSE(self, self.onClose)
def onClose(self, event):
'''called when the Frame is closed by whatever means'''
wx.MessageBox('Bye Bye', 'Closing')
self.Destroy()
class App(wx.App):
def OnInit(self):
self.frame = Frame()
self.frame.Show()
self.SetTopWindow(self.frame)
return True
def main():
app = App()
app.MainLoop()
if __name__ == '__main__':
main()
This will pop up a message box when the Frame is closed, either through clicking on the X or pressing Alt-F4 (on Windows).
Dave - The Developers' Coach
|