Пример #1
0
    def __init__(self, app):
        # super(PlayBar, self).__init__(*args, **kwargs)
        self.app = app
        self.rotating_index = 0
        self.text = urwid.Text('', align=urwid.LEFT)
        self.flags = [
        ]
        self.progressbar = ProgressBar()

        self.shuffle_el = urwid.AttrWrap(urwid.Text(u' \u22cd SHUF '), 'flag')
        self.repeat_el = urwid.AttrWrap(urwid.Text(u' \u27f2 REP '), 'flag')

        self.infobar = urwid.Columns([
            self.text,
            ('pack', self.shuffle_el),
            # ('pack', urwid.Text(' ')),
            ('pack', self.repeat_el)
        ])
        super(PlayBar, self).__init__([
            ('pack', self.progressbar),
            ('pack', self.infobar),
        ])
        self.update()

        player = Player.get()
        player.media_position_changed += self.update
        player.media_state_changed += self.update
        player.track_changed += self.update
        player.playback_flags_changed += self.update
Пример #2
0
 def get_text(self):
     """
     Return text for display in this bar.
     """
     player = Player.get()
     track = player.get_current_track()
     if track is None:
         return u'{} {}'.format(
             meta.APP_NAME,
             meta.VERSION
         )
     progress = player.get_play_progress_seconds()
     total = player.get_length_seconds()
     return (self.get_style(), u' {} {} - {} [{:02d}:{:02d} / {:02d}:{:02d}]'.format(
         # u'|>' if player.is_playing else u'||',
         # self.get_rotating_bar(),
         u'\u2505' if player.is_loading
         else u'\u25B6' if player.is_playing
         else u'\u25A0',
         track.artist,
         track.title,
         progress // 60,
         progress % 60,
         total // 60,
         total % 60,
     ))
Пример #3
0
    def __init__(self, app):
        self.app = app

        self.current_item = None
        self.tracks = []
        self.walker = urwid.SimpleFocusListWalker([])

        player = Player.get()
        player.track_changed += self.track_changed
        player.media_state_changed += self.media_state_changed

        self.list_box = urwid.ListBox(self.walker)
        self.filter_prefix = '> '
        self.filter_query = ''
        self.filter_box = urwid.Text(self.filter_prefix)
        self.filter_info = urwid.Text('')
        self.filter_panel = urwid.Columns(
            [self.filter_box, ('pack', self.filter_info)])
        self.content = urwid.Pile([
            self.list_box,
        ])

        self.overlay = urwid.Overlay(top_w=None,
                                     bottom_w=self.content,
                                     align='center',
                                     valign='middle',
                                     width=50,
                                     height='pack')

        self._is_filtering = False
        self.popup = None

        super(SongListBox, self).__init__(body=self.content)
Пример #4
0
 def get_style():
     """
     Return the style for current playback state.
     """
     player = Player.get()
     if player.is_loading or player.is_playing:
         return 'title-playing'
     return 'title-idle'
Пример #5
0
 def __init__(self):
     self.bands = [
         Slider(index, freq)
         for index, freq
         in enumerate(Player.get().get_equalizer_freqs())
     ]
     super(Equalizer, self).__init__(
         self.bands
     )
Пример #6
0
 def item_activated(self, songitem):
     """
     Called when specific song item is activated.
     Toggles track playback state or loads entire playlist
     that contains current track into player queue.
     """
     player = Player.get()
     if songitem.is_currently_played:
         player.play_pause()
     else:
         player.load_queue(self.tracks, songitem.index)
Пример #7
0
    def __init__(self, app):
        self.app = app
        self.songlist = SongListBox(app)

        player = Player.get()
        self.songlist.populate(player.get_queue_tracks())
        player.queue_changed += self.queue_changed
        player.track_appended += self.track_appended
        player.track_removed += self.track_removed

        super(QueuePage, self).__init__([
            self.songlist
        ])
Пример #8
0
    def media_state_changed(self, is_loading, is_playing):
        """
        Called when player media state changes.
        Updates corresponding song item state (if found in this song list).
        """
        current_track = Player.get().get_current_track()
        if current_track is None:
            return

        for songitem in self.walker:
            if isinstance(songitem, urwid.Text):
                continue
            if songitem.track == current_track:
                songitem.set_state(
                    SongListItem.STATE_LOADING if is_loading else SongListItem.
                    STATE_PLAYING if is_playing else SongListItem.STATE_PAUSED)
        self.app.redraw()
Пример #9
0
 def update(self, *_):
     """
     Force update of this widget.
     Called when something unrelated to completion value changes,
     e.g. current track or playback flags.
     """
     player = Player.get()
     self.text.set_text(self.get_text())
     self.progressbar.set_progress(player.get_play_progress())
     self.progressbar.set_done_style(
         'progressbar_done'
         if player.is_playing
         else 'progressbar_done_paused'
     )
     self.shuffle_el.attr = 'flag-active' \
         if player.get_is_random() \
         else 'flag'
     self.repeat_el.attr = 'flag-active' \
         if player.get_is_repeat_one() \
         else 'flag'
     self.app.redraw()
Пример #10
0
 def tracks_to_songlist(self, tracks):
     """
     Convert list of track data items into list of :class:`.SongListItem` instances.
     """
     current_track = Player.get().get_current_track()
     items = []
     current_index = None
     for index, track in enumerate(tracks):
         songitem = SongListItem(track)
         if current_track is not None and current_track == track:
             songitem.set_state(SongListItem.STATE_LOADING)
             if current_index is None:
                 current_index = index
         urwid.connect_signal(songitem, 'activate', self.item_activated)
         urwid.connect_signal(songitem, 'append-requested',
                              self.item_append_requested)
         urwid.connect_signal(songitem, 'unappend-requested',
                              self.item_unappend_requested)
         urwid.connect_signal(songitem, 'station-requested',
                              self.item_station_requested)
         urwid.connect_signal(songitem, 'context-menu-requested',
                              self.context_menu_requested)
         items.append(songitem)
     return (items, current_index)
Пример #11
0
 def toggle_repeat_one():
     """
     Toggle repeat mode.
     """
     player = Player.get()
     player.set_repeat_one(not player.get_is_repeat_one())
Пример #12
0
 def seek_forward():
     """
     Seek 5% forward.
     """
     Player.get().seek(0.05)
Пример #13
0
 def toggle_shuffle():
     """
     Toggle random playback.
     """
     player = Player.get()
     player.set_random(not player.get_is_random())
Пример #14
0
 def next_song():
     """
     Play next song.
     """
     Player.get().next(True)
Пример #15
0
 def seek_backward():
     """
     Seek 5% backward.
     """
     Player.get().seek(-0.05)
Пример #16
0
 def seek_start():
     """
     Seek to the start of the song.
     """
     Player.get().seek_absolute(0)
Пример #17
0
 def play_pause():
     """
     Toggle play/pause.
     """
     Player.get().play_pause()
Пример #18
0
 def item_station_requested(songitem):
     """
     Called when specific item emits *station-requested* item.
     Requests new station creation.
     """
     Player.get().create_station_from_track(songitem.track)
Пример #19
0
 def queue_changed(self):
     """
     Called when player queue is changed.
     Updates this queue widget.
     """
     self.songlist.populate(Player.get().get_queue_tracks())
Пример #20
0
 def item_append_requested(songitem):
     """
     Called when specific item emits *append-requested* item.
     Appends track to player queue.
     """
     Player.get().append_to_queue(songitem.track)
Пример #21
0
 def item_unappend_requested(songitem):
     """
     Called when specific item emits *remove-requested* item.
     Removes track from player queue.
     """
     Player.get().remove_from_queue(songitem.track)
Пример #22
0
 def __init__(self, songitem):
     self.songitem = songitem
     options = [
         urwid.AttrWrap(urwid.Text(' ' + songitem.full_title), 'panel'),
         urwid.AttrWrap(
             urwid.Text(' Source: {}'.format(songitem.track.source)),
             'panel_divider'),
         urwid.AttrWrap(
             urwid.Text(' StoreID: {}'.format(songitem.track.store_id)),
             'panel_divider')
     ]
     options.append(
         urwid.AttrWrap(urwid.Divider(u'\u2500'), 'panel_divider',
                        'panel_divider_focus'))
     if not GP.get().get_track_by_id(songitem.track.id):
         options.append(
             urwid.AttrWrap(
                 urwid.Button('Add to my library',
                              on_press=self.add_to_my_library), 'panel',
                 'panel_focus'))
     else:
         options.append(
             urwid.AttrWrap(
                 urwid.Button('Remove from my library',
                              on_press=self.remove_from_my_library),
                 'panel', 'panel_focus'))
     options.append(
         urwid.AttrWrap(urwid.Divider(u'\u2500'), 'panel_divider',
                        'panel_divider_focus'))
     options.append(
         urwid.AttrWrap(
             urwid.Button('Create station', on_press=self.create_station),
             'panel', 'panel_focus'))
     options.append(
         urwid.AttrWrap(urwid.Divider(u'\u2500'), 'panel_divider',
                        'panel_divider_focus'))
     if self.songitem.track in Player.get().get_queue_tracks():
         options.append(
             urwid.AttrWrap(
                 urwid.Button('Remove from queue',
                              on_press=self.remove_from_queue), 'panel',
                 'panel_focus'))
     else:
         options.append(
             urwid.AttrWrap(
                 urwid.Button('Append to queue',
                              on_press=self.append_to_queue), 'panel',
                 'panel_focus'))
     options.append(
         urwid.AttrWrap(urwid.Divider(u'\u2500'), 'panel_divider',
                        'panel_divider_focus'))
     if self.songitem.track.cached_url is not None:
         options.append(
             urwid.AttrWrap(
                 urwid.Button('Copy URL to clipboard',
                              on_press=self.copy_url), 'panel',
                 'panel_focus'))
     options.append(
         urwid.AttrWrap(urwid.Button('Close', on_press=self.close), 'panel',
                        'panel_focus'))
     super(SongListBoxPopup, self).__init__(urwid.Pile(options))
Пример #23
0
 def update(self):
     """
     Update player equalizer & toggle redraw.
     """
     Player.get().set_equalizer_value(self.index, self.value)
     self._invalidate()
Пример #24
0
 def append_to_queue(self, _):
     """
     Appends related track to queue.
     """
     Player.get().append_to_queue(self.songitem.track)
     self.close()
Пример #25
0
 def create_station(self, _):
     """
     Create a station from this track.
     """
     Player.get().create_station_from_track(self.songitem.track)
     self.close()
Пример #26
0
 def remove_from_queue(self, _):
     """
     Removes related track from queue.
     """
     Player.get().remove_from_queue(self.songitem.track)
     self.close()