]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/Sound.py
wxCheckListBox doesn't require wxUSE_OWNER_DRAWN when using WXUNIVERSAL
[wxWidgets.git] / wxPython / demo / Sound.py
... / ...
CommitLineData
1
2import wx
3
4from Main import opj
5
6#----------------------------------------------------------------------
7
8class TestPanel(wx.Panel):
9 def __init__(self, parent, log):
10 wx.Panel.__init__(self, parent, -1)
11 self.log = log
12
13 b = wx.Button(self, -1, "Play Sound 1 (sync)", (25, 25))
14 self.Bind(wx.EVT_BUTTON, self.OnButton1, b)
15
16 b = wx.Button(self, -1, "Play Sound 2 (async)", (25, 65))
17 self.Bind(wx.EVT_BUTTON, self.OnButton2, b)
18
19 b = wx.Button(self, -1, "Select .WAV file", (25, 105))
20 self.Bind(wx.EVT_BUTTON, self.OnSelectSound, b)
21
22
23 def OnButton1(self, evt):
24 try:
25 sound = wx.Sound(opj('data/anykey.wav'))
26 self.log.write("before Play...\n")
27 sound.Play(wx.SOUND_SYNC)
28 self.log.write("...after Play\n")
29 except NotImplementedError, v:
30 wx.MessageBox(str(v), "Exception Message")
31
32
33 def OnButton2(self, evt):
34 try:
35 if True:
36 sound = wx.Sound(opj('data/plan.wav'))
37 else:
38 # sounds can also be loaded from a buffer object
39 data = open(opj('data/plan.wav'), 'rb').read()
40 sound = wx.SoundFromData(data)
41
42 self.log.write("before Play...\n")
43 sound.Play(wx.SOUND_ASYNC)
44 self.sound = sound # save a reference (This shoudln't be needed, but there seems to be a bug...)
45 wx.YieldIfNeeded()
46 self.log.write("...after Play\n")
47 except NotImplementedError, v:
48 wx.MessageBox(str(v), "Exception Message")
49
50
51 def OnSelectSound(self, evt):
52 dlg = wx.FileDialog(wx.GetTopLevelParent(self),
53 "Choose a sound file",
54 wildcard="WAV files (*.wav)|*.wav",
55 style=wx.OPEN)
56 if dlg.ShowModal() == wx.ID_OK:
57 try:
58 #sound = wx.Sound(dlg.GetPath(), wx.SOUND_SYNC)
59 #sound.Play()
60
61 # another way to do it.
62 wx.Sound.PlaySound(dlg.GetPath(), wx.SOUND_SYNC)
63
64 except NotImplementedError, v:
65 wx.MessageBox(str(v), "Exception Message")
66 dlg.Destroy()
67
68
69#----------------------------------------------------------------------
70
71def runTest(frame, nb, log):
72 win = TestPanel(nb, log)
73 return win
74
75#----------------------------------------------------------------------
76
77
78overview = """<html><body>
79<h2>Sound</h2>
80This class represents a short wave file, in Windows WAV format, that can
81be stored in memory and played. Currently this class is implemented on Windows
82and GTK (Linux) only.
83<p>
84This demo offers two examples, both driven by buttons, but obviously the event
85that drives the playing of the sound can come from anywhere.
86
87</body></html>
88"""
89
90
91if __name__ == '__main__':
92 import sys,os
93 import run
94 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])