]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | |
2 | import wx | |
493f1553 | 3 | |
6c5ae2d2 | 4 | from Main import opj |
493f1553 RD |
5 | |
6 | #---------------------------------------------------------------------- | |
7 | ||
8fa876ca | 8 | class TestPanel(wx.Panel): |
b2bacf13 | 9 | def __init__(self, parent, log): |
8fa876ca | 10 | wx.Panel.__init__(self, parent, -1) |
b2bacf13 RD |
11 | self.log = log |
12 | ||
13 | b = wx.Button(self, -1, "Play Sound 1 (sync)", (25, 25)) | |
8fa876ca | 14 | self.Bind(wx.EVT_BUTTON, self.OnButton1, b) |
493f1553 | 15 | |
b2bacf13 | 16 | b = wx.Button(self, -1, "Play Sound 2 (async)", (25, 65)) |
8fa876ca | 17 | self.Bind(wx.EVT_BUTTON, self.OnButton2, b) |
493f1553 | 18 | |
b2bacf13 RD |
19 | b = wx.Button(self, -1, "Select .WAV file", (25, 105)) |
20 | self.Bind(wx.EVT_BUTTON, self.OnSelectSound, b) | |
21 | ||
e5dd90b1 RD |
22 | |
23 | def OnButton1(self, evt): | |
24 | try: | |
78862f24 | 25 | sound = wx.Sound(opj('data/anykey.wav')) |
b2bacf13 RD |
26 | self.log.write("before Play...\n") |
27 | sound.Play(wx.SOUND_SYNC) | |
28 | self.log.write("...after Play\n") | |
e5dd90b1 | 29 | except NotImplementedError, v: |
8fa876ca | 30 | wx.MessageBox(str(v), "Exception Message") |
e5dd90b1 RD |
31 | |
32 | ||
33 | def OnButton2(self, evt): | |
493f1553 | 34 | try: |
9a5dd1c3 RD |
35 | #sound = wx.Sound(opj('data/plan.wav')) |
36 | data = open(opj('data/plan.wav'), 'rb').read() | |
37 | sound = wx.SoundFromData(data) | |
b2bacf13 RD |
38 | self.log.write("before Play...\n") |
39 | sound.Play(wx.SOUND_ASYNC) | |
40 | wx.YieldIfNeeded() | |
41 | self.log.write("...after Play\n") | |
493f1553 | 42 | except NotImplementedError, v: |
8fa876ca | 43 | wx.MessageBox(str(v), "Exception Message") |
493f1553 | 44 | |
b2bacf13 RD |
45 | |
46 | def OnSelectSound(self, evt): | |
47 | dlg = wx.FileDialog(wx.GetTopLevelParent(self), | |
48 | "Choose a sound file", | |
49 | wildcard="WAV files (*.wav)|*.wav", | |
50 | style=wx.OPEN) | |
51 | if dlg.ShowModal() == wx.ID_OK: | |
52 | try: | |
53 | sound = wx.Sound(dlg.GetPath()) | |
54 | sound.Play() | |
55 | except NotImplementedError, v: | |
56 | wx.MessageBox(str(v), "Exception Message") | |
57 | dlg.Destroy() | |
58 | ||
59 | ||
493f1553 RD |
60 | #---------------------------------------------------------------------- |
61 | ||
62 | def runTest(frame, nb, log): | |
b2bacf13 | 63 | win = TestPanel(nb, log) |
493f1553 RD |
64 | return win |
65 | ||
66 | #---------------------------------------------------------------------- | |
67 | ||
68 | ||
78862f24 RD |
69 | overview = """<html><body> |
70 | <h2>Sound</h2> | |
8fa876ca RD |
71 | This class represents a short wave file, in Windows WAV format, that can |
72 | be stored in memory and played. Currently this class is implemented on Windows | |
73 | and GTK (Linux) only. | |
78862f24 | 74 | <p> |
8fa876ca RD |
75 | This demo offers two examples, both driven by buttons, but obviously the event |
76 | that drives the playing of the sound can come from anywhere. | |
1fded56b | 77 | |
78862f24 | 78 | </body></html> |
8fa876ca | 79 | """ |
1fded56b RD |
80 | |
81 | ||
82 | if __name__ == '__main__': | |
83 | import sys,os | |
84 | import run | |
8eca4fef | 85 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) |