[gnome-music/wip/jfelder/songwidget-listboxrow: 9/9] songwidget: Directly inherit from GtkListBoxRow




commit 4aa017d8a52bc3ed0d9ba71fcaf33c26a5b5f001
Author: Jean Felder <jfelder src gnome org>
Date:   Sat May 8 17:53:16 2021 +0200

    songwidget: Directly inherit from GtkListBoxRow
    
    This removes a need for a GtkEventBox

 data/ui/SongWidget.ui                   |  3 ++-
 gnomemusic/views/searchview.py          | 12 +++---------
 gnomemusic/widgets/disclistboxwidget.py | 15 ++++-----------
 gnomemusic/widgets/playlistswidget.py   | 21 +++++++--------------
 gnomemusic/widgets/songwidget.py        | 11 ++++++-----
 5 files changed, 22 insertions(+), 40 deletions(-)
---
diff --git a/data/ui/SongWidget.ui b/data/ui/SongWidget.ui
index bb9e6596f..e60ad30e6 100644
--- a/data/ui/SongWidget.ui
+++ b/data/ui/SongWidget.ui
@@ -2,8 +2,9 @@
 <!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <template class="SongWidget" parent="GtkEventBox">
+  <template class="SongWidget" parent="GtkListBoxRow">
     <property name="visible">True</property>
+    <property name="selectable">False</property>
     <property name="can_focus">False</property>
     <signal name="drag_data_received" handler="_on_drag_data_received"/>
     <child>
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 918ae05b9..6dc50a325 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -163,11 +163,7 @@ class SearchView(Gtk.Stack):
             GObject.BindingFlags.BIDIRECTIONAL
             | GObject.BindingFlags.SYNC_CREATE)
 
-        row = Gtk.ListBoxRow()
-        row.props.selectable = False
-        row.add(song_widget)
-
-        return row
+        return song_widget
 
     def _create_album_widget(self, corealbum):
         album_widget = AlbumCover(corealbum)
@@ -246,8 +242,7 @@ class SearchView(Gtk.Stack):
 
     @Gtk.Template.Callback()
     def _song_activated(
-            self, list_box: Gtk.ListBox, row: Gtk.ListBoxRow) -> bool:
-        song_widget = row.get_child()
+            self, list_box: Gtk.ListBox, song_widget: SongWidget) -> bool:
         if song_widget.props.select_click:
             song_widget.props.select_click = False
             return True
@@ -433,8 +428,7 @@ class SearchView(Gtk.Stack):
         if self.props.state == SearchView.State.MAIN:
             with self._model.freeze_notify():
                 def song_select(child):
-                    song_widget = child.get_child()
-                    song_widget.props.coresong.props.selected = value
+                    child.props.coresong.props.selected = value
 
                 self._songs_listbox.foreach(song_select)
                 self._album_flowbox.foreach(child_select)
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index 2a7c31fdc..77ee0d871 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -73,16 +73,14 @@ class DiscBox(Gtk.ListBoxRow):
     def select_all(self):
         """Select all songs"""
         def child_select_all(child):
-            song_widget = child.get_child()
-            song_widget.props.coresong.props.selected = True
+            child.props.coresong.props.selected = True
 
         self._list_box.foreach(child_select_all)
 
     def deselect_all(self):
         """Deselect all songs"""
         def child_deselect_all(child):
-            song_widget = child.get_child()
-            song_widget.props.coresong.props.selected = False
+            child.props.coresong.props.selected = False
 
         self._list_box.foreach(child_deselect_all)
 
@@ -94,16 +92,11 @@ class DiscBox(Gtk.ListBoxRow):
             GObject.BindingFlags.BIDIRECTIONAL
             | GObject.BindingFlags.SYNC_CREATE)
 
-        row = Gtk.ListBoxRow()
-        row.props.selectable = False
-        row.add(song_widget)
-
-        return row
+        return song_widget
 
     @Gtk.Template.Callback()
     def _song_activated(
-            self, list_box: Gtk.ListBox, row: Gtk.ListBoxRow) -> bool:
-        song_widget = row.get_child()
+            self, list_box: Gtk.ListBox, song_widget: SongWidget) -> bool:
         if song_widget.props.select_click:
             song_widget.props.select_click = False
             return True
diff --git a/gnomemusic/widgets/playlistswidget.py b/gnomemusic/widgets/playlistswidget.py
index 3cc2e4b96..cb19efdd1 100644
--- a/gnomemusic/widgets/playlistswidget.py
+++ b/gnomemusic/widgets/playlistswidget.py
@@ -110,16 +110,12 @@ class PlaylistsWidget(Gtk.Box):
         if can_dnd is True:
             song_widget.connect("widget_moved", self._on_song_widget_moved)
 
-        row = Gtk.ListBoxRow()
-        row.props.selectable = False
-        row.add(song_widget)
-
-        return row
+        return song_widget
 
     @Gtk.Template.Callback()
     def _on_song_activated(
-            self, list_box: Gtk.ListBox, row: Gtk.ListBoxRow) -> bool:
-        coresong = row.get_child().props.coresong
+            self, list_box: Gtk.ListBox, song_widget: SongWidget) -> bool:
+        coresong = song_widget.props.coresong
         self._play(coresong)
         return True
 
@@ -136,7 +132,7 @@ class PlaylistsWidget(Gtk.Box):
         self._coremodel.props.active_core_object = current_playlist
 
     def _on_song_widget_moved(self, target, source_position):
-        target_position = target.get_parent().get_index()
+        target_position = target.get_index()
         current_playlist = self._playlists_view.props.current_playlist
         current_playlist.reorder(source_position, target_position)
 
@@ -163,15 +159,13 @@ class PlaylistsWidget(Gtk.Box):
 
     def _play_song(self, menuitem, data=None):
         selected_row = self._songs_list.get_selected_row()
-        song_widget = selected_row.get_child()
-        coresong = song_widget.props.coresong
+        coresong = selected_row.props.coresong
         self._songs_list.unselect_all()
         self._play(coresong)
 
     def _add_song_to_playlist(self, menuitem, data=None):
         selected_row = self._songs_list.get_selected_row()
-        song_widget = selected_row.get_child()
-        coresong = song_widget.props.coresong
+        coresong = selected_row.props.coresong
 
         playlist_dialog = PlaylistDialog(self._application)
         playlist_dialog.props.transient_for = self._window
@@ -185,8 +179,7 @@ class PlaylistsWidget(Gtk.Box):
     def _stage_song_for_deletion(self, menuitem, data=None):
         selected_row = self._songs_list.get_selected_row()
         position = selected_row.get_index()
-        song_widget = selected_row.get_child()
-        coresong = song_widget.props.coresong
+        coresong = selected_row.props.coresong
 
         current_playlist = self._playlists_view.props.current_playlist
 
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 2a1d61776..31e67849a 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -36,7 +36,7 @@ from gnomemusic.widgets.starimage import StarImage  # noqa: F401
 
 
 @Gtk.Template(resource_path='/org/gnome/Music/ui/SongWidget.ui')
-class SongWidget(Gtk.EventBox):
+class SongWidget(Gtk.ListBoxRow):
     """The single song widget used in DiscListBox
 
     Contains
@@ -173,9 +173,10 @@ class SongWidget(Gtk.EventBox):
         drag_row.props.show_song_number = self.props.show_song_number
 
         self._drag_widget.add(drag_row)
-        self._drag_widget.drag_highlight_row(drag_row.get_parent())
+        self._drag_widget.drag_highlight_row(drag_row)
         self._drag_widget.props.visible = True
-        Gtk.drag_set_icon_widget(context, self._drag_widget, x, y)
+        Gtk.drag_set_icon_widget(
+            context, self._drag_widget, x - allocation.x, y - allocation.y)
 
     @Gtk.Template.Callback()
     def _on_drag_end(self, klass, context):
@@ -183,7 +184,7 @@ class SongWidget(Gtk.EventBox):
 
     @Gtk.Template.Callback()
     def _on_drag_data_get(self, klass, context, selection_data, info, time_):
-        row_position = self.get_parent().get_index()
+        row_position = self.get_index()
         selection_data.set(
             Gdk.Atom.intern("row_position", False), 0,
             bytes(str(row_position), encoding="UTF8"))
@@ -192,7 +193,7 @@ class SongWidget(Gtk.EventBox):
     def _on_drag_data_received(
             self, klass, context, x, y, selection_data, info, time_):
         source_position = int(str(selection_data.get_data(), "UTF-8"))
-        target_position = self.get_parent().get_index()
+        target_position = self.get_index()
         if source_position == target_position:
             return
 


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