]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/MediaCtrl.py
fix compilation error
[wxWidgets.git] / wxPython / demo / MediaCtrl.py
CommitLineData
256c055e
RD
1
2import wx
3import wx.media
4import os
5
6#----------------------------------------------------------------------
7
8class TestPanel(wx.Panel):
9 def __init__(self, parent, log):
10 self.log = log
11 wx.Panel.__init__(self, parent, -1,
12 style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN)
13
14 # Create some controls
15 self.mc = wx.media.MediaCtrl(self)
16 self.mc.SetMinSize((320,200))
17
18 btn1 = wx.Button(self, -1, "Load File")
19 self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn1)
20
21 btn2 = wx.Button(self, -1, "Load URL")
22 self.Bind(wx.EVT_BUTTON, self.OnLoadURI, btn2)
23
24 btn3 = wx.Button(self, -1, "Play")
25 self.Bind(wx.EVT_BUTTON, self.OnPlay, btn3)
26
27 btn4 = wx.Button(self, -1, "Pause")
28 self.Bind(wx.EVT_BUTTON, self.OnPause, btn4)
29
30 btn5 = wx.Button(self, -1, "Stop")
31 self.Bind(wx.EVT_BUTTON, self.OnStop, btn5)
32
33 # setup the layout
34 sizer = wx.GridBagSizer(5,5)
35 sizer.Add(self.mc, (1,1), span=(5,1))#, flag=wx.EXPAND)
36 sizer.Add(btn1, (1,3))
37 sizer.Add(btn2, (2,3))
38 sizer.Add(btn3, (3,3))
39 sizer.Add(btn4, (4,3))
40 sizer.Add(btn5, (5,3))
41 self.SetSizer(sizer)
42
43
44 def OnLoadFile(self, evt):
45 dlg = wx.FileDialog(self, message="Choose a media file",
46 defaultDir=os.getcwd(), defaultFile="",
47 style=wx.OPEN | wx.CHANGE_DIR )
48 if dlg.ShowModal() == wx.ID_OK:
49 path = dlg.GetPath()
50 if not self.mc.Load(path):
51 wx.MessageBox("Unable to load %s." % path,
52 "ERROR: Unsupported format?",
53 wx.ICON_ERROR | wx.OK)
54 else:
55 self.mc.SetBestFittingSize()
56 self.GetSizer().Layout()
57 dlg.Destroy()
58
59
60 def OnLoadURI(self, evt):
61 dlg = wx.TextEntryDialog(self, "URL:", "Please enter the URL of a media file",
62 "http://www.mwscomp.com/movies/grail/tim-the-enchanter.avi")
63 if dlg.ShowModal() == wx.ID_OK:
64 url = dlg.GetValue()
65 if not self.mc.LoadFromURI(url):
66 wx.MessageBox("Unable to load %s." % url,
67 "ERROR", wx.ICON_ERROR | wx.OK)
68 else:
69 self.mc.SetBestFittingSize()
70 self.GetSizer().Layout()
71 dlg.Destroy()
72
73
74 def OnPlay(self, evt):
75 self.mc.Play()
76
77 def OnPause(self, evt):
78 self.mc.Pause()
79
80 def OnStop(self, evt):
81 self.mc.Stop()
82
83
84
85
86#----------------------------------------------------------------------
87
88def runTest(frame, nb, log):
89 try:
90 win = TestPanel(nb, log)
91 return win
92 except NotImplementedError:
93 from Main import MessagePanel
94 win = MessagePanel(nb, 'wx.MediaCtrl is not available on this platform.',
95 'Sorry', wx.ICON_WARNING)
96 return win
97
98
99#----------------------------------------------------------------------
100
101
102
103overview = """<html><body>
104<h2><center>wx.MediaCtrl</center></h2>
105
9828eeb4
RD
106wx.MediaCtrl is a class that allows a way to convieniently display types of
107media, such as videos, audio files, natively through native codecs.
108
109<p>
110wx.MediaCtrl uses native backends to render media, for example on Windows
111there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
112QuickTime backend.
113<p>
114wx.MediaCtrl is not currently available on unix systems.
115
256c055e
RD
116</body></html>
117"""
118
119
120
121if __name__ == '__main__':
122 import sys,os
123 import run
124 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
125