Responde to changes in track position and volume

This commit is contained in:
Manuel Cortez 2018-02-22 13:58:28 -06:00
parent b2539ba697
commit 7f693fe9b2
2 changed files with 37 additions and 32 deletions

View File

@ -29,7 +29,8 @@ class Controller(object):
self.connect_events() self.connect_events()
self.timer = wx.Timer(self.window) self.timer = wx.Timer(self.window)
self.window.Bind(wx.EVT_TIMER, self.on_timer, self.timer) self.window.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
self.timer.Start() self.timer.Start(75)
self.window.vol_slider.SetValue(player.player.volume)
# Shows window. # Shows window.
self.window.Show() self.window.Show()
@ -69,6 +70,7 @@ class Controller(object):
self.window.Bind(wx.EVT_COMMAND_SCROLL_CHANGED, self.on_time_change, self.window.time_slider) self.window.Bind(wx.EVT_COMMAND_SCROLL_CHANGED, self.on_time_change, self.window.time_slider)
self.window.list.Bind(wx.EVT_LISTBOX_DCLICK, self.on_play) self.window.list.Bind(wx.EVT_LISTBOX_DCLICK, self.on_play)
self.window.list.Bind(wx.EVT_CONTEXT_MENU, self.on_context) self.window.list.Bind(wx.EVT_CONTEXT_MENU, self.on_context)
self.window.Bind(wx.EVT_CLOSE, self.on_close)
pub.subscribe(self.change_status, "change_status") pub.subscribe(self.change_status, "change_status")
# Event functions. These functions will call other functions in a thread and are bound to widget events. # Event functions. These functions will call other functions in a thread and are bound to widget events.
@ -97,7 +99,7 @@ class Controller(object):
if player.player.player.is_playing() == 1: if player.player.player.is_playing() == 1:
return player.player.pause() return player.player.pause()
else: else:
return self.on_play() return player.player.player.play()
def on_next(self, *args, **kwargs): def on_next(self, *args, **kwargs):
return utils.call_threaded(player.player.next) return utils.call_threaded(player.player.next)
@ -114,10 +116,10 @@ class Controller(object):
player.player.stop() player.player.stop()
def on_volume_down(self, *args, **kwargs): def on_volume_down(self, *args, **kwargs):
player.player.volume = player.player.volume-5 self.window.vol_slider.SetValue(self.window.volume_slider.GetValue()-5)
def on_volume_up(self, *args, **kwargs): def on_volume_up(self, *args, **kwargs):
player.player.volume = player.player.volume+5 self.window.vol_slider.SetValue(self.window.volume_slider.GetValue()-5)
def on_mute(self, *args, **kwargs): def on_mute(self, *args, **kwargs):
player.player.volume = 0 player.player.volume = 0
@ -149,16 +151,19 @@ class Controller(object):
volume = self.window.vol_slider.GetValue() volume = self.window.vol_slider.GetValue()
player.player.player.audio_set_volume(volume) player.player.player.audio_set_volume(volume)
def on_time_change(self, *args, **kwargs): def on_time_change(self, event, *args, **kwargs):
p = self.window.time_slider.GetValue()/100000.0 p = event.GetPosition()
print(p) player.player.player.set_position(p/100.0)
player.player.player.set_position(p) event.Skip()
def on_timer(self, *args, **kwargs): def on_timer(self, *args, **kwargs):
length = player.player.player.get_length() if not self.window.time_slider.HasFocus():
self.window.time_slider.SetRange(-1, length) progress = player.player.player.get_position()*100
time = player.player.player.get_time() self.window.time_slider.SetValue(progress)
self.window.time_slider.SetValue(time)
def on_close(self, event):
self.timer.Stop()
event.Skip()
def change_status(self, status): def change_status(self, status):
""" Function used for changing the status bar from outside the main controller module.""" """ Function used for changing the status bar from outside the main controller module."""

View File

@ -36,36 +36,36 @@ class mainWindow(wx.Frame):
self.search = wx.Button(self.panel, wx.NewId(), _("Search")) self.search = wx.Button(self.panel, wx.NewId(), _("Search"))
self.search.SetDefault() self.search.SetDefault()
box = wx.BoxSizer(wx.HORIZONTAL) box = wx.BoxSizer(wx.HORIZONTAL)
box.Add(lbl2, 0, wx.ALL, 20) box.Add(lbl2, 0, wx.GROW)
box.Add(self.text, 0, wx.ALL, 5) box.Add(self.text, 1, wx.GROW)
box.Add(self.search, 0, wx.ALL, 5) box.Add(self.search, 0, wx.GROW)
self.sizer.Add(box, 0, wx.ALL, 5) self.sizer.Add(box, 0, wx.GROW)
lbl = wx.StaticText(self.panel, wx.NewId(), _("Results")) lbl = wx.StaticText(self.panel, wx.NewId(), _("Results"))
self.list = wx.ListBox(self.panel, wx.NewId()) self.list = wx.ListBox(self.panel, wx.NewId())
self.sizer.Add(lbl, 0, wx.ALL, 5) self.sizer.Add(lbl, 0, wx.GROW)
self.sizer.Add(self.list, 1, wx.EXPAND, 5) self.sizer.Add(self.list, 1, wx.GROW)
self.time_slider = wx.Slider(self.panel, -1, 0, 0, 1000) box1 = wx.BoxSizer(wx.HORIZONTAL)
self.time_slider.SetRange(0, 1000) box2 = wx.BoxSizer(wx.HORIZONTAL)
box1.Add(wx.StaticText(self.panel, wx.NewId(), _("Position")), 0, wx.GROW)
self.time_slider = wx.Slider(self.panel, -1)
box1.Add(self.time_slider, 1, wx.GROW)
box1.Add(wx.StaticText(self.panel, wx.NewId(), _("Volume")), 0, wx.GROW)
self.vol_slider = wx.Slider(self.panel, -1, 0, 0, 100, size=(100, -1))
box1.Add(self.vol_slider, 1, wx.GROW)
self.previous = wx.Button(self.panel, wx.NewId(), _("Previous")) self.previous = wx.Button(self.panel, wx.NewId(), _("Previous"))
self.play = wx.Button(self.panel, wx.NewId(), _("Play")) self.play = wx.Button(self.panel, wx.NewId(), _("Play"))
self.stop = wx.Button(self.panel, wx.NewId(), _("Stop")) self.stop = wx.Button(self.panel, wx.NewId(), _("Stop"))
self.next = wx.Button(self.panel, wx.NewId(), _("Next")) self.next = wx.Button(self.panel, wx.NewId(), _("Next"))
self.vol_slider = wx.Slider(self.panel, -1, 0, 0, 100, size=(100, -1))
box1 = wx.BoxSizer(wx.HORIZONTAL)
box2 = wx.BoxSizer(wx.HORIZONTAL)
box1.Add(self.time_slider, 1)
box2.Add(self.previous) box2.Add(self.previous)
box2.Add(self.play, flag=wx.RIGHT, border=5) box2.Add(self.play, flag=wx.RIGHT, border=5)
box2.Add(self.stop) box2.Add(self.stop)
box2.Add(self.next) box2.Add(self.next)
box2.Add((-1, -1), 1) self.sizer.Add(box1, 0, wx.GROW)
box2.Add(self.vol_slider, flag=wx.TOP | wx.LEFT, border=5) self.sizer.Add(box2, 1, wx.GROW)
self.sizer.Add(box1, flag=wx.EXPAND | wx.BOTTOM, border=10) self.panel.SetSizerAndFit(self.sizer)
self.sizer.Add(box2, flag=wx.EXPAND | wx.BOTTOM, border=10) # self.SetClientSize(self.sizer.CalcMin())
self.panel.SetSizer(self.sizer) # self.Layout()
self.SetClientSize(self.sizer.CalcMin()) # self.SetSize(self.GetBestSize())
self.Layout()
self.SetSize(self.GetBestSize())
def change_status(self, status): def change_status(self, status):
self.sb.SetStatusText(status) self.sb.SetStatusText(status)