[gnome-music/wip/jfelder/gtk4-v3: 66/112] star




commit ca062d65e507c528f511c641572337b81545530e
Author: Jean Felder <jfelder src gnome org>
Date:   Sun Jan 9 19:21:58 2022 +0100

    star

 data/ui/SongListItem.ui         | 21 +++++++++++++++++++++
 gnomemusic/widgets/discbox.py   |  1 +
 gnomemusic/widgets/starimage.py | 12 ++++++++++++
 3 files changed, 34 insertions(+)
---
diff --git a/data/ui/SongListItem.ui b/data/ui/SongListItem.ui
index 36e286c97..d8daeb1a3 100644
--- a/data/ui/SongListItem.ui
+++ b/data/ui/SongListItem.ui
@@ -48,6 +48,27 @@
             </attributes>
           </object>
         </child>
+        <child>
+          <object class="StarImage" id="_star_image">
+            <property name="can_focus">False</property>
+            <property name="valign">center</property>
+            <property name="margin-end">12</property>
+            <property name="margin-start">12</property>
+            <binding name="favorite">
+              <lookup name="favorite" type="CoreSong">
+                <lookup name="item">GtkListItem</lookup>
+              </lookup>
+            </binding>
+            <!-- <property name="favorite" bind-source="foo" bind-property="active" 
bind-flags="bidirectional"/> -->
+            <!-- <property name="text" bind-source="preview" bind-property="text" 
bind-flags="bidirectional"/> -->
+            <!-- bind-flags="bidirectional"/> -->
+            <!-- <binding name="favorite"> -->
+            <!--   <lookup name="favorite" type="CoreSong"> -->
+            <!--     <lookup name="item" bind-flags="bidirectional">GtkListItem</lookup> -->
+            <!--   </lookup> -->
+            <!-- </binding> -->
+          </object>
+        </child>
       </object>
     </property>
   </template>
diff --git a/gnomemusic/widgets/discbox.py b/gnomemusic/widgets/discbox.py
index 669ae6c20..f1a9957bf 100644
--- a/gnomemusic/widgets/discbox.py
+++ b/gnomemusic/widgets/discbox.py
@@ -115,6 +115,7 @@ class DiscBox(Gtk.ListBoxRow):
         return song_widget
 
     def _song_activated(self, widget, position):
+        print("activated")
         self.emit("song-activated", self._model[position])
         # if widget.props.select_click:
         #     widget.props.select_click = False
diff --git a/gnomemusic/widgets/starimage.py b/gnomemusic/widgets/starimage.py
index 1d84ecd31..253e45305 100644
--- a/gnomemusic/widgets/starimage.py
+++ b/gnomemusic/widgets/starimage.py
@@ -38,6 +38,12 @@ class StarImage(Gtk.Image):
         self.get_style_context().add_class("star")
         self.props.visible = True
 
+        ctrl = Gtk.GestureClick().new()
+        ctrl.props.propagation_phase = Gtk.PropagationPhase.CAPTURE
+        ctrl.props.button = 1
+        ctrl.connect("pressed", self._on_pressed_cb)
+        self.add_controller(ctrl)
+
     @GObject.Property(type=bool, default=False)
     def favorite(self):
         """Return the current state of the widget
@@ -72,3 +78,9 @@ class StarImage(Gtk.Image):
             self.set_state_flags(Gtk.StateFlags.PRELIGHT, False)
         else:
             self.unset_state_flags(Gtk.StateFlags.PRELIGHT)
+
+    def _on_pressed_cb(self, gesture, n_press, x, y):
+        print("pressed")
+        self.props.favorite = not self.props.favorite
+        gesture.set_state(Gtk.EventSequenceState.CLAIMED)
+        return True


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