[gnome-music/wip/jfelder/core-playlists-view] songwidget: Add support for artist and album names



commit cd847148ed478e0b7bb332e05ff51b9a8831704e
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Jul 10 01:25:13 2019 +0200

    songwidget: Add support for artist and album names

 data/ui/SongWidget.ui             | 57 ++++++++++++++++++++++++++++++++++++++-
 gnomemusic/views/playlistsview.py |  2 +-
 gnomemusic/widgets/songwidget.py  | 13 ++++++++-
 3 files changed, 69 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/SongWidget.ui b/data/ui/SongWidget.ui
index 16b7ccc2..309997fa 100644
--- a/data/ui/SongWidget.ui
+++ b/data/ui/SongWidget.ui
@@ -67,7 +67,7 @@
           </object>
         </child>
         <child>
-          <object class="GtkBox" id="box2">
+          <object class="GtkBox" id="title_box">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="margin_top">1</property>
@@ -87,6 +87,52 @@
                 <property name="margin_start">9</property>
               </object>
             </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox" id="artist_box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_top">1</property>
+            <property name="margin_bottom">1</property>
+            <property name="hexpand">True</property>
+            <child>
+              <object class="GtkLabel" id="_artist_label">
+                <property name="visible">False</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="halign">start</property>
+                <property name="hexpand">True</property>
+                <property name="valign">start</property>
+                <property name="ellipsize">end</property>
+                <property name="max_width_chars">90</property>
+                <property name="justify">fill</property>
+                <property name="margin_start">9</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox" id="album_duration_box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_top">1</property>
+            <property name="margin_bottom">1</property>
+            <property name="hexpand">True</property>
+            <child>
+              <object class="GtkLabel" id="_album_label">
+                <property name="visible">False</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="halign">start</property>
+                <property name="hexpand">True</property>
+                <property name="valign">start</property>
+                <property name="ellipsize">end</property>
+                <property name="max_width_chars">90</property>
+                <property name="justify">fill</property>
+                <property name="margin_start">9</property>
+              </object>
+            </child>
             <child>
               <object class="GtkLabel" id="_duration_label">
                 <property name="visible">True</property>
@@ -94,6 +140,7 @@
                 <property name="no_show_all">True</property>
                 <property name="halign">end</property>
                 <property name="valign">center</property>
+                <property name="hexpand">True</property>
                 <property name="single_line_mode">True</property>
               </object>
             </child>
@@ -126,4 +173,12 @@
       </object>
     </child>
   </template>
+  <object class="GtkSizeGroup">
+    <property name="mode">horizontal</property>
+  <widgets>
+    <widget name="title_box"/>
+    <widget name="artist_box"/>
+    <widget name="album_duration_box"/>
+  </widgets>
+</object>
 </interface>
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index bcd83a74..5238a27f 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -246,7 +246,7 @@ class PlaylistsView(BaseView):
 
     def _create_song_widget(self, coresong, playlist):
         can_dnd = not playlist.props.is_smart
-        song_widget = SongWidget(coresong, can_dnd)
+        song_widget = SongWidget(coresong, can_dnd, True)
         song_widget.props.show_song_number = False
 
         song_widget.connect('button-release-event', self._song_activated)
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index cc12a022..a604a4cb 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -64,6 +64,8 @@ class SongWidget(Gtk.EventBox):
 
     _playlists = Playlists.get_default()
 
+    _album_label = Gtk.Template.Child()
+    _artist_label = Gtk.Template.Child()
     _dnd_eventbox = Gtk.Template.Child()
     _select_button = Gtk.Template.Child()
     _number_label = Gtk.Template.Child()
@@ -84,11 +86,12 @@ class SongWidget(Gtk.EventBox):
         return '<SongWidget>'
 
     @log
-    def __init__(self, coresong, can_dnd=False):
+    def __init__(self, coresong, can_dnd=False, show_artist_and_album=False):
         """Instanciates a SongWidget
 
         :param Corsong coresong: song associated with the widget
         :param bool can_dnd: allow drag and drop operations
+        :param bool show_artist_and_album: display artist and album
         """
         super().__init__()
 
@@ -110,6 +113,14 @@ class SongWidget(Gtk.EventBox):
         time = utils.seconds_to_string(self.props.coresong.props.duration)
         self._duration_label.props.label = time
 
+        if show_artist_and_album is True:
+            album = self.props.coresong.props.album
+            self._album_label.props.label = album
+            self._album_label.props.visible = True
+            artist = self.props.coresong.props.artist
+            self._artist_label.props.label = artist
+            self._artist_label.props.visible = True
+
         self._select_button.set_visible(False)
 
         self._play_icon.set_from_icon_name(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]