]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/MediaCtrl.py
added a test to check how exception handling works with Win32 SEH; corrected copyright
[wxWidgets.git] / wxPython / demo / MediaCtrl.py
CommitLineData
256c055e
RD
1
2import wx
3import wx.media
4import os
5
95262b5f
RD
6from Main import opj
7
256c055e
RD
8#----------------------------------------------------------------------
9
10class TestPanel(wx.Panel):
11 def __init__(self, parent, log):
12 self.log = log
13 wx.Panel.__init__(self, parent, -1,
14 style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN)
15
16 # Create some controls
d6660ffa 17 self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
256c055e
RD
18
19 btn1 = wx.Button(self, -1, "Load File")
20 self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn1)
21
95262b5f
RD
22 btn2 = wx.Button(self, -1, "Play")
23 self.Bind(wx.EVT_BUTTON, self.OnPlay, btn2)
256c055e 24
95262b5f
RD
25 btn3 = wx.Button(self, -1, "Pause")
26 self.Bind(wx.EVT_BUTTON, self.OnPause, btn3)
256c055e 27
95262b5f
RD
28 btn4 = wx.Button(self, -1, "Stop")
29 self.Bind(wx.EVT_BUTTON, self.OnStop, btn4)
30
31 btn5 = wx.ToggleButton(self, -1, "Loop")
32 self.Bind(wx.EVT_TOGGLEBUTTON, self.OnLoopToggle, btn5)
256c055e 33
d6660ffa
RD
34 slider = wx.Slider(self, -1, 0, 0, 0)
35 self.slider = slider
36 self.Bind(wx.EVT_SLIDER, self.OnSeek, slider)
37
38 self.st_size = wx.StaticText(self, -1, size=(100,-1))
39 self.st_len = wx.StaticText(self, -1, size=(100,-1))
40 self.st_pos = wx.StaticText(self, -1, size=(100,-1))
41
42
256c055e
RD
43 # setup the layout
44 sizer = wx.GridBagSizer(5,5)
45 sizer.Add(self.mc, (1,1), span=(5,1))#, flag=wx.EXPAND)
46 sizer.Add(btn1, (1,3))
47 sizer.Add(btn2, (2,3))
48 sizer.Add(btn3, (3,3))
49 sizer.Add(btn4, (4,3))
50 sizer.Add(btn5, (5,3))
d6660ffa
RD
51 sizer.Add(slider, (6,1), flag=wx.EXPAND)
52 sizer.Add(self.st_size, (1, 5))
53 sizer.Add(self.st_len, (2, 5))
54 sizer.Add(self.st_pos, (3, 5))
256c055e 55 self.SetSizer(sizer)
d6660ffa
RD
56
57 self.DoLoadFile(opj("data/testmovie.mpg"))
58 self.mc.Stop()
59
60 self.timer = wx.Timer(self)
61 self.Bind(wx.EVT_TIMER, self.OnTimer)
62 self.timer.Start(100)
63
256c055e
RD
64
65
66 def OnLoadFile(self, evt):
67 dlg = wx.FileDialog(self, message="Choose a media file",
68 defaultDir=os.getcwd(), defaultFile="",
69 style=wx.OPEN | wx.CHANGE_DIR )
70 if dlg.ShowModal() == wx.ID_OK:
71 path = dlg.GetPath()
d6660ffa 72 self.DoLoadFile(path)
256c055e 73 dlg.Destroy()
d6660ffa
RD
74
75
76 def DoLoadFile(self, path):
77 if not self.mc.Load(path):
78 wx.MessageBox("Unable to load %s: Unsupported format?" % path,
79 "ERROR",
80 wx.ICON_ERROR | wx.OK)
81 else:
82 self.mc.SetBestFittingSize()
83 self.GetSizer().Layout()
84 self.slider.SetRange(0, self.mc.Length())
85 self.mc.Play()
256c055e
RD
86
87
95262b5f
RD
88 def OnLoopToggle(self, evt):
89 btn = evt.GetEventObject()
90 self.mc.Loop(btn.GetValue())
91
256c055e
RD
92
93 def OnPlay(self, evt):
94 self.mc.Play()
95
96 def OnPause(self, evt):
97 self.mc.Pause()
98
99 def OnStop(self, evt):
100 self.mc.Stop()
101
102
d6660ffa
RD
103 def OnSeek(self, evt):
104 offset = self.slider.GetValue()
105 self.mc.Seek(offset)
106
107 def OnTimer(self, evt):
108 offset = self.mc.Tell()
109 self.slider.SetValue(offset)
110 self.st_size.SetLabel('size: %s' % self.mc.GetBestSize())
111 self.st_len.SetLabel('length: %d seconds' % (self.mc.Length()/1000))
112 self.st_pos.SetLabel('position: %d' % offset)
256c055e
RD
113
114
115#----------------------------------------------------------------------
116
117def runTest(frame, nb, log):
118 try:
119 win = TestPanel(nb, log)
120 return win
121 except NotImplementedError:
122 from Main import MessagePanel
123 win = MessagePanel(nb, 'wx.MediaCtrl is not available on this platform.',
124 'Sorry', wx.ICON_WARNING)
125 return win
126
127
128#----------------------------------------------------------------------
129
130
131
132overview = """<html><body>
133<h2><center>wx.MediaCtrl</center></h2>
134
d6660ffa
RD
135wx.MediaCtrl is a class that allows a way to convieniently display
136various types of media, such as videos, audio files, natively through
137native codecs. Several different formats of audio and video files are
138supported, but some formats may not be playable on all platforms or
139may require specific codecs to be installed.
9828eeb4
RD
140
141<p>
142wx.MediaCtrl uses native backends to render media, for example on Windows
143there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
144QuickTime backend.
145<p>
146wx.MediaCtrl is not currently available on unix systems.
147
256c055e
RD
148</body></html>
149"""
150
151
152
153if __name__ == '__main__':
154 import sys,os
155 import run
156 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
157