Change lable to 'pause' in the play button when something is playing

This commit is contained in:
Manuel Cortez 2019-04-25 08:48:19 -05:00
parent afc4c0ca1f
commit 8c03601bd2
2 changed files with 25 additions and 0 deletions

View File

@ -632,9 +632,12 @@ class audioBuffer(feedBuffer):
def connect_events(self):
widgetUtils.connect_event(self.tab.play, widgetUtils.BUTTON_PRESSED, self.play_audio)
widgetUtils.connect_event(self.tab.play_all, widgetUtils.BUTTON_PRESSED, self.play_all)
pub.subscribe(self.change_label, "playback-changed")
super(audioBuffer, self).connect_events()
def play_audio(self, *args, **kwargs):
if player.player.stream != None:
return player.player.pause()
selected = self.tab.list.get_selected()
if selected == -1:
selected = 0
@ -778,6 +781,16 @@ class audioBuffer(feedBuffer):
url = "https://vk.com/audio{user_id}_{post_id}".format(user_id=post["owner_id"], post_id=post["id"])
webbrowser.open_new_tab(url)
def change_label(self, stopped):
if hasattr(self.tab, "play"):
if stopped == False:
self.tab.play.SetLabel(_("P&ause"))
else:
self.tab.play.SetLabel(_("P&lay"))
def __del__(self):
pub.unsubscribe(self.change_label, "playback-changed")
class audioAlbum(audioBuffer):
""" this buffer was supposed to be used with audio albums
but is deprecated as VK removed its audio support for third party apps."""

View File

@ -55,6 +55,18 @@ class audioPlayer(object):
pub.subscribe(self.play_previous, "play-previous")
pub.subscribe(self.seek, "seek")
# Stopped has a special function here, hence the decorator
# when stopped will be set to True, it will send a pubsub event to inform other parts of the application about the status change.
# this is useful for changing labels between play and pause, and so on, in buttons.
@property
def stopped(self):
return self._stopped
@stopped.setter
def stopped(self, value):
self._stopped = value
pub.sendMessage("playback-changed", stopped=value)
def play(self, object, set_info=True, fresh=False):
""" Play an URl Stream.
@object dict: typically an audio object as returned by VK, with a "url" component which must be a valid URL to a media file.