]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/Sound.py
wxCheckListBox doesn't require wxUSE_OWNER_DRAWN when using WXUNIVERSAL
[wxWidgets.git] / wxPython / demo / Sound.py
index fde55f785c1794e724ecaf0f4dd85b3d0deed433..2584de414c0676163fc2027f728a8019959d3533 100644 (file)
@@ -6,35 +6,70 @@ from Main import opj
 #----------------------------------------------------------------------
 
 class TestPanel(wx.Panel):
 #----------------------------------------------------------------------
 
 class TestPanel(wx.Panel):
-    def __init__(self, parent):
+    def __init__(self, parent, log):
         wx.Panel.__init__(self, parent, -1)
         wx.Panel.__init__(self, parent, -1)
+        self.log = log
 
 
-        b = wx.Button(self, -1, "Play Sound 1", (25, 25))
+        b = wx.Button(self, -1, "Play Sound 1 (sync)", (25, 25))
         self.Bind(wx.EVT_BUTTON, self.OnButton1, b)
 
         self.Bind(wx.EVT_BUTTON, self.OnButton1, b)
 
-        b = wx.Button(self, -1, "Play Sound 2", (25, 65))
+        b = wx.Button(self, -1, "Play Sound 2 (async)", (25, 65))
         self.Bind(wx.EVT_BUTTON, self.OnButton2, b)
 
         self.Bind(wx.EVT_BUTTON, self.OnButton2, b)
 
+        b = wx.Button(self, -1, "Select .WAV file", (25, 105))
+        self.Bind(wx.EVT_BUTTON, self.OnSelectSound, b)
+
 
     def OnButton1(self, evt):
         try:
             sound = wx.Sound(opj('data/anykey.wav'))
 
     def OnButton1(self, evt):
         try:
             sound = wx.Sound(opj('data/anykey.wav'))
-            sound.Play()
+            self.log.write("before Play...\n")
+            sound.Play(wx.SOUND_SYNC)
+            self.log.write("...after Play\n")
         except NotImplementedError, v:
             wx.MessageBox(str(v), "Exception Message")
 
 
     def OnButton2(self, evt):
         try:
         except NotImplementedError, v:
             wx.MessageBox(str(v), "Exception Message")
 
 
     def OnButton2(self, evt):
         try:
-            sound = wx.Sound(opj('data/plan.wav'))
-            sound.Play()
+            if True:
+                sound = wx.Sound(opj('data/plan.wav'))
+            else:
+                # sounds can also be loaded from a buffer object
+                data = open(opj('data/plan.wav'), 'rb').read()
+                sound = wx.SoundFromData(data)
+                
+            self.log.write("before Play...\n")
+            sound.Play(wx.SOUND_ASYNC)
+            self.sound = sound  # save a reference (This shoudln't be needed, but there seems to be a bug...)
+            wx.YieldIfNeeded()
+            self.log.write("...after Play\n")
         except NotImplementedError, v:
             wx.MessageBox(str(v), "Exception Message")
 
         except NotImplementedError, v:
             wx.MessageBox(str(v), "Exception Message")
 
+
+    def OnSelectSound(self, evt):
+        dlg = wx.FileDialog(wx.GetTopLevelParent(self),
+                            "Choose a sound file",
+                            wildcard="WAV files (*.wav)|*.wav",
+                            style=wx.OPEN)
+        if dlg.ShowModal() == wx.ID_OK:
+            try:
+                #sound = wx.Sound(dlg.GetPath(), wx.SOUND_SYNC)
+                #sound.Play()
+
+                # another way to do it.
+                wx.Sound.PlaySound(dlg.GetPath(), wx.SOUND_SYNC)
+                
+            except NotImplementedError, v:
+                wx.MessageBox(str(v), "Exception Message")
+        dlg.Destroy()
+
+
 #----------------------------------------------------------------------
 
 def runTest(frame, nb, log):
 #----------------------------------------------------------------------
 
 def runTest(frame, nb, log):
-    win = TestPanel(nb)
+    win = TestPanel(nb, log)
     return win
 
 #----------------------------------------------------------------------
     return win
 
 #----------------------------------------------------------------------
@@ -42,8 +77,8 @@ def runTest(frame, nb, log):
 
 overview = """<html><body>
 <h2>Sound</h2>
 
 overview = """<html><body>
 <h2>Sound</h2>
-This class represents a short wave file, in Windows WAV format, that can 
-be stored in memory and played. Currently this class is implemented on Windows 
+This class represents a short wave file, in Windows WAV format, that can
+be stored in memory and played. Currently this class is implemented on Windows
 and GTK (Linux) only.
 <p>
 This demo offers two examples, both driven by buttons, but obviously the event
 and GTK (Linux) only.
 <p>
 This demo offers two examples, both driven by buttons, but obviously the event
@@ -56,4 +91,4 @@ that drives the playing of the sound can come from anywhere.
 if __name__ == '__main__':
     import sys,os
     import run
 if __name__ == '__main__':
     import sys,os
     import run
-    run.main(['', os.path.basename(sys.argv[0])])
+    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])