2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
import wx
|
2001-05-18 17:59:59 -04:00
|
|
|
|
2002-01-23 20:24:39 -05:00
|
|
|
from Main import opj
|
2001-05-18 17:59:59 -04:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
2004-03-18 17:04:08 -05:00
|
|
|
def __init__(self, parent, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2004-03-18 17:04:08 -05:00
|
|
|
self.log = log
|
2004-05-07 18:18:37 -04:00
|
|
|
|
2004-03-18 17:04:08 -05:00
|
|
|
b = wx.Button(self, -1, "Play Sound 1 (sync)", (25, 25))
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton1, b)
|
2001-05-18 17:59:59 -04:00
|
|
|
|
2004-03-18 17:04:08 -05:00
|
|
|
b = wx.Button(self, -1, "Play Sound 2 (async)", (25, 65))
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton2, b)
|
2001-05-18 17:59:59 -04:00
|
|
|
|
2004-03-18 17:04:08 -05:00
|
|
|
b = wx.Button(self, -1, "Select .WAV file", (25, 105))
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnSelectSound, b)
|
|
|
|
|
2002-03-13 17:26:55 -05:00
|
|
|
|
|
|
|
def OnButton1(self, evt):
|
|
|
|
try:
|
2004-02-02 22:55:05 -05:00
|
|
|
sound = wx.Sound(opj('data/anykey.wav'))
|
2004-03-18 17:04:08 -05:00
|
|
|
self.log.write("before Play...\n")
|
|
|
|
sound.Play(wx.SOUND_SYNC)
|
|
|
|
self.log.write("...after Play\n")
|
2002-03-13 17:26:55 -05:00
|
|
|
except NotImplementedError, v:
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.MessageBox(str(v), "Exception Message")
|
2002-03-13 17:26:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
def OnButton2(self, evt):
|
2001-05-18 17:59:59 -04:00
|
|
|
try:
|
2004-05-07 18:18:37 -04:00
|
|
|
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)
|
|
|
|
|
2004-03-18 17:04:08 -05:00
|
|
|
self.log.write("before Play...\n")
|
|
|
|
sound.Play(wx.SOUND_ASYNC)
|
|
|
|
wx.YieldIfNeeded()
|
|
|
|
self.log.write("...after Play\n")
|
2001-05-18 17:59:59 -04:00
|
|
|
except NotImplementedError, v:
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.MessageBox(str(v), "Exception Message")
|
2001-05-18 17:59:59 -04:00
|
|
|
|
2004-03-18 17:04:08 -05:00
|
|
|
|
|
|
|
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())
|
|
|
|
sound.Play()
|
|
|
|
except NotImplementedError, v:
|
|
|
|
wx.MessageBox(str(v), "Exception Message")
|
|
|
|
dlg.Destroy()
|
2004-05-07 18:18:37 -04:00
|
|
|
|
2004-03-18 17:04:08 -05:00
|
|
|
|
2001-05-18 17:59:59 -04:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
2004-03-18 17:04:08 -05:00
|
|
|
win = TestPanel(nb, log)
|
2001-05-18 17:59:59 -04:00
|
|
|
return win
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2004-02-02 22:55:05 -05:00
|
|
|
overview = """<html><body>
|
|
|
|
<h2>Sound</h2>
|
2004-05-07 18:18:37 -04:00
|
|
|
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
|
2003-12-08 20:23:28 -05:00
|
|
|
and GTK (Linux) only.
|
2004-02-02 22:55:05 -05:00
|
|
|
<p>
|
2003-12-08 20:23:28 -05:00
|
|
|
This demo offers two examples, both driven by buttons, but obviously the event
|
|
|
|
that drives the playing of the sound can come from anywhere.
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2004-02-02 22:55:05 -05:00
|
|
|
</body></html>
|
2003-12-08 20:23:28 -05:00
|
|
|
"""
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|