[gnome-music/wip/jfelder/gtk4-v3: 139/145] songwidget: Restore star toggle




commit f8aa16a4fc175779846c8d0fdc834fa13733400d
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Feb 3 20:53:27 2022 +0100

    songwidget: Restore star toggle

 data/ui/SongWidget.ui            |  8 +++++++-
 gnomemusic/widgets/songwidget.py | 18 ++++++++----------
 2 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/data/ui/SongWidget.ui b/data/ui/SongWidget.ui
index 3a2ff6650..d6ce06c0e 100644
--- a/data/ui/SongWidget.ui
+++ b/data/ui/SongWidget.ui
@@ -134,7 +134,13 @@
                     <property name="focusable">0</property>
                     <property name="halign">end</property>
                     <property name="valign">center</property>
-                    <!-- <signal name="button-release-event" handler="_on_star_toggle" swapped="no"/> -->
+                    <child>
+                      <object class="GtkGestureClick">
+                        <property name="button">1</property>
+                        <property name="propagation-phase">capture</property>
+                        <signal name="released" handler="_on_star_toggle" swapped="no"/>
+                      </object>
+                    </child>
                     <child>
                       <object class="GtkEventControllerMotion">
                         <signal name="enter" handler="_on_star_hover" swapped="no"/>
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 5129fddde..80a4a98af 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -202,16 +202,14 @@ class SongWidget(Gtk.ListBoxRow):
         # (one event in SongWidget and the other one in select_button).
         self.props.select_click = not self.props.select_click
 
-    # @Gtk.Template.Callback()
-    # def _on_star_toggle(self, widget, event):
-    #     (_, button) = event.get_button()
-    #     if button != Gdk.BUTTON_PRIMARY:
-    #         return False
-
-    #     favorite = not self._star_image.favorite
-    #     self._star_image.props.favorite = favorite
-
-    #     return True
+    @Gtk.Template.Callback()
+    def _on_star_toggle(
+            self, controller: Gtk.GestureClick, n_press: int, x: float,
+            y: float) -> bool:
+        controller.set_state(Gtk.EventSequenceState.CLAIMED)
+        favorite = not self._star_image.favorite
+        self._star_image.props.favorite = favorite
+        return Gdk.EVENT_STOP
 
     @Gtk.Template.Callback()
     def _on_star_hover(self, controller, x, y):


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