]> git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test_mediaCtrl.py
style required on wxGTK
[wxWidgets.git] / wxPython / tests / test_mediaCtrl.py
1 import wx
2 import wx.media
3 from wx.lib.mixins.inspection import InspectableApp
4
5 import os; print os.getpid(); raw_input("press enter...")
6
7 class TestFrame(wx.Frame):
8 def __init__(self, *args, **kw):
9 wx.Frame.__init__(self, *args, **kw)
10 self.CreateStatusBar()
11 pnl = wx.Panel(self)
12
13 self.mc = wx.media.MediaCtrl(pnl, size=(-1,200))
14 #self.fn = "/home/robind/smb4k/BEAST/MyVideos/SageTV/48HoursMystery-6199728-0.mpg"
15
16 self.Bind(wx.media.EVT_MEDIA_PLAY, self.OnMediaPlay, self.mc)
17 self.Bind(wx.media.EVT_MEDIA_PAUSE, self.OnMediaPause, self.mc)
18 self.Bind(wx.media.EVT_MEDIA_STOP, self.OnMediaStop, self.mc)
19 self.Bind(wx.media.EVT_MEDIA_FINISHED, self.OnMediaFinished, self.mc)
20 self.Bind(wx.media.EVT_MEDIA_LOADED, self.OnMediaLoaded, self.mc)
21
22 selectBtn = wx.Button(pnl, -1, "Select")
23 loadBtn = wx.Button(pnl, -1, "Load")
24 playBtn = wx.Button(pnl, -1, "Play")
25 pauseBtn= wx.Button(pnl, -1, "Pause")
26 stopBtn = wx.Button(pnl, -1, "Stop")
27
28 self.Bind(wx.EVT_BUTTON, self.OnBtnSelect, selectBtn)
29 self.Bind(wx.EVT_BUTTON, self.OnBtnLoad, loadBtn)
30 self.Bind(wx.EVT_BUTTON, self.OnBtnPlay, playBtn)
31 self.Bind(wx.EVT_BUTTON, self.OnBtnPause, pauseBtn)
32 self.Bind(wx.EVT_BUTTON, self.OnBtnStop, stopBtn)
33
34
35 vbox = wx.BoxSizer(wx.VERTICAL)
36 vbox.AddF(self.mc, wx.SizerFlags(1).Expand().Border(wx.ALL, 5))
37 hbox = wx.BoxSizer(wx.HORIZONTAL)
38 hbox.AddF(selectBtn, wx.SizerFlags().Border())
39 hbox.AddF(loadBtn, wx.SizerFlags().Border())
40 hbox.AddF(playBtn, wx.SizerFlags().Border())
41 hbox.AddF(pauseBtn, wx.SizerFlags().Border())
42 hbox.AddF(stopBtn, wx.SizerFlags().Border())
43 vbox.Add(hbox)
44 pnl.SetSizer(vbox)
45
46 sizer = wx.BoxSizer()
47 sizer.AddF(pnl, wx.SizerFlags(1).Expand())
48 self.SetSizer(sizer)
49 wx.CallLater(200, self.SetClientSize, pnl.GetBestSize())
50
51 self.timer = wx.Timer(self)
52 self.Bind(wx.EVT_TIMER, self.OnShowStatus)
53 self.timer.Start(500)
54
55
56 def OnBtnSelect(self, evt):
57 name = wx.FileSelector("Choose media file")
58 if name:
59 self.fn = name
60
61 def OnBtnLoad(self, evt):
62 print "Loading %s..." % self.fn
63 print "Load:", self.mc.Load(self.fn)
64
65 def OnBtnPlay(self, evt):
66 print "Play:", self.mc.Play()
67
68 def OnBtnPause(self, evt):
69 print "Pause:", self.mc.Pause()
70
71 def OnBtnStop(self, evt):
72 print "Stop:", self.mc.Stop()
73
74
75 def OnShowStatus(self, evt):
76 current = self.mc.Tell()
77 length = self.mc.Length()
78
79 dl_current = self.mc.GetDownloadProgress()
80 dl_length = self.mc.GetDownloadTotal()
81
82 cw,ch = self.mc.GetSize()
83 bw,bh = self.mc.GetBestSize()
84
85 vol = self.mc.GetVolume()
86
87 stateMap = { wx.media.MEDIASTATE_PLAYING : "Playing",
88 wx.media.MEDIASTATE_PAUSED : "Paused",
89 wx.media.MEDIASTATE_STOPPED : "Stopped", }
90 state = stateMap.get(self.mc.GetState(), "Other")
91
92 st = "Size:%d,%d BSize:%d,%d Pos:%d/%d DL:%d/%d V:%d %s" % (
93 cw,ch, bw,bh, current, length, dl_current, dl_length, vol*100, state)
94
95 self.SetStatusText(st)
96
97
98
99 def OnMediaPlay(self, evt):
100 print "OnMediaPlay"
101
102 def OnMediaPause(self, evt):
103 print "OnMediaPause"
104
105 def OnMediaStop(self, evt):
106 print "OnMediaStop"
107
108 def OnMediaFinished(self, evt):
109 print "OnMediaFinished"
110
111 def OnMediaLoaded(self, evt):
112 print "OnMediaLoaded"
113
114
115
116 app = InspectableApp(False)
117 frm = TestFrame(None, title="simple wxMediaCtrl test")
118 frm.Show()
119 app.MainLoop()
120