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




commit ed2ed6c7e3d9d1f529114882aa7e29937d589125
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 | 28 +++++++++++++++++++---------
 po/POTFILES.in                    |  1 +
 3 files changed, 44 insertions(+), 9 deletions(-)
---
diff --git a/data/ui/AlbumWidget.ui b/data/ui/AlbumWidget.ui
index da8bbe0ab..9c124a9be 100644
--- a/data/ui/AlbumWidget.ui
+++ b/data/ui/AlbumWidget.ui
@@ -98,6 +98,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>
@@ -115,4 +132,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 23f1d0495..92a29e8f1 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -36,6 +36,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
 
 
@@ -53,6 +54,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()
 
@@ -157,6 +159,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) -> None:
         composer = self._corealbum.props.composer
         show = False
@@ -181,23 +186,24 @@ class AlbumWidget(Gtk.ScrolledWindow):
             "{}, {} minute", "{}, {} minutes", mins).format(year, mins)
         self._released_label.props.label = release_info_label
 
-    def _song_activated(
-            self, widget: Gtk.Widget, song_widget: SongWidget) -> None:
-        if self.props.selection_mode:
-            song_widget.props.selected = not song_widget.props.selected
-            return
-
-        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
 
-        return
+    def _song_activated(
+            self, widget: Gtk.Widget, song_widget: SongWidget) -> None:
+        if self.props.selection_mode:
+            song_widget.props.selected = not song_widget.props.selected
+            return
+
+        self._play(song_widget.props.coresong)
 
     def select_all(self) -> None:
         self._disc_list_box.select_all()
@@ -209,3 +215,7 @@ class AlbumWidget(Gtk.ScrolledWindow):
             self, widget: Gtk.Widget, value: GObject.ParamSpecBoolean) -> None:
         if not self.props.selection_mode:
             self.deselect_all()
+
+    @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 c9ffdcb66..a880ab386 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]