Listified artists view

This commit is contained in:
Sumner Evans
2019-08-01 23:11:17 -06:00
parent 9a48fc7481
commit c84ddcd476
3 changed files with 105 additions and 13 deletions

View File

@@ -10,7 +10,8 @@
padding: 0; padding: 0;
} }
#playlist-list-spinner:checked { #playlist-list-spinner:checked,
#artist-list-spinner:checked {
margin: 10px; margin: 10px;
padding: 0px; padding: 0px;
} }

View File

@@ -4,7 +4,7 @@ from typing import List, Union, Optional
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, Gio from gi.repository import Gtk, GObject, Pango
from libremsonic.state_manager import ApplicationState from libremsonic.state_manager import ApplicationState
from libremsonic.cache_manager import CacheManager from libremsonic.cache_manager import CacheManager
@@ -22,6 +22,15 @@ from libremsonic.server.api_objects import (
from .albums import AlbumsGrid from .albums import AlbumsGrid
class ArtistModel(GObject.Object):
def __init__(self, id, name, cover_art, album_count=0):
self.id = id
self.name = name
self.cover_art = cover_art
self.album_count = album_count
super().__init__()
class ArtistsPanel(Gtk.Paned): class ArtistsPanel(Gtk.Paned):
"""Defines the arist panel.""" """Defines the arist panel."""
@@ -36,20 +45,101 @@ class ArtistsPanel(Gtk.Paned):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
Gtk.Paned.__init__(self, orientation=Gtk.Orientation.HORIZONTAL) Gtk.Paned.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
# self.pack1(playlist_list_vbox, False, False) self.selected_artist = None
self.pack2(ArtistDetailPanel(), True, False)
self.artist_list = ArtistList()
self.artist_list.connect('selection-changed',
self.on_list_selection_changed)
self.pack1(self.artist_list, False, False)
self.artist_detail_panel = ArtistDetailPanel()
self.pack2(self.artist_detail_panel, True, False)
def update(self, state: ApplicationState): def update(self, state: ApplicationState):
pass self.artist_list.update()
# self.artist_detail_panel.update()
def on_list_selection_changed(self, artist_list, artist):
self.artist_detail_panel.update_artist_view(artist.id)
class ArtistModel(GObject.Object): class ArtistList(Gtk.Box):
def __init__(self, id, name, cover_art, album_count=0): __gsignals__ = {
self.id = id 'selection-changed': (
self.name = name GObject.SIGNAL_RUN_FIRST,
self.cover_art = cover_art GObject.TYPE_NONE,
self.album_count = album_count (object, ),
super().__init__() ),
}
def __init__(self):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
self.artist_map = {}
list_actions = Gtk.ActionBar()
refresh = util.button_with_icon('view-refresh')
refresh.connect('clicked', lambda *a: self.update(force=True))
list_actions.pack_end(refresh)
self.add(list_actions)
list_scroll_window = Gtk.ScrolledWindow(min_content_width=220)
self.list = Gtk.ListBox(name='artist-list-listbox')
self.loading_indicator = Gtk.ListBoxRow(activatable=False,
selectable=False)
loading_spinner = Gtk.Spinner(name='artist-list-spinner', active=True)
self.loading_indicator.add(loading_spinner)
self.list.add(self.loading_indicator)
self.list.connect('row-activated', self.on_row_activated)
list_scroll_window.add(self.list)
self.pack_start(list_scroll_window, True, True, 0)
def update(self, force=False):
self.update_list(force=force)
@util.async_callback(
lambda *a, **k: CacheManager.get_artists(*a, **k),
before_download=lambda self: self.loading_indicator.show(),
on_failure=lambda self, e: self.loading_indicator.hide(),
)
def update_list(self, artists):
selected_row = self.list.get_selected_row()
selected_artist = None
if selected_row:
selected_artist = self.artist_map.get(selected_row.get_index())
# Remove everything
for row in self.list.get_children()[1:]:
self.list.remove(row)
self.playlist_map = {}
selected_idx = None
for i, artist in enumerate(artists):
# Use i + 1 because of the loading indicator in index 0.
if selected_artist and artist.id == selected_artist.id:
selected_idx = i + 1
self.artist_map[i + 1] = artist
self.list.add(
Gtk.Label(
label=artist.name,
margin=12,
halign=Gtk.Align.START,
ellipsize=Pango.EllipsizeMode.END,
max_width_chars=30,
))
if selected_idx:
row = self.list.get_row_at_index(selected_idx)
self.list.select_row(row)
self.list.show_all()
self.loading_indicator.hide()
def on_row_activated(self, listbox, row):
self.emit('selection-changed', self.artist_map[row.get_index()])
class ArtistDetailPanel(Gtk.Box): class ArtistDetailPanel(Gtk.Box):

View File

@@ -499,11 +499,12 @@ class PlaylistsPanel(Gtk.Paned):
selected_idx = None selected_idx = None
for i, playlist in enumerate(playlists): for i, playlist in enumerate(playlists):
# Use i+1 due to loading indicator # Use i+1 due to loading indicator
if playlist == selected_playlist: if selected_playlist and playlist.id == selected_playlist.id:
selected_idx = i + 1 selected_idx = i + 1
self.playlist_map[i + 1] = playlist self.playlist_map[i + 1] = playlist
self.playlist_list.insert(self.create_playlist_label(playlist), self.playlist_list.insert(self.create_playlist_label(playlist),
i + 1) i + 1)
if selected_idx: if selected_idx:
row = self.playlist_list.get_row_at_index(selected_idx) row = self.playlist_list.get_row_at_index(selected_idx)
self.playlist_list.select_row(row) self.playlist_list.select_row(row)