[gnome-music/wip/mschraal/gtk4-v2: 8/60] songwidget: Disable DnD, remove EventBox use (FIXME)




commit a754152319fc85874846d97b77c1f138b71f7c86
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Apr 11 16:14:49 2021 +0200

    songwidget: Disable DnD, remove EventBox use (FIXME)

 data/ui/SongWidget.ui            |  28 +++++------
 gnomemusic/widgets/songwidget.py | 106 +++++++++++++++++++--------------------
 2 files changed, 66 insertions(+), 68 deletions(-)
---
diff --git a/data/ui/SongWidget.ui b/data/ui/SongWidget.ui
index 19b8f0a52..05274ca22 100644
--- a/data/ui/SongWidget.ui
+++ b/data/ui/SongWidget.ui
@@ -2,10 +2,10 @@
 <!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <template class="SongWidget" parent="GtkEventBox">
+  <template class="SongWidget" parent="GtkBox">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <signal name="drag_data_received" handler="_on_drag_data_received"/>
+    <!-- <signal name="drag_data_received" handler="_on_drag_data_received"/> -->
     <child>
       <object class="GtkBox" id="box1">
         <property name="visible">True</property>
@@ -14,11 +14,11 @@
         <property name="margin-bottom">10</property>
         <property name="margin-top">10</property>
         <child>
-          <object class="GtkEventBox" id="_dnd_eventbox">
+          <object class="GtkBox" id="_dnd_eventbox">
             <property name="visible">False</property>
-            <signal name="drag-begin" handler="_on_drag_begin"/>
-            <signal name="drag-end" handler="_on_drag_end"/>
-            <signal name="drag_data_get" handler="_on_drag_data_get"/>
+            <!-- <signal name="drag-begin" handler="_on_drag_begin"/> -->
+            <!-- <signal name="drag-end" handler="_on_drag_end"/> -->
+            <!-- <signal name="drag_data_get" handler="_on_drag_data_get"/> -->
             <child>
               <object class="GtkImage">
                 <property name="visible">True</property>
@@ -37,7 +37,7 @@
             <property name="can_focus">False</property>
             <property name="homogeneous">True</property>
             <child>
-              <object class="GtkEventBox" id="eventbox2">
+              <object class="GtkBox">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <child>
@@ -157,14 +157,19 @@
             <property name="can-focus">False</property>
             <property name="visible">True</property>
             <child>
-              <object class="GtkEventBox" id="_star_eventbox">
+              <object class="GtkBox" id="_star_box">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="halign">end</property>
                 <property name="valign">center</property>
-                <property name="visible_window">True</property>
                 <property name="margin-end">12</property>
                 <signal name="button-release-event" handler="_on_star_toggle" swapped="no"/>
+                <child>
+                  <object class="GtkEventControllerMotion">
+                    <signal name="enter" handler="_on_star_hover" swapped="no"/>
+                    <signal name="leave" handler="_on_star_unhover" swapped="no"/>
+                  </object>
+                </child>
                 <child>
                   <object class="StarImage" id="_star_image">
                     <property name="visible">True</property>
@@ -200,9 +205,4 @@
       <widget name="_album_duration_box"/>
     </widgets>
   </object>
-  <object class="GtkEventControllerMotion" id="_controller_motion">
-    <property name="widget">_star_eventbox</property>
-    <signal name="enter" handler="_on_star_hover" swapped="no"/>
-    <signal name="leave" handler="_on_star_unhover" swapped="no"/>
-  </object>
 </interface>
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 1773695c4..c11bfca2b 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -34,7 +34,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.Box):
     """The single song widget used in DiscListBox
 
     Contains
@@ -61,13 +61,11 @@ class SongWidget(Gtk.EventBox):
     _album_duration_box = Gtk.Template.Child()
     _artist_box = Gtk.Template.Child()
     _artist_label = Gtk.Template.Child()
-    _controller_motion = Gtk.Template.Child()
-    _dnd_eventbox = Gtk.Template.Child()
+    # _dnd_eventbox = Gtk.Template.Child()
     _select_button = Gtk.Template.Child()
     _number_label = Gtk.Template.Child()
     _title_label = Gtk.Template.Child()
     _duration_label = Gtk.Template.Child()
-    _star_eventbox = Gtk.Template.Child()
     _star_image = Gtk.Template.Child()
     _star_stack = Gtk.Template.Child()
     _play_icon = Gtk.Template.Child()
@@ -145,56 +143,56 @@ class SongWidget(Gtk.EventBox):
         if not self.props.coresong.props.is_tracker:
             self._star_stack.props.visible_child_name = "empty"
 
-        if can_dnd is True:
-            self._dnd_eventbox.props.visible = True
-            self._drag_widget = None
-            entries = [
-                Gtk.TargetEntry.new(
-                    "GTK_EVENT_BOX", Gtk.TargetFlags.SAME_APP, 0)
-            ]
-            self._dnd_eventbox.drag_source_set(
-                Gdk.ModifierType.BUTTON1_MASK, entries,
-                Gdk.DragAction.MOVE)
-            self.drag_dest_set(
-                Gtk.DestDefaults.ALL, entries, Gdk.DragAction.MOVE)
-
-    @Gtk.Template.Callback()
-    def _on_drag_begin(self, klass, context):
-        gdk_window = self.get_window()
-        _, x, y, _ = gdk_window.get_device_position(context.get_device())
-        allocation = self.get_allocation()
-
-        self._drag_widget = Gtk.ListBox()
-        self._drag_widget.set_size_request(allocation.width, allocation.height)
-
-        drag_row = SongWidget(self.props.coresong)
-        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.props.visible = True
-        Gtk.drag_set_icon_widget(context, self._drag_widget, x, y)
-
-    @Gtk.Template.Callback()
-    def _on_drag_end(self, klass, context):
-        self._drag_widget = None
-
-    @Gtk.Template.Callback()
-    def _on_drag_data_get(self, klass, context, selection_data, info, time_):
-        row_position = self.get_parent().get_index()
-        selection_data.set(
-            Gdk.Atom.intern("row_position", False), 0,
-            bytes(str(row_position), encoding="UTF8"))
-
-    @Gtk.Template.Callback()
-    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()
-        if source_position == target_position:
-            return
-
-        self.emit("widget-moved", source_position)
+        # if can_dnd is True:
+        #     self._dnd_eventbox.props.visible = True
+        #     self._drag_widget = None
+        #     entries = [
+        #         Gtk.TargetEntry.new(
+        #             "GTK_EVENT_BOX", Gtk.TargetFlags.SAME_APP, 0)
+        #     ]
+        #     self._dnd_eventbox.drag_source_set(
+        #         Gdk.ModifierType.BUTTON1_MASK, entries,
+        #         Gdk.DragAction.MOVE)
+        #     self.drag_dest_set(
+        #         Gtk.DestDefaults.ALL, entries, Gdk.DragAction.MOVE)
+
+    # @Gtk.Template.Callback()
+    # def _on_drag_begin(self, klass, context):
+    #     gdk_window = self.get_window()
+    #     _, x, y, _ = gdk_window.get_device_position(context.get_device())
+    #     allocation = self.get_allocation()
+
+    #     self._drag_widget = Gtk.ListBox()
+    #     self._drag_widget.set_size_request(allocation.width, allocation.height)
+
+    #     drag_row = SongWidget(self.props.coresong)
+    #     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.props.visible = True
+    #     Gtk.drag_set_icon_widget(context, self._drag_widget, x, y)
+
+    # @Gtk.Template.Callback()
+    # def _on_drag_end(self, klass, context):
+    #     self._drag_widget = None
+
+    # @Gtk.Template.Callback()
+    # def _on_drag_data_get(self, klass, context, selection_data, info, time_):
+    #     row_position = self.get_parent().get_index()
+    #     selection_data.set(
+    #         Gdk.Atom.intern("row_position", False), 0,
+    #         bytes(str(row_position), encoding="UTF8"))
+
+    # @Gtk.Template.Callback()
+    # 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()
+    #     if source_position == target_position:
+    #         return
+
+    #     self.emit("widget-moved", source_position)
 
     @Gtk.Template.Callback()
     def _on_select_button_toggled(self, widget):


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