[gnome-music/wip/jfelder/gtk4-v3: 17/119] songwidget: Disable DnD, remove EventBox use (FIXME)




commit 9a74aa936ca50519bbbf72bdde7dcca9ded0dd88
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            |  25 +++++----
 gnomemusic/widgets/songwidget.py | 106 +++++++++++++++++++--------------------
 2 files changed, 64 insertions(+), 67 deletions(-)
---
diff --git a/data/ui/SongWidget.ui b/data/ui/SongWidget.ui
index 49614501c..8ab9b3fcf 100644
--- a/data/ui/SongWidget.ui
+++ b/data/ui/SongWidget.ui
@@ -6,18 +6,18 @@
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="selectable">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>
         <property name="can_focus">False</property>
         <property name="spacing">6</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>
@@ -140,13 +140,18 @@
             <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>
                 <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>
@@ -202,10 +207,4 @@
       <widget name="_album_duration_box"/>
     </widgets>
   </object>
-  <object class="GtkEventControllerMotion" id="_controller_motion">
-    <property name="propagation-phase">target</property>
-    <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 b97eda9b0..84a68f869 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -62,14 +62,12 @@ class SongWidget(Gtk.ListBoxRow):
     _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()
     _menu_button = 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()
@@ -147,57 +145,57 @@ class SongWidget(Gtk.ListBoxRow):
         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)
-        self._drag_widget.props.visible = True
-        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):
-        self._drag_widget = None
-
-    @Gtk.Template.Callback()
-    def _on_drag_data_get(self, klass, context, selection_data, info, time_):
-        row_position = self.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_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)
+    #     self._drag_widget.props.visible = True
+    #     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):
+    #     self._drag_widget = None
+
+    # @Gtk.Template.Callback()
+    # def _on_drag_data_get(self, klass, context, selection_data, info, time_):
+    #     row_position = self.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_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]