Commit 8ff8e6d3 authored by Marinus Schraal's avatar Marinus Schraal

Add tooltips for media info

Add tooltips for artist, album & song title to widgets that commonly
support it. This allows ellipsized labels to be read.

Added a TwoLineTip widget that is used for multi-line tooltips.

The following widgets have tooltips added or altered:
 * SongWidget
 * SidebarRow
 * AlbumCover
 * Song info in PlayerToolbar
 * AlbumWidget
parent 4a86d031
......@@ -6,8 +6,10 @@
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_tooltip">True</property>
<property name="valign">start</property>
<property name="orientation">vertical</property>
<signal name="query-tooltip" handler="_on_tooltip_query"/>
<child>
<object class="GtkOverlay">
<property name="visible">True</property>
......@@ -49,7 +51,6 @@
<property name="ellipsize">middle</property>
<property name="max_width_chars">20</property>
<property name="lines">2</property>
<property name="tooltip_text" bind-source="_title_label" bind-property="label" bind-flags="default" />
</object>
</child>
<child>
......@@ -58,7 +59,6 @@
<property name="can_focus">False</property>
<property name="ellipsize">middle</property>
<property name="max_width_chars">20</property>
<property name="tooltip_text" bind-source="_artist_label" bind-property="label" bind-flags="default" />
<style>
<class name="albumcover-artist-label"/>
<class name="dim-label"/>
......
......@@ -118,12 +118,14 @@
</object>
</child>
<child>
<object class="GtkBox" id="nowplaying">
<object class="GtkBox" id="_song_info_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="has_tooltip">True</property>
<property name="valign">center</property>
<property name="spacing">8</property>
<signal name="query-tooltip" handler="_on_tooltip_query"/>
<child>
<object class="CoverStack" id="_cover_stack">
<property name="visible">True</property>
......
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="TwoLineTip" parent="GtkBox">
<property name="can_focus">False</property>
<property name="expand">False</property>
<property name="orientation">vertical</property>
<property name="visible">True</property>
<child>
<object class="GtkLabel" id="_title_label">
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="visible">True</property>
<style>
<class name="tooltip-title"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="_subtitle_label">
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="visible">True</property>
</object>
</child>
</template>
</interface>
......@@ -128,3 +128,8 @@ box#ArtistAlbumsWidget .artist-label {
headerbar {
transition: 250ms ease-in-out;
}
/* TwoLineTip */
.tooltip-title {
font-weight: bold;
}
......@@ -24,5 +24,6 @@
<file preprocess="xml-stripblanks">PlaylistContextMenu.ui</file>
<file preprocess="xml-stripblanks">PlaylistControls.ui</file>
<file preprocess="xml-stripblanks">PlaylistDialog.ui</file>
<file preprocess="xml-stripblanks">TwoLineTip.ui</file>
</gresource>
</gresources>
......@@ -29,6 +29,7 @@ from gi.repository import Gdk, GLib, GObject, Grl, Gtk
from gnomemusic import log
from gnomemusic import utils
from gnomemusic.albumartcache import Art
from gnomemusic.widgets.twolinetip import TwoLineTip
@Gtk.Template(resource_path='/org/gnome/Music/AlbumCover.ui')
......@@ -68,8 +69,16 @@ class AlbumCover(Gtk.FlowBoxChild):
self._media = media
self._artist_label.props.label = utils.get_artist_name(media)
self._title_label.props.label = utils.get_media_title(media)
self._tooltip = TwoLineTip()
artist = utils.get_artist_name(media)
title = utils.get_media_title(media)
self._tooltip.props.title = utils.get_artist_name(media)
self._tooltip.props.subtitle = utils.get_media_title(media)
self._artist_label.props.label = artist
self._title_label.props.label = title
self.bind_property(
'selected', self._check, 'active',
......@@ -79,6 +88,8 @@ class AlbumCover(Gtk.FlowBoxChild):
'selection-mode', self._check, 'visible',
GObject.BindingFlags.BIDIRECTIONAL)
self.connect('query-tooltip', self._on_tooltip_query)
self._events.add_events(Gdk.EventMask.TOUCH_MASK)
self._cover_stack.props.size = Art.Size.MEDIUM
......@@ -113,3 +124,10 @@ class AlbumCover(Gtk.FlowBoxChild):
if self.props.selection_mode:
self.props.selected = not self.props.selected
@Gtk.Template.Callback()
@log
def _on_tooltip_query(self, widget, x, y, kb, tooltip, data=None):
tooltip.set_custom(self._tooltip)
return True
......@@ -129,8 +129,13 @@ class AlbumWidget(Gtk.EventBox):
art.image = self._cover
self._album = utils.get_album_title(item)
self._artist_label.props.label = utils.get_artist_name(item)
artist = utils.get_artist_name(item)
self._title_label.props.label = self._album
self._title_label.props.tooltip_text = self._album
self._artist_label.props.label = artist
self._artist_label.props.tooltip_text = artist
year = utils.get_media_year(item)
if not year:
......
......@@ -31,6 +31,7 @@ from gnomemusic.gstplayer import Playback
from gnomemusic.player import RepeatMode
from gnomemusic.widgets.coverstack import CoverStack # noqa: F401
from gnomemusic.widgets.smoothscale import SmoothScale # noqa: F401
from gnomemusic.widgets.twolinetip import TwoLineTip
import gnomemusic.utils as utils
......@@ -48,16 +49,17 @@ class PlayerToolbar(Gtk.ActionBar):
__gtype_name__ = 'PlayerToolbar'
_artist_label = Gtk.Template.Child()
_cover_stack = Gtk.Template.Child()
_duration_label = Gtk.Template.Child()
_pause_image = Gtk.Template.Child()
_next_button = Gtk.Template.Child()
_pause_image = Gtk.Template.Child()
_play_button = Gtk.Template.Child()
_play_image = Gtk.Template.Child()
_prev_button = Gtk.Template.Child()
_progress_scale = Gtk.Template.Child()
_progress_time_label = Gtk.Template.Child()
_repeat_image = Gtk.Template.Child()
_cover_stack = Gtk.Template.Child()
_song_info_box = Gtk.Template.Child()
_title_label = Gtk.Template.Child()
def __repr__(self):
......@@ -74,6 +76,8 @@ class PlayerToolbar(Gtk.ActionBar):
self._cover_stack.props.size = Art.Size.XSMALL
self._cover_stack.connect('updated', self._on_cover_stack_updated)
self._tooltip = TwoLineTip()
self._sync_repeat_image()
self._headerbar.connect(
......@@ -171,10 +175,24 @@ class PlayerToolbar(Gtk.ActionBar):
self._play_button.set_sensitive(True)
self._sync_prev_next()
self._artist_label.set_label(utils.get_artist_name(current_song))
self._title_label.set_label(utils.get_media_title(current_song))
artist = utils.get_artist_name(current_song)
title = utils.get_media_title(current_song)
self._title_label.props.label = title
self._artist_label.props.label = artist
self._tooltip.props.title = title
self._tooltip.props.subtitle = artist
self._cover_stack.update(current_song)
@log
def _on_clock_tick(self, player, seconds):
self._progress_time_label.set_label(utils.seconds_to_string(seconds))
@Gtk.Template.Callback()
@log
def _on_tooltip_query(self, widget, x, y, kb, tooltip, data=None):
tooltip.set_custom(self._tooltip)
return True
......@@ -56,5 +56,6 @@ class SidebarRow(Gtk.ListBoxRow):
GObject.BindingFlags.BIDIRECTIONAL)
self.bind_property('selection-mode', self._revealer, 'reveal-child')
self.bind_property('text', self._label, 'label')
self.bind_property('text', self._label, 'tooltip-text')
self.show()
......@@ -96,6 +96,7 @@ class SongWidget(Gtk.EventBox):
title = utils.get_media_title(media)
self._title_label.set_max_width_chars(50)
self._title_label.set_text(title)
self._title_label.props.tooltip_text = title
time = utils.seconds_to_string(media.get_duration())
self._duration_label.set_text(time)
......
# Copyright 2018 The GNOME Music developers
#
# GNOME Music is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# GNOME Music is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with GNOME Music; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# The GNOME Music authors hereby grant permission for non-GPL compatible
# GStreamer plugins to be used and distributed together with GStreamer
# and GNOME Music. This permission is above and beyond the permissions
# granted by the GPL license by which GNOME Music is covered. If you
# modify this code, you may extend this exception to your version of the
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
from gi.repository import GObject, Gtk
from gnomemusic import log
@Gtk.Template(resource_path='/org/gnome/Music/TwoLineTip.ui')
class TwoLineTip(Gtk.Box):
"""Tooltip with two lines of text
A bolded title and a regular subtitle.
"""
__gtype_name__ = 'TwoLineTip'
_title_label = Gtk.Template.Child()
_subtitle_label = Gtk.Template.Child()
title = GObject.Property(type=str)
subtitle = GObject.Property(type=str)
def __repr__(self):
return '<TwoLineTip>'
@log
def __init__(self):
super().__init__()
self.bind_property('title', self._title_label, 'label')
self.bind_property('subtitle', self._subtitle_label, 'label')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment