[gnome-music/wip/jfelder/new-album-design-v3: 1/2] albumwidget: Add a play button




commit a13ffbb4e42206549ceac310d4e8b4e6be26b622
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Jul 30 15:08:49 2021 +0200

    albumwidget: Add a play button
    
    Closes: https://gitlab.gnome.org/GNOME/gnome-music/-/issues/433

 data/ui/AlbumWidget.ui            | 24 ++++++++++++++++++++++++
 gnomemusic/widgets/albumwidget.py | 27 +++++++++++++++++++--------
 po/POTFILES.in                    |  1 +
 3 files changed, 44 insertions(+), 8 deletions(-)
---
diff --git a/data/ui/AlbumWidget.ui b/data/ui/AlbumWidget.ui
index bd596990f..a71043bf5 100644
--- a/data/ui/AlbumWidget.ui
+++ b/data/ui/AlbumWidget.ui
@@ -100,6 +100,23 @@
                         </style>
                       </object>
                     </child>
+                    <child>
+                      <object class="GtkButton" id="_play_button">
+                        <property name="visible">True</property>
+                        <property name="can-focus">True</property>
+                        <property name="receives-default">True</property>
+                        <property name="image">_play_image</property>
+                        <property name="always_show_image">True</property>
+                        <property name="tooltip-text" translatable="yes">Play</property>
+                        <property name="halign">start</property>
+                        <property name="valign">center</property>
+                        <property name="margin-top">12</property>
+                        <signal name="clicked" handler="_on_play_button_clicked" swapped="no"/>
+                        <style>
+                          <class name="circular"/>
+                        </style>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>
@@ -117,4 +134,11 @@
       </object>
     </child>
   </template>
+  <object class="GtkImage" id="_play_image">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="margin-top">1</property>
+    <property name="icon_name">media-playback-start-symbolic</property>
+    <property name="icon_size">1</property>
+  </object>
 </interface>
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 05ca51df0..31964e56c 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -35,6 +35,7 @@ from gnomemusic.widgets.disclistboxwidget import DiscListBox  # noqa: F401
 if typing.TYPE_CHECKING:
     from gnomemusic.application import Application
     from gnomemusic.coredisc import CoreDisc
+    from gnomemusic.coresong import CoreSong
     from gnomemusic.widgets.songwidget import SongWidget
 
 
@@ -52,6 +53,7 @@ class AlbumWidget(Gtk.ScrolledWindow):
     _composer_label = Gtk.Template.Child()
     _art_stack = Gtk.Template.Child()
     _disc_list_box = Gtk.Template.Child()
+    _play_button = Gtk.Template.Child()
     _released_label = Gtk.Template.Child()
     _title_label = Gtk.Template.Child()
 
@@ -136,6 +138,9 @@ class AlbumWidget(Gtk.ScrolledWindow):
                 discbox = self._disc_list_box.get_row_at_index(i)
                 discbox.props.show_disc_label = True
 
+        empty_album = (n_items == 0)
+        self._play_button.props.sensitive = not empty_album
+
     def _set_composer_label(self, corealbum: CoreAlbum) -> None:
         composer = corealbum.props.composer
         show = False
@@ -148,22 +153,24 @@ class AlbumWidget(Gtk.ScrolledWindow):
         self._composer_label.props.visible = show
         self._composer_label.props.visible = show
 
-    def _song_activated(
-            self, widget: Gtk.Widget, song_widget: SongWidget) -> int:
-        if self.props.selection_mode:
-            song_widget.props.selected = not song_widget.props.selected
-            return GLib.SOURCE_CONTINUE
-
-        signal_id = None
+    def _play(self, coresong: Optional[CoreSong] = None) -> None:
+        signal_id = 0
 
         def _on_playlist_loaded(klass, playlist_type):
-            self._player.play(song_widget.props.coresong)
+            self._player.play(coresong)
             self._coremodel.disconnect(signal_id)
 
         signal_id = self._coremodel.connect(
             "playlist-loaded", _on_playlist_loaded)
         self._coremodel.props.active_core_object = self._corealbum
 
+    def _song_activated(
+            self, widget: Gtk.Widget, song_widget: SongWidget) -> int:
+        if self.props.selection_mode:
+            song_widget.props.selected = not song_widget.props.selected
+            return GLib.SOURCE_CONTINUE
+
+        self._play(song_widget.props.coresong)
         return GLib.SOURCE_CONTINUE
 
     def select_all(self) -> None:
@@ -186,3 +193,7 @@ class AlbumWidget(Gtk.ScrolledWindow):
         :rtype: CoreAlbum
         """
         return self._corealbum
+
+    @Gtk.Template.Callback()
+    def _on_play_button_clicked(self, button: Gtk.Button) -> None:
+        self._play()
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ae853c878..50b80c21a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@ data/org.gnome.Music.appdata.xml.in.in
 data/org.gnome.Music.desktop.in.in
 data/org.gnome.Music.gschema.xml
 data/ui/AboutDialog.ui.in
+data/ui/AlbumWidget.ui
 data/ui/AppMenu.ui
 data/ui/HeaderBar.ui
 data/ui/help-overlay.ui


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