Skip to content

Commit

Permalink
Information page displays artist name and album image
Browse files Browse the repository at this point in the history
Refs: #172
  • Loading branch information
orontee committed Dec 8, 2024
1 parent c1b8f99 commit fc505f2
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 22 deletions.
3 changes: 3 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ The format is based on `Keep a Changelog
Added
-----

- Information page displays artist name and album image
`#172 <https://github.com/orontee/argos/issues/172>`_

Changed
-------

Expand Down
107 changes: 99 additions & 8 deletions argos/ui/album_details_box.ui
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,42 @@
<property name="vexpand">True</property>
<property name="shadow-type">none</property>
<child>
<object class="GtkLabel" id="artist_information_label">
<!-- n-columns=1 n-rows=2 -->
<object class="GtkGrid" id="artist_information_grid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="valign">start</property>
<property name="vexpand">True</property>
<property name="wrap">True</property>
<property name="row-spacing">5</property>
<property name="column-spacing">5</property>
<child>
<object class="GtkLabel" id="artist_information_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="valign">start</property>
<property name="vexpand">True</property>
<property name="wrap">True</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="artist_information_title_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
<property name="selectable">True</property>
<property name="ellipsize">end</property>
<property name="single-line-mode">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
</child>
</object>
Expand All @@ -210,12 +240,73 @@
<property name="vexpand">True</property>
<property name="shadow-type">none</property>
<child>
<object class="GtkLabel" id="album_information_label">
<!-- n-columns=2 n-rows=3 -->
<object class="GtkGrid" id="album_information_grid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="valign">start</property>
<property name="vexpand">True</property>
<property name="wrap">True</property>
<property name="row-spacing">5</property>
<property name="column-spacing">5</property>
<child>
<object class="GtkLabel" id="album_information_title_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
<property name="selectable">True</property>
<property name="ellipsize">end</property>
<property name="single-line-mode">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkImage" id="album_information_image">
<property name="name">album-information-image</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="valign">start</property>
<property name="icon_size">0</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
<property name="height">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="album_information_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="valign">start</property>
<property name="vexpand">True</property>
<property name="wrap">True</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="album_information_subtitle_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="selectable">True</property>
<property name="ellipsize">end</property>
<property name="single-line-mode">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
61 changes: 47 additions & 14 deletions argos/widgets/albumdetailsbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""<span style="italic">{_MISSING_INFO_MSG}</span>"""
_INFO_TITLE_WITH_MARKUP = """<span size="x-large" weight="bold">{title}</span>"""
_INFO_SUBTITLE_WITH_MARKUP = """<span size="x-large">{subtitle}</span>"""


@Gtk.Template(resource_path="/io/github/orontee/Argos/ui/album_details_box.ui")
Expand Down Expand Up @@ -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="")
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit fc505f2

Please sign in to comment.