From fc505f26c002546d7895dc1b01962ad903861de3 Mon Sep 17 00:00:00 2001 From: Matthias Meulien Date: Sun, 8 Dec 2024 23:11:34 +0100 Subject: [PATCH] Information page displays artist name and album image Refs: #172 --- NEWS.rst | 3 + argos/ui/album_details_box.ui | 107 ++++++++++++++++++++++++++++--- argos/widgets/albumdetailsbox.py | 61 ++++++++++++++---- 3 files changed, 149 insertions(+), 22 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index ed0c7c7..e006e27 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -14,6 +14,9 @@ The format is based on `Keep a Changelog Added ----- +- Information page displays artist name and album image + `#172 `_ + Changed ------- diff --git a/argos/ui/album_details_box.ui b/argos/ui/album_details_box.ui index 9faab7c..d807ebc 100644 --- a/argos/ui/album_details_box.ui +++ b/argos/ui/album_details_box.ui @@ -182,12 +182,42 @@ True none - + + True False - start - True - True + 5 + 5 + + + True + False + start + True + True + True + + + 0 + 1 + + + + + True + False + start + start + True + True + end + True + + + 0 + 0 + + @@ -210,12 +240,73 @@ True none - + + True False - start - True - True + 5 + 5 + + + True + False + start + start + True + True + end + True + + + 0 + 0 + + + + + album-information-image + True + False + end + start + 0 + + + 1 + 0 + 2 + + + + + True + False + start + True + True + True + + + 0 + 2 + 2 + + + + + True + False + start + start + True + end + True + + + 0 + 1 + + diff --git a/argos/widgets/albumdetailsbox.py b/argos/widgets/albumdetailsbox.py index 709aeb9..f8e1250 100644 --- a/argos/widgets/albumdetailsbox.py +++ b/argos/widgets/albumdetailsbox.py @@ -21,10 +21,12 @@ LOGGER = logging.getLogger(__name__) _ALBUM_IMAGE_SIZE = 200 +_SMALL_ALBUM_IMAGE_SIZE = 80 _MISSING_INFO_MSG = _("Information not available") _MISSING_INFO_MSG_WITH_MARKUP = f"""{_MISSING_INFO_MSG}""" _INFO_TITLE_WITH_MARKUP = """{title}""" +_INFO_SUBTITLE_WITH_MARKUP = """{subtitle}""" @Gtk.Template(resource_path="/io/github/orontee/Argos/ui/album_details_box.ui") @@ -58,9 +60,13 @@ class AlbumDetailsBox(Gtk.Box): information_button: Gtk.ToggleButton = Gtk.Template.Child() information_stack: Gtk.Stack = Gtk.Template.Child() - album_information_label: Gtk.Label = Gtk.Template.Child() album_information_viewport: Gtk.Viewport = Gtk.Template.Child() + album_information_title_label: Gtk.Label = Gtk.Template.Child() + album_information_subtitle_label: Gtk.Label = Gtk.Template.Child() + album_information_image: Gtk.Image = Gtk.Template.Child() + album_information_label: Gtk.Label = Gtk.Template.Child() artist_information_label: Gtk.Label = Gtk.Template.Child() + artist_information_title_label: Gtk.Label = Gtk.Template.Child() artist_information_viewport: Gtk.Viewport = Gtk.Template.Child() uri = GObject.Property(type=str, default="") @@ -92,9 +98,6 @@ def __init__(self, application: Gtk.Application): ) self.track_selection_button.set_menu_model(track_selection_menu) - self.album_information_label.set_selectable(True) - self.artist_information_label.set_selectable(True) - self.set_sensitive(self._model.server_reachable and self._model.connected) for widget in ( @@ -247,16 +250,26 @@ def _update_length_label(self, length: Optional[int]) -> None: self.length_label.show_now() def _update_album_image(self, image_path: Optional[Path]) -> None: - scaled_pixbuf = None + cover_pixbuf = None + small_cover_pixbuf = None if image_path: - scaled_pixbuf = scale_album_image(image_path, max_size=_ALBUM_IMAGE_SIZE) + cover_pixbuf = scale_album_image(image_path, max_size=_ALBUM_IMAGE_SIZE) + small_cover_pixbuf = scale_album_image( + image_path, max_size=_SMALL_ALBUM_IMAGE_SIZE + ) - if scaled_pixbuf: - self.album_image.set_from_pixbuf(scaled_pixbuf) + if cover_pixbuf: + self.album_image.set_from_pixbuf(cover_pixbuf) else: self.album_image.set_from_pixbuf(self.default_album_image) + if small_cover_pixbuf: + self.album_information_image.set_from_pixbuf(small_cover_pixbuf) + else: + self.album_information_image.clear() + self.album_image.show_now() + self.album_information_image.show_now() def _update_track_view(self, album: Optional[AlbumModel]) -> None: if album is None: @@ -275,10 +288,22 @@ def _update_track_view(self, album: Optional[AlbumModel]) -> None: self._clear_tracks_box_selection = True def _update_information_box(self, album: Optional[AlbumModel]) -> None: + if album is not None: + album_information_title = _INFO_TITLE_WITH_MARKUP.format(title=album.name) + self.album_information_title_label.set_markup(album_information_title) + self.album_information_title_label.set_tooltip_text(album.name) + + album_information_subtitle = _INFO_SUBTITLE_WITH_MARKUP.format( + subtitle=album.artist_name + ) + self.album_information_subtitle_label.set_markup(album_information_subtitle) + self.album_information_subtitle_label.set_tooltip_text(album.artist_name) + else: + self.album_information_title_label.clear() + self.album_information_subtitle_label.clear() + album_information = ( - _INFO_TITLE_WITH_MARKUP.format(title=album.name) - + "\n\n" - + album.information.album_abstract + album.information.album_abstract if album is not None and album.information is not None and album.information.album_abstract is not None @@ -292,16 +317,24 @@ def _update_information_box(self, album: Optional[AlbumModel]) -> None: if self.album_information_viewport.props.vadjustment is not None: self.album_information_viewport.props.vadjustment.set_value(0) + if album is not None: + artist_information_title = _INFO_TITLE_WITH_MARKUP.format( + title=album.artist_name + ) + self.artist_information_title_label.set_markup(artist_information_title) + self.artist_information_title_label.set_tooltip_text(album.artist_name) + else: + self.artist_information_title_label.clear() + artist_information = ( - _INFO_TITLE_WITH_MARKUP.format(title=album.artist_name) - + "\n\n" - + album.information.artist_abstract + album.information.artist_abstract if album is not None and album.information is not None and album.information.artist_abstract else _MISSING_INFO_MSG_WITH_MARKUP ) self.artist_information_label.set_markup(artist_information) + if self.artist_information_viewport.props.hadjustment is not None: self.artist_information_viewport.props.hadjustment.set_value(0)