Added controls for handling playback from the main window
This commit is contained in:
parent
9b29bb2c5c
commit
a4b73a963e
@ -27,6 +27,9 @@ class Controller(object):
|
||||
# Here we will save results for searches as song objects.
|
||||
self.results = []
|
||||
self.connect_events()
|
||||
self.timer = wx.Timer(self.window)
|
||||
self.window.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
|
||||
self.timer.Start()
|
||||
# Shows window.
|
||||
self.window.Show()
|
||||
|
||||
@ -56,9 +59,16 @@ class Controller(object):
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_volume_up, menuitem=self.window.player_volume_up)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_mute, menuitem=self.window.player_mute)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_shuffle, menuitem=self.window.player_shuffle)
|
||||
widgetUtils.connect_event(self.window.previous, widgetUtils.BUTTON_PRESSED, self.on_previous)
|
||||
widgetUtils.connect_event(self.window.play, widgetUtils.BUTTON_PRESSED, self.on_play_pause)
|
||||
widgetUtils.connect_event(self.window.stop, widgetUtils.BUTTON_PRESSED, self.on_stop)
|
||||
widgetUtils.connect_event(self.window.next, widgetUtils.BUTTON_PRESSED, self.on_next)
|
||||
self.window.Bind(wx.EVT_COMMAND_SCROLL_THUMBTRACK, self.on_set_volume, self.window.vol_slider)
|
||||
self.window.Bind(wx.EVT_COMMAND_SCROLL_CHANGED, self.on_set_volume, self.window.vol_slider)
|
||||
self.window.Bind(wx.EVT_COMMAND_SCROLL_THUMBTRACK, 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_CONTEXT_MENU, self.on_context)
|
||||
|
||||
pub.subscribe(self.change_status, "change_status")
|
||||
|
||||
# Event functions. These functions will call other functions in a thread and are bound to widget events.
|
||||
@ -87,7 +97,7 @@ class Controller(object):
|
||||
if player.player.player.is_playing() == 1:
|
||||
return player.player.pause()
|
||||
else:
|
||||
player.player.player.play()
|
||||
return self.on_play()
|
||||
|
||||
def on_next(self, *args, **kwargs):
|
||||
return utils.call_threaded(player.player.next)
|
||||
@ -135,6 +145,21 @@ class Controller(object):
|
||||
log.debug("downloading %s URL to %s filename" % (item.download_url, path,))
|
||||
utils.call_threaded(utils.download_file, item.download_url, path)
|
||||
|
||||
def on_set_volume(self, *args, **kwargs):
|
||||
volume = self.window.vol_slider.GetValue()
|
||||
player.player.player.audio_set_volume(volume)
|
||||
|
||||
def on_time_change(self, *args, **kwargs):
|
||||
p = self.window.time_slider.GetValue()/100000.0
|
||||
print(p)
|
||||
player.player.player.set_position(p)
|
||||
|
||||
def on_timer(self, *args, **kwargs):
|
||||
length = player.player.player.get_length()
|
||||
self.window.time_slider.SetRange(-1, length)
|
||||
time = player.player.player.get_time()
|
||||
self.window.time_slider.SetValue(time)
|
||||
|
||||
def change_status(self, status):
|
||||
""" Function used for changing the status bar from outside the main controller module."""
|
||||
self.window.change_status("{0} {1}".format(status, self.get_status_info()))
|
||||
|
@ -44,6 +44,24 @@ class mainWindow(wx.Frame):
|
||||
self.list = wx.ListBox(self.panel, wx.NewId())
|
||||
self.sizer.Add(lbl, 0, wx.ALL, 5)
|
||||
self.sizer.Add(self.list, 1, wx.EXPAND, 5)
|
||||
self.time_slider = wx.Slider(self.panel, -1, 0, 0, 1000)
|
||||
self.time_slider.SetRange(0, 1000)
|
||||
self.previous = wx.Button(self.panel, wx.NewId(), _("Previous"))
|
||||
self.play = wx.Button(self.panel, wx.NewId(), _("Play"))
|
||||
self.stop = wx.Button(self.panel, wx.NewId(), _("Stop"))
|
||||
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.play, flag=wx.RIGHT, border=5)
|
||||
box2.Add(self.stop)
|
||||
box2.Add(self.next)
|
||||
box2.Add((-1, -1), 1)
|
||||
box2.Add(self.vol_slider, flag=wx.TOP | wx.LEFT, border=5)
|
||||
self.sizer.Add(box1, flag=wx.EXPAND | wx.BOTTOM, border=10)
|
||||
self.sizer.Add(box2, flag=wx.EXPAND | wx.BOTTOM, border=10)
|
||||
self.panel.SetSizer(self.sizer)
|
||||
self.SetClientSize(self.sizer.CalcMin())
|
||||
self.Layout()
|
||||
|
Loading…
Reference in New Issue
Block a user