[gnome-music/wip/jfelder/selection-misc-cleanups: 6/7] discbox: Inherit from GtkListBoxRow



commit 0185bd0474e0cdb9dd2fd04b8aefc089b3d16ef7
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Jan 9 17:48:41 2020 +0100

    discbox: Inherit from GtkListBoxRow
    
    This simplifies the code a little bit and ensures that the row is not
    selectable by default.

 data/ui/DiscBox.ui                      | 75 ++++++++++++++++++---------------
 gnomemusic/widgets/albumwidget.py       |  8 +---
 gnomemusic/widgets/artistalbumwidget.py |  4 +-
 gnomemusic/widgets/disclistboxwidget.py |  2 +-
 4 files changed, 45 insertions(+), 44 deletions(-)
---
diff --git a/data/ui/DiscBox.ui b/data/ui/DiscBox.ui
index d1576f37..a769b65c 100644
--- a/data/ui/DiscBox.ui
+++ b/data/ui/DiscBox.ui
@@ -2,39 +2,46 @@
 <!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.12"/>
-  <template parent="GtkBox" class="DiscBox">
-      <property name="visible">True</property>
-      <property name="can_focus">False</property>
-      <property name="orientation">vertical</property>
-      <child>
-        <object class="GtkLabel" id="_disc_label">
-          <property name="visible">True</property>
-          <property name="can_focus">False</property>
-          <property name="halign">fill</property>
-          <!-- <property name="hexpand">True</property> -->
-          <property name="no_show_all">True</property>
-          <property name="xalign">0.0</property>
-          <style>
-            <class name="disc-label"/>
-          </style>
-        </object>
-        <packing>
-          <property name="position">0</property>
-        </packing>
-      </child>
-      <child>
-        <object class="GtkListBox" id="_list_box">
-          <property name="visible">True</property>
-          <property name="can_focus">False</property>
-          <property name="valign">start</property>
-          <property name="selection_mode">none</property>
-          <style>
-            <class name="songs-list"/>
-          </style>
-        </object>
-        <packing>
-          <property name="position">1</property>
-        </packing>
-      </child>
+  <template parent="GtkListBoxRow" class="DiscBox">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="selectable">False</property>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkLabel" id="_disc_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">fill</property>
+            <!-- <property name="hexpand">True</property> -->
+            <property name="no_show_all">True</property>
+            <property name="xalign">0.0</property>
+            <style>
+              <class name="disc-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkListBox" id="_list_box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="valign">start</property>
+            <property name="selection_mode">none</property>
+            <style>
+              <class name="songs-list"/>
+            </style>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
   </template>
 </interface>
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 19616db5..e7f8d353 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -138,15 +138,11 @@ class AlbumWidget(Gtk.EventBox):
     def _on_model_items_changed(self, model, position, removed, added):
         n_items = model.get_n_items()
         if n_items == 1:
-            row = self._disc_listbox.get_row_at_index(0)
-            row.props.selectable = False
-            discbox = row.get_child()
+            discbox = self._disc_listbox.get_row_at_index(0)
             discbox.props.show_disc_label = False
         else:
             for i in range(n_items):
-                row = self._disc_listbox.get_row_at_index(i)
-                row.props.selectable = False
-                discbox = row.get_child()
+                discbox = self._disc_listbox.get_row_at_index(i)
                 discbox.props.show_disc_label = True
 
     def _set_composer_label(self, corealbum):
diff --git a/gnomemusic/widgets/artistalbumwidget.py b/gnomemusic/widgets/artistalbumwidget.py
index 9d90fb2c..70ef433e 100644
--- a/gnomemusic/widgets/artistalbumwidget.py
+++ b/gnomemusic/widgets/artistalbumwidget.py
@@ -109,9 +109,7 @@ class ArtistAlbumWidget(Gtk.Box):
     def _on_model_items_changed(self, model, position, removed, added):
         n_items = model.get_n_items()
         for i in range(n_items):
-            row = self._disc_list_box.get_row_at_index(i)
-            row.props.selectable = False
-            discbox = row.get_child()
+            discbox = self._disc_list_box.get_row_at_index(i)
             discbox.props.show_disc_label = (n_items > 1)
 
     def _song_activated(self, widget, song_widget):
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index b7e95e33..242e4674 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -30,7 +30,7 @@ from gnomemusic.widgets.songwidget import SongWidget
 
 
 @Gtk.Template(resource_path='/org/gnome/Music/ui/DiscBox.ui')
-class DiscBox(Gtk.Box):
+class DiscBox(Gtk.ListBoxRow):
     """A widget which compromises one disc
 
     DiscBox contains a disc label for the disc number on top


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