]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/MediaCtrl.py
wxCheckListBox doesn't require wxUSE_OWNER_DRAWN when using WXUNIVERSAL
[wxWidgets.git] / wxPython / demo / MediaCtrl.py
... / ...
CommitLineData
1
2import wx
3import wx.media
4import os
5
6from Main import opj
7
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
17 try:
18 self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
19 except NotImplementedError:
20 self.Destroy()
21 raise
22
23 btn1 = wx.Button(self, -1, "Load File")
24 self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn1)
25
26 btn2 = wx.Button(self, -1, "Play")
27 self.Bind(wx.EVT_BUTTON, self.OnPlay, btn2)
28
29 btn3 = wx.Button(self, -1, "Pause")
30 self.Bind(wx.EVT_BUTTON, self.OnPause, btn3)
31
32 btn4 = wx.Button(self, -1, "Stop")
33 self.Bind(wx.EVT_BUTTON, self.OnStop, btn4)
34
35 slider = wx.Slider(self, -1, 0, 0, 0)
36 self.slider = slider
37 self.Bind(wx.EVT_SLIDER, self.OnSeek, slider)
38
39 self.st_size = wx.StaticText(self, -1, size=(100,-1))
40 self.st_len = wx.StaticText(self, -1, size=(100,-1))
41 self.st_pos = wx.StaticText(self, -1, size=(100,-1))
42
43
44 # setup the layout
45 sizer = wx.GridBagSizer(5,5)
46 sizer.Add(self.mc, (1,1), span=(5,1))#, flag=wx.EXPAND)
47 sizer.Add(btn1, (1,3))
48 sizer.Add(btn2, (2,3))
49 sizer.Add(btn3, (3,3))
50 sizer.Add(btn4, (4,3))
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))
55 self.SetSizer(sizer)
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
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()
72 self.DoLoadFile(path)
73 dlg.Destroy()
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()
86
87
88 def OnPlay(self, evt):
89 self.mc.Play()
90
91 def OnPause(self, evt):
92 self.mc.Pause()
93
94 def OnStop(self, evt):
95 self.mc.Stop()
96
97
98 def OnSeek(self, evt):
99 offset = self.slider.GetValue()
100 self.mc.Seek(offset)
101
102 def OnTimer(self, evt):
103 offset = self.mc.Tell()
104 self.slider.SetValue(offset)
105 self.st_size.SetLabel('size: %s' % self.mc.GetBestSize())
106 self.st_len.SetLabel('length: %d seconds' % (self.mc.Length()/1000))
107 self.st_pos.SetLabel('position: %d' % offset)
108
109
110#----------------------------------------------------------------------
111
112def runTest(frame, nb, log):
113 try:
114 win = TestPanel(nb, log)
115 return win
116 except NotImplementedError:
117 from Main import MessagePanel
118 win = MessagePanel(nb, 'wx.MediaCtrl is not available on this platform.',
119 'Sorry', wx.ICON_WARNING)
120 return win
121
122
123#----------------------------------------------------------------------
124
125
126
127overview = """<html><body>
128<h2><center>wx.MediaCtrl</center></h2>
129
130wx.MediaCtrl is a class that allows a way to convieniently display
131various types of media, such as videos, audio files, natively through
132native codecs. Several different formats of audio and video files are
133supported, but some formats may not be playable on all platforms or
134may require specific codecs to be installed.
135
136<p>
137wx.MediaCtrl uses native backends to render media, for example on Windows
138there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
139QuickTime backend.
140<p>
141wx.MediaCtrl is not currently available on unix systems.
142
143</body></html>
144"""
145
146
147
148if __name__ == '__main__':
149 import sys,os
150 import run
151 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
152