Beispiel #1
0
    def __init__(self, app):
        self.app = app
        self.songlist = SongListBox(app)

        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])
Beispiel #2
0
    def __init__(self, app):
        self.app = app

        self.playlistlist = PlaylistListBox(app, '\u2630')
        self.songlist = SongListBox(app)
        self.songlist.set_placeholder('\n Select a playlist.')

        urwid.connect_signal(self.playlistlist, 'activate',
                             self.playlist_activated)

        super(PlaylistsPage, self).__init__([self.playlistlist, self.songlist])
Beispiel #3
0
    def __init__(self, app):
        self.app = app

        self.stationlist = StationListBox(app, '\u2708')
        self.songlist = SongListBox(app)
        self.songlist.set_placeholder('\n Select a station.')

        urwid.connect_signal(self.stationlist, 'activate',
                             self.station_activated)

        super(StationsPage, self).__init__([self.stationlist, self.songlist])
Beispiel #4
0
    def __init__(self, app):
        self.app = app
        self.songlist = SongListBox(app)
        self._focus_position = 0
        self.search_box = SearchBox()

        urwid.connect_signal(self.search_box, 'search-requested',
                             self.perform_search)

        super(SearchPage, self).__init__([('pack', self.search_box),
                                          ('pack', urwid.Divider(u'\u2500')),
                                          self.songlist])
Beispiel #5
0
    def __init__(self, app):
        self.app = app
        self.artistlist = ArtistListBox(app, '\U0001F399')
        self.albumlist = AlbumListBox(app)
        self.songlist = SongListBox(app)
        self.songlist.set_placeholder('\n Select an artist')

        urwid.connect_signal(self.artistlist, 'activate', self.item_activated)
        urwid.connect_signal(self.albumlist, 'activate', self.album_activate)

        super(ArtistsPage,
              self).__init__([self.artistlist, self.albumlist, self.songlist])
Beispiel #6
0
class ArtistsPage(urwid.Columns, AbstractPage):
    """
    Playlists page.
    Contains two parts:
    - List of artists
    - List of albums by selected artist
    """
    @property
    def name(self):
        return 'Artists'

    @property
    def key(self):
        return 2

    @property
    def slug(self):
        """
        Return page ID (`str`)
        """
        return "artists"

    def __init__(self, app):
        self.app = app
        self.artistlist = ArtistListBox(app, icon='\U0001F399')
        self.albumlist = AlbumListBox(app, placeholder='Select an artist')
        self.songlist = SongListBox(app)
        self.songlist.set_placeholder('\n Select an album')

        urwid.connect_signal(self.artistlist, 'activate', self.item_activated)
        urwid.connect_signal(self.albumlist, 'activate', self.album_activated)

        gp.parsed_songs += self.populate
        gp.caches_invalidated += self.populate

        super(ArtistsPage,
              self).__init__([self.artistlist, self.albumlist, self.songlist])

    def populate(self):
        self.artistlist.populate(gp.cached_artists)
        self.app.redraw()

    def item_activated(self, artist):
        if artist.albums is not None:
            self.albumlist.populate(artist.albums)

    def album_activated(self, album):
        self.songlist.populate(album.tracks)
        self.app.redraw()

    def activate(self):
        pass
Beispiel #7
0
    def __init__(self, app):
        self.app = app
        self.albumslist = AlbumListBox(app, '\u2630')
        self.songlist = SongListBox(app)
        self.songlist.set_placeholder('\n Select an album.')

        gp.parsed_songs += self.populate
        gp.caches_invalidated += self.populate

        urwid.connect_signal(self.albumslist, 'activate',
                             self.playlist_activated)

        super(AlbumsPage, self).__init__([self.albumslist, self.songlist])
Beispiel #8
0
class AlbumsPage(urwid.Columns, AbstractPage):
    """
    Playlists page.

    Contains two parts:

    - List of playlists (:class:`.PlaylistListBox`)
    - List of songs in selected playlist (:class:`clay:songlist:SongListBox`)
    """
    @property
    def name(self):
        return 'Albums'

    @property
    def key(self):
        return 3

    @property
    def slug(self):
        """
        Return page ID (str).
        """
        return "albums"

    def __init__(self, app):
        self.app = app
        self.albumslist = AlbumListBox(app, '\u2630')
        self.songlist = SongListBox(app)
        self.songlist.set_placeholder('\n Select an album.')

        gp.parsed_songs += self.populate
        gp.caches_invalidated += self.populate

        urwid.connect_signal(self.albumslist, 'activate',
                             self.playlist_activated)

        super(AlbumsPage, self).__init__([self.albumslist, self.songlist])

    def populate(self, *_):
        self.albumslist.populate(gp.cached_albums)
        self.app.redraw()

    def playlist_activated(self, album):
        """
        Called when specific playlist is selected.
        Populates songlist with tracks from the selected playlist.
        """
        self.songlist.populate(album.tracks)

    def activate(self):
        pass
Beispiel #9
0
    def __init__(self, app):
        self.app = app
        self.artistlist = ArtistListBox(app, icon='\U0001F399')
        self.albumlist = AlbumListBox(app, placeholder='Select an artist')
        self.songlist = SongListBox(app)
        self.songlist.set_placeholder('\n Select an album')

        urwid.connect_signal(self.artistlist, 'activate', self.item_activated)
        urwid.connect_signal(self.albumlist, 'activate', self.album_activated)

        gp.parsed_songs += self.populate
        gp.caches_invalidated += self.populate

        super(ArtistsPage,
              self).__init__([self.artistlist, self.albumlist, self.songlist])
Beispiel #10
0
class PlaylistsPage(urwid.Columns, AbstractPage):
    """
    Playlists page.

    Contains two parts:

    - List of playlists (:class:`.PlaylistListBox`)
    - List of songs in selected playlist (:class:`clay:songlist:SongListBox`)
    """
    @property
    def name(self):
        return 'Playlists'

    @property
    def key(self):
        return 4

    @property
    def slug(self):
        """
        Return page ID (str).
        """
        return "playlists"

    def __init__(self, app):
        self.app = app

        self.playlistlist = PlaylistListBox(app, '\u2630')
        self.songlist = SongListBox(app)
        self.songlist.set_placeholder('\n Select a playlist.')

        urwid.connect_signal(self.playlistlist, 'activate',
                             self.playlist_activated)

        super(PlaylistsPage, self).__init__([self.playlistlist, self.songlist])

    def playlist_activated(self, playlist):
        """
        Called when specific playlist is selected.
        Populates songlist with tracks from the selected playlist.
        """
        self.songlist.populate(playlist.tracks)

    def activate(self):
        pass
Beispiel #11
0
class QueuePage(urwid.Columns, AbstractPage):
    """
    Queue page.
    """
    @property
    def name(self):
        return 'Queue'

    @property
    def key(self):
        return 6

    @property
    def slug(self):
        """
        Return page ID (str).
        """
        return "queue"

    def __init__(self, app):
        self.app = app
        self.songlist = SongListBox(app)

        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])

    def queue_changed(self):
        """
        Called when player queue is changed.
        Updates this queue widget.
        """
        self.songlist.populate(player.get_queue_tracks())

    def track_appended(self, track):
        """
        Called when new track is appended to the player queue.
        Appends track to this queue widget.
        """
        self.songlist.append_track(track)

    def track_removed(self, track):
        """
        Called when a track is removed from the player queue.
        Removes track from this queue widget.
        """
        self.songlist.remove_track(track)

    def activate(self):
        pass
Beispiel #12
0
class StationsPage(urwid.Columns, AbstractPage):
    """
    Stations page.

    Contains two parts:

    - List of stations (:class:`.StationBox`)
    - List of songs in selected station (:class:`clay:songlist:SongListBox`)
    """
    @property
    def name(self):
        return 'Stations'

    @property
    def key(self):
        return 3

    @property
    def slug(self):
        """
        Return page ID (str).
        """
        return "stations"

    def __init__(self, app):
        self.app = app

        self.stationlist = StationListBox(app, '\u2708')
        self.songlist = SongListBox(app)
        self.songlist.set_placeholder('\n Select a station.')

        urwid.connect_signal(self.stationlist, 'activate',
                             self.station_activated)

        super(StationsPage, self).__init__([self.stationlist, self.songlist])

    def station_activated(self, station):
        """
        Called when specific station  is selected.
        Requests fetching of station tracks
        """
        self.songlist.set_placeholder(u'\n \uf01e Loading station tracks...')
        station.load_tracks_async(callback=self.on_station_loaded)

    def on_station_loaded(self, station, error):
        """
        Called when station  tracks  fetch completes.
        Populates songlist with tracks from the selected station.
        """
        if error:
            notification_area.notify('Failed to get station tracks: {}'.format(
                str(error)))

        self.songlist.populate(station.get_tracks())
        self.app.redraw()

    def activate(self):
        pass
Beispiel #13
0
class SearchPage(urwid.Pile, AbstractPage):
    """
    Search page.

    Allows to perform searches & displays search results.
    """
    @property
    def append(self):
        return True

    @property
    def name(self):
        return 'Search'

    @property
    def key(self):
        return 6

    @property
    def slug(self):
        """
        Return page ID (str).
        """
        return "search"

    def __init__(self, app):
        self.app = app
        self.songlist = SongListBox(app)
        self._focus_position = 0
        self.search_box = SearchBox()

        urwid.connect_signal(self.search_box, 'search-requested',
                             self.perform_search)

        super(SearchPage, self).__init__([('pack', self.search_box),
                                          ('pack', urwid.Divider(u'\u2500')),
                                          self.songlist])

    def perform_search(self, query):
        """
        Search tracks by query.
        """
        self.songlist.set_placeholder(
            u' \U0001F50D Searching for "{}"...'.format(query))
        gp.search_async(query, callback=self.search_finished)

    def search_finished(self, results, error):
        """
        Populate song list with search results.
        """
        if error:
            notification_area.notify('Failed to search: {}'.format(str(error)))
        else:
            self.songlist.populate(results.get_tracks())
            self.app.redraw()

    def activate(self):
        hotkey_manager.filtering = True

    def keypress(self, size, key):
        hotkey_manager.filtering = (self.focus == self.search_box)

        if key == 'tab':
            if self.focus == self.search_box:
                self.focus_position = 2
            else:
                self.focus_position = 0
            return None
        return super(SearchPage, self).keypress(size, key)