'''Wx_lib_filebrowsebutton_sound.py Select a sound file and play it Wx. lib. filebrowsebutton. FileBrowseButton (parent, labelText, fileMask) (Combines wx. TextCtrl and wxFileDialog widgets) Wx. Sound (fileName, isResource = False) Tested with Python27 and wxPython291 by vegaseat 25jul2013 ''' Import wx Import wx. lib. filebrowsebutton Class MyFrame (wx. Frame ): Def _ init _ (self, parent, mytitle, mysize ): Wx. Frame. _ init _ (self, parent, wx. ID_ANY, mytitle, Size = mysize) Self. SetBackgroundColour ("green ") Panel = wx. Panel (self) # Mask file browser to look for. wav sound files Self. fbb = wx. lib. filebrowsebutton. FileBrowseButton (panel, LabelText = "Select a WAVE file:", fileMask = "*. wav ") Self. play_button = wx. Button (panel, wx. ID_ANY, "> Play ") Self. play_button.Bind (wx. EVT_BUTTON, self. onPlay) # Setup the layout with sizers Hsizer = wx. BoxSizer (wx. HORIZONTAL) Hsizer. Add (self. fbb, 1, wx. ALIGN_CENTER_VERTICAL) Hsizer. Add (self. play_button, 0, wx. ALIGN_CENTER_VERTICAL) # Create a border space Border = wx. BoxSizer (wx. VERTICAL) Border. Add (hsizer, 0, wx. EXPAND | wx. ALL, 10) Panel. SetSizer (border) Def onPlay (self, evt ): Filename = self. fbb. GetValue () Self. sound = wx. Sound (filename) # Error handling... If self. sound. IsOk (): Self. sound. Play (wx. SOUND_ASYNC) Else: Wx. MessageBox ("Missing or invalid sound file", "Error ") App = wx. App (0) # Create a MyFrame instance and show the frame Mytitle = "wx. lib. filebrowsebutton and wx. Sound" Width = 600 Height = 90 MyFrame (None, mytitle, (width, height). Show () App. MainLoop () |