[gnome-music/wip/mschraal/core: 169/190] albumwidget: Do not show disc label with 1 disc



commit 770bc5171e9578b966b896b740f06bce9bd96010
Author: Marinus Schraal <mschraal gnome org>
Date:   Tue Jul 2 00:26:51 2019 +0200

    albumwidget: Do not show disc label with 1 disc
    
    Also add a better fix to make the listboxrows non-selectable.

 gnomemusic/widgets/albumwidget.py | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 226a05bf..8c213b31 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -77,13 +77,10 @@ class AlbumWidget(Gtk.EventBox):
 
         self._album = corealbum.props.media
         self._album_model = corealbum.props.model
+        self._album_model.connect_after(
+            "items-changed", self._on_model_items_changed)
         self._listbox.bind_model(self._album_model, self._create_widget)
 
-        def non_selectable(child):
-            child.props.selectable = False
-
-        self._listbox.forall(non_selectable)
-
         corealbum.connect("notify::duration", self._on_duration_changed)
 
     def _create_widget(self, disc):
@@ -107,6 +104,20 @@ class AlbumWidget(Gtk.EventBox):
 
         return disc_box
 
+    def _on_model_items_changed(self, model, position, removed, added):
+        n_items = model.get_n_items()
+        if n_items == 1:
+            row = self._listbox.get_row_at_index(0)
+            row.props.selectable = False
+            discbox = row.get_child()
+            discbox.props.show_disc_label = False
+        else:
+            for i in range(n_items):
+                row = self._listbox.get_row_at_index(i)
+                row.props.selectable = False
+                discbox = row.get_child()
+                discbox.props.show_disc_label = True
+
     @log
     def _set_composer_label(self, corealbum):
         composer = corealbum.props.composer


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