]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-18/sound.py
fix building/running of tex2rtf
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-18 / sound.py
1 import wx
2 from wx.lib.filebrowsebutton import FileBrowseButton
3
4 class MyFrame(wx.Frame):
5 def __init__(self):
6 wx.Frame.__init__(self, None, title="wx.Sound",
7 size=(500,100))
8 p = wx.Panel(self)
9
10 # create the controls
11 self.fbb = FileBrowseButton(p,
12 labelText="Select WAV file:",
13 fileMask="*.wav")
14 btn = wx.Button(p, -1, "Play")
15 self.Bind(wx.EVT_BUTTON, self.OnPlaySound, btn)
16
17 # setup the layout with sizers
18 sizer = wx.BoxSizer(wx.HORIZONTAL)
19 sizer.Add(self.fbb, 1, wx.ALIGN_CENTER_VERTICAL)
20 sizer.Add(btn, 0, wx.ALIGN_CENTER_VERTICAL)
21 border = wx.BoxSizer(wx.VERTICAL)
22 border.Add(sizer, 0, wx.EXPAND|wx.ALL, 15)
23 p.SetSizer(border)
24
25
26 def OnPlaySound(self, evt):
27 filename = self.fbb.GetValue()
28 self.sound = wx.Sound(filename)
29 if self.sound.IsOk():
30 self.sound.Play(wx.SOUND_ASYNC)
31 else:
32 wx.MessageBox("Invalid sound file", "Error")
33
34
35 app = wx.PySimpleApp()
36 frm = MyFrame()
37 frm.Show()
38 app.MainLoop()