From: Digital X. <dig...@us...> - 2007-03-10 17:12:53
|
Update of /cvsroot/openrpg/openrpg1/orpg/tools In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv30203/orpg/tools Modified Files: orpg_sound.py Log Message: Made it so you can play sounds if you are not connected to a server Made it so Sounds are saved in a drop down list on the Sound Toolbar so you can sounds Made it so if a sound was playing and another sound interupted it, if you switch back to the previous sound it would start back up again where it left off Added a progress bar to the Sound Toolbar Index: orpg_sound.py =================================================================== RCS file: /cvsroot/openrpg/openrpg1/orpg/tools/orpg_sound.py,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** orpg_sound.py 11 Feb 2007 03:49:36 -0000 1.22 --- orpg_sound.py 10 Mar 2007 17:12:47 -0000 1.23 *************** *** 2,28 **** from orpg.orpg_wx import * - #---------------------------------------------------------------------- - - class StaticText(wx.StaticText): - """ - A StaticText that only updates the label if it has changed, to - help reduce potential flicker since these controls would be - updated very frequently otherwise. - """ - def SetLabel(self, label): - if label <> self.GetLabel(): - wx.StaticText.SetLabel(self, label) - - #---------------------------------------------------------------------- class orpgSound(wx.Panel): def __init__(self, parent, openrpg): wx.Panel.__init__(self, parent, -1) ! self.openrpg = openrpg self.settings = openrpg.get_component('settings') # Create some controls try: ! self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER) self.mc.Hide() self.OldPlayer = False --- 2,15 ---- from orpg.orpg_wx import * class orpgSound(wx.Panel): def __init__(self, parent, openrpg): wx.Panel.__init__(self, parent, -1) ! self.parent = parent self.openrpg = openrpg self.settings = openrpg.get_component('settings') # Create some controls try: ! self.mc = wx.media.MediaCtrl(self) self.mc.Hide() self.OldPlayer = False *************** *** 41,58 **** self.stopBtn = btn3 ! self.st_name = StaticText(self, -1, size=(100,-1)) self.loopSound = False # setup the layout sizer = wx.GridBagSizer(hgap=1, vgap=1) ! sizer.Add(self.st_name, (0,0), flag=wx.EXPAND) sizer.Add(btn2, (0,1)) sizer.Add(btn3, (0,2)) sizer.AddGrowableCol(0) self.SetSizer(sizer) self.SetAutoLayout(True) self.Fit() self.Bind(wx.EVT_CLOSE, self.OnClose) self.timer = wx.Timer(self, wx.NewId()) --- 28,54 ---- self.stopBtn = btn3 ! self.playList = wx.Choice(self, wx.ID_ANY) ! self.playDict = {} ! ! ! self.slider = wx.Slider(self, -1, 0, 0, 0, size=wx.Size(300, -1)) ! self.Bind(wx.EVT_SLIDER, self.onSeek, self.slider) self.loopSound = False + self.seeking = False # setup the layout sizer = wx.GridBagSizer(hgap=1, vgap=1) ! sizer.Add(self.playList, (0,0)) sizer.Add(btn2, (0,1)) sizer.Add(btn3, (0,2)) + sizer.Add(self.slider, (0,3), flag=wx.EXPAND) sizer.AddGrowableCol(0) + sizer.AddGrowableCol(3) self.SetSizer(sizer) self.SetAutoLayout(True) self.Fit() + self.Bind(wx.EVT_CHOICE, self.PlaySelected, self.playList) self.Bind(wx.EVT_CLOSE, self.OnClose) self.timer = wx.Timer(self, wx.NewId()) *************** *** 79,90 **** os.system(unix_player + " " + sound_file) def LoadSound(self, sound_file, type="local"): (path, name) = os.path.split(sound_file) ! if type == 'remote': ! self.mc.LoadFromURI(sound_file) ! else: ! self.mc.Load(sound_file) ! self.st_name.SetLabel(name) return --- 75,124 ---- os.system(unix_player + " " + sound_file) + def onSeek(self, evt): + offset = self.slider.GetValue() + self.mc.Seek(offset) + + def PlaySelected(self, evt): + name = self.playList.GetStringSelection() + info = self.playDict[name] + sound_file = info[0] + pos = info[1] + + self.mc.Load(sound_file) + + pane = self.parent._mgr.GetPane("Sound Control Toolbar") + pane.window.SetInitialSize() + pane.BestSize(pane.window.GetEffectiveMinSize() + (0, 1)) + self.parent._mgr.Update() + + print pos + + if pos > 0: + self.seeking = True + wx.CallAfter(self.mc.Pause) + def LoadSound(self, sound_file, type="local"): + if self.mc.GetState() == wx.media.MEDIASTATE_PLAYING: + pos = self.mc.Tell() + len = self.mc.Length() + self.mc.Stop() + if (len-pos) <= 2000: + pos = 0 + pname = self.playList.GetStringSelection() + self.playDict[pname][1] = pos + (path, name) = os.path.split(sound_file) ! self.mc.Load(sound_file) ! if not self.playDict.has_key(name): ! self.playList.Append(name) ! ! pane = self.parent._mgr.GetPane("Sound Control Toolbar") ! pane.window.SetInitialSize() ! pane.BestSize(pane.window.GetEffectiveMinSize() + (0, 1)) ! self.parent._mgr.Update() ! ! self.playDict[name] = [sound_file, 0] ! self.playList.SetStringSelection(name) return *************** *** 114,123 **** self.stopBtn.Disable() if self.mc.GetState() != wx.media.MEDIASTATE_PLAYING and self.loopSound: self.mc.Play() elif self.stopBtn.IsShown(): self.playBtn.Hide() self.stopBtn.Hide() - self.Layout() return --- 148,173 ---- self.stopBtn.Disable() + self.slider.SetRange(0, self.mc.Length()) + + if not self.seeking: + self.slider.SetValue(self.mc.Tell()) + if self.mc.GetState() != wx.media.MEDIASTATE_PLAYING and self.loopSound: self.mc.Play() + + if self.seeking: + name = self.playList.GetStringSelection() + info = self.playDict[name] + + if self.mc.Tell() >= info[1]: + self.seeking = False + + else: + self.slider.SetValue(info[1]) + wx.CallAfter(self.onSeek, None) + elif self.stopBtn.IsShown(): self.playBtn.Hide() self.stopBtn.Hide() return |