def SetTitle(self, title=None): """Set the title to something.""" if application.stream is None: if title is None: title = 'Not Playing' mode = None else: if title is None: title = str(application.track) if application.stream.is_stopped: mode = 'Stopped' elif application.stream.is_paused: mode = 'Paused' else: mode = 'Playing' title = '%s%s' % (title, ' [{}]'.format(mode) if mode is not None else '') tracks.storage.now_playing = title tracks.storage.previous = get_previous() if tracks.storage.previous is None: tracks.storage.previous = 'No Track' else: tracks.storage.previous = str(tracks.storage.previous) tracks.storage.next = get_next(remove=False) if tracks.storage.next is None: tracks.storage.next = 'No Track' else: tracks.storage.next = str(tracks.storage.next) super(MainFrame, self).SetTitle('%s - %s' % (application.name, title))
def SetTitle(self, title=None): """Set the title to something.""" if application.stream is None: if title is None: title = 'Not Playing' mode = None else: if title is None: title = str(application.track) if application.stream.is_stopped: mode = 'Stopped' elif application.stream.is_paused: mode = 'Paused' else: mode = 'Playing' title = '%s%s' % (title, ' [{}]'.format(mode) if mode is not None else '') tracks.storage.now_playing = title tracks.storage.previous = get_previous() if tracks.storage.previous is None: tracks.storage.previous = 'No Track' else: tracks.storage.previous = str(tracks.storage.previous) tracks.storage.next = get_next(remove = False) if tracks.storage.next is None: tracks.storage.next = 'No Track' else: tracks.storage.next = str(tracks.storage.next) super(MainFrame, self).SetTitle('%s - %s' % (application.name, title))
def play_manager(self, event): """Manage the currently playing track.""" while self.commands: cmd = self.commands.pop() logger.info('Calling command %s.', cmd) try: wx.CallAfter(cmd) except Exception as e: logger.exception(e) try: load_playlist(self.playlist_action.playlists.pop(0)) except AttributeError: # There is either no playlist action, or there are no playlists to load yet. pass except IndexError: # There are no more playlists. Let's rock! a = self.playlist_action self.playlist_action = None a.complete() if self.autoload: t = self.autoload.pop(0) if isinstance(t, dict): self.load_result(t) else: self.add_result(t) self.update_status() if isinstance( application.track, URLStream ) and not self.getting_stream_title: self.getting_stream_title = True Thread( target=self.set_title_from_stream, args=[application.track.url] ).start() if application.stream is not None: try: pos = application.stream.get_position() except AssertionError: pos = 0.0 try: length = application.stream.get_length() except BassError: length = pos * 2 # It's an internet stream. if not self.position.HasFocus() and length: self.position.SetValue(int(pos * (100 / length))) stop_after = self.stop_after.IsChecked() if (length - pos) <= (0 if stop_after else config.sound['fadeout_threshold']): if stop_after: n = None else: n = get_next(remove = True) play(n) else: self.position.SetValue(0)
def play_manager(self, event): """Manage the currently playing track.""" while self.commands: cmd = self.commands.pop() logger.info('Calling command %s.', cmd) try: wx.CallAfter(cmd) except Exception as e: logger.exception(e) try: load_playlist(self.playlist_action.playlists.pop(0)) except AttributeError: # There is either no playlist action, or there are no playlists to load yet. pass except IndexError: # There are no more playlists. Let's rock! a = self.playlist_action self.playlist_action = None a.complete() if self.autoload: t = self.autoload.pop(0) if isinstance(t, dict): self.load_result(t) else: self.add_result(t) self.update_status() if isinstance(application.track, URLStream) and not self.getting_stream_title: self.getting_stream_title = True Thread(target=self.set_title_from_stream, args=[application.track.url]).start() if application.stream is not None: try: pos = application.stream.get_position() except AssertionError: pos = 0.0 try: length = application.stream.get_length() except BassError: length = pos * 2 # It's an internet stream. if not self.position.HasFocus() and length: self.position.SetValue(int(pos * (100 / length))) stop_after = self.stop_after.IsChecked() if (length - pos) <= (0 if stop_after else config.sound['fadeout_threshold']): if stop_after: n = None else: n = get_next(remove=True) play(n) else: self.position.SetValue(0)
def update_labels(self): """Update the labels of the previous and next buttons.""" prev = get_previous() prev = 'Previous' if prev is None else 'Previous (%s)' % prev self.previous.SetLabel('&%s' % prev) tracks.storage.previous = prev next = get_next(remove=False) next = 'Next' if next is None else 'Next (%s)' % next self.next.SetLabel('&%s' % next) tracks.storage.next = next if application.stream is not None and application.stream.is_playing: pp = PAUSE_LABEL else: pp = PLAY_LABEL tracks.storage.play_pause = pp self.play.SetLabel('&' + pp)
def update_labels(self): """Update the labels of the previous and next buttons.""" prev = get_previous() prev = 'Previous' if prev is None else 'Previous (%s)' % prev self.previous.SetLabel('&%s' % prev) tracks.storage.previous = prev next = get_next(remove = False) next = 'Next' if next is None else 'Next (%s)' % next self.next.SetLabel('&%s' % next) tracks.storage.next = next if application.stream is not None and application.stream.is_playing: pp = PAUSE_LABEL else: pp = PLAY_LABEL tracks.storage.play_pause = pp self.play.SetLabel('&' + pp)
from .base import app, jsonify, NotFound from sqlalchemy.orm.exc import NoResultFound class storage(object): """Store queries for get_info.""" playlists = [] stations = [] tracks = [] now_playing = None previous = None next = None play_pause = None track_actions = { 'previous': lambda: play(get_previous()), 'next': lambda: play(get_next()), 'play_pause': lambda: application.frame.play_pause(None), 'volume_down': lambda: set_volume(max(0, application.frame.volume.GetValue() - 5)), 'volume_up': lambda: set_volume(min(100, application.frame.volume.GetValue() + 5)) } @app.route('/play_track/<key>') def play_track(request, key): """Play the track with the given ID.""" def f(key): try: track = session.query(Track).filter(Track.key == key).one() play(track) except NoResultFound: pass # No track with that id. wx.CallAfter(f, key)
def on_next(self, event): """Play the next track.""" play(get_next(remove=True))
def __init__(self, parent): self.name = '&Play' super(PlayMenu, self).__init__() parent.Bind(wx.EVT_MENU, application.frame.play_pause, self.Append(wx.ID_ANY, '&Play / Pause', 'Play or pause the current track.')) parent.Bind(wx.EVT_MENU, application.frame.do_stop, self.Append(wx.ID_ANY, '&Stop\tCTRL+.', 'Stop the currently playing track.')) stop_after = self.AppendCheckItem(wx.ID_ANY, 'Stop &After Current Track\tCTRL+SHIFT+.', 'Stop when the currently playing track has finished playing.') stop_after.Check(config.system['stop_after']) parent.Bind(wx.EVT_MENU, lambda event: application.frame.add_command(self.do_stop_after, bool(event.GetSelection())), stop_after) if not hasattr(application.frame, 'stop_after'): application.frame.stop_after = stop_after parent.Bind(wx.EVT_MENU, lambda event: queue(application.frame.get_result()) if application.frame.get_result() is not None else wx.Bell(), self.Append(wx.ID_ANY, '&Queue Item\tSHIFT+RETURN', 'Add the currently focused track to the play queue.')) parent.Bind(wx.EVT_MENU, application.frame.on_previous, self.Append(wx.ID_ANY, '&Previous Track%s\tCTRL+LEFT' % ('' if get_previous() is None else ' (%s)' % (get_previous())), 'Play the previous track.')) parent.Bind(wx.EVT_MENU, application.frame.on_next, self.Append(wx.ID_ANY, '&Next Track%s\tCTRL+RIGHT' % ('' if get_next(False) is None else ' (%s)' % (get_next(remove = False))), 'Play the next track.')) parent.Bind(wx.EVT_MENU, lambda event: set_volume(max(0, application.frame.volume.GetValue() - 5)), self.Append(wx.ID_ANY, 'Volume &Down\tCTRL+DOWN', 'Reduce volume by 5%.')) parent.Bind(wx.EVT_MENU, lambda event: set_volume(min(100, application.frame.volume.GetValue() + 5)), self.Append(wx.ID_ANY, 'Volume &Up\tCTRL+UP', 'Increase volume by 5%.')) repeat_menu = wx.Menu() self.repeat_off = repeat_menu.AppendRadioItem(wx.ID_ANY, '&Off', 'No repeat.') self.repeat_track = repeat_menu.AppendRadioItem(wx.ID_ANY, '&Track', 'Repeat just the currently playing track.') self.repeat_all = repeat_menu.AppendRadioItem(wx.ID_ANY, '&All', 'Repeat all.') wx.CallAfter([self.repeat_off, self.repeat_track, self.repeat_all][config.system['repeat']].Check, True) for value, option in enumerate(['repeat_off', 'repeat_track', 'repeat_all']): control = getattr(self, option) parent.Bind(wx.EVT_MENU, lambda event, value = value: config.system.repeat.set(value), control) if not hasattr(application.frame, option): setattr(application.frame, option, control) self.AppendSubMenu(repeat_menu, '&Repeat')#, 'Repeat options') shuffle = self.AppendCheckItem(wx.ID_ANY, '&Shuffle\tCTRL+H', 'Play all tracks shuffled.') parent.Bind(wx.EVT_MENU, lambda event: application.frame.add_command(self.do_shuffle, bool(event.GetSelection())), shuffle) shuffle.Check(config.system['shuffle']) if not hasattr(application.frame, 'shuffle'): application.frame.shuffle = shuffle parent.Bind(wx.EVT_MENU, parent.cast_result, self.Append(wx.ID_ANY, '&Cast...\tF11', 'Cast the currently-focused item'))
def on_next(self, event): """Play the next track.""" play(get_next(remove = True))