]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/MediaCtrl.py
restored accidentally removed code which deselects the previously selected button...
[wxWidgets.git] / wxPython / demo / MediaCtrl.py
1
2 import wx
3 import wx.media
4 import os
5
6 from Main import opj
7
8 #----------------------------------------------------------------------
9
10 class 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 self.mc = wx.media.MediaCtrl(self, -1, opj("data/testmovie.mpg"),
18 style=wx.SIMPLE_BORDER)
19 self.mc.SetBackgroundColour("black")
20 #self.mc.SetMinSize((320,200))
21 self.mc.Stop()
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 btn5 = wx.ToggleButton(self, -1, "Loop")
36 self.Bind(wx.EVT_TOGGLEBUTTON, self.OnLoopToggle, btn5)
37
38
39 # setup the layout
40 sizer = wx.GridBagSizer(5,5)
41 sizer.Add(self.mc, (1,1), span=(5,1))#, flag=wx.EXPAND)
42 sizer.Add(btn1, (1,3))
43 sizer.Add(btn2, (2,3))
44 sizer.Add(btn3, (3,3))
45 sizer.Add(btn4, (4,3))
46 sizer.Add(btn5, (5,3))
47 self.SetSizer(sizer)
48
49
50 def OnLoadFile(self, evt):
51 dlg = wx.FileDialog(self, message="Choose a media file",
52 defaultDir=os.getcwd(), defaultFile="",
53 style=wx.OPEN | wx.CHANGE_DIR )
54 if dlg.ShowModal() == wx.ID_OK:
55 path = dlg.GetPath()
56 if not self.mc.Load(path):
57 wx.MessageBox("Unable to load %s: Unsupported format?" % path,
58 "ERROR",
59 wx.ICON_ERROR | wx.OK)
60 else:
61 self.mc.SetBestFittingSize()
62 self.GetSizer().Layout()
63 dlg.Destroy()
64
65
66 def OnLoopToggle(self, evt):
67 btn = evt.GetEventObject()
68 self.mc.Loop(btn.GetValue())
69
70
71 def OnPlay(self, evt):
72 self.mc.Play()
73
74 def OnPause(self, evt):
75 self.mc.Pause()
76
77 def OnStop(self, evt):
78 self.mc.Stop()
79
80
81
82
83 #----------------------------------------------------------------------
84
85 def runTest(frame, nb, log):
86 try:
87 win = TestPanel(nb, log)
88 return win
89 except NotImplementedError:
90 from Main import MessagePanel
91 win = MessagePanel(nb, 'wx.MediaCtrl is not available on this platform.',
92 'Sorry', wx.ICON_WARNING)
93 return win
94
95
96 #----------------------------------------------------------------------
97
98
99
100 overview = """<html><body>
101 <h2><center>wx.MediaCtrl</center></h2>
102
103 wx.MediaCtrl is a class that allows a way to convieniently display types of
104 media, such as videos, audio files, natively through native codecs.
105
106 <p>
107 wx.MediaCtrl uses native backends to render media, for example on Windows
108 there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
109 QuickTime backend.
110 <p>
111 wx.MediaCtrl is not currently available on unix systems.
112
113 </body></html>
114 """
115
116
117
118 if __name__ == '__main__':
119 import sys,os
120 import run
121 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
122