[gnome-music/wip/jfelder/event-controller-key: 1/3] playlistcontrols: Use a controller for rename entry




commit 2a79e3ad3b9f29798d0a464efdd243356e6e861d
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Mar 24 20:39:29 2021 +0100

    playlistcontrols: Use a controller for rename entry
    
    The "key-press-event" signal has been removed from GTK4. Use a
    controller instead.

 data/ui/PlaylistControls.ui            | 5 ++++-
 gnomemusic/widgets/playlistcontrols.py | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/PlaylistControls.ui b/data/ui/PlaylistControls.ui
index 0c52d1b82..7a2024f95 100644
--- a/data/ui/PlaylistControls.ui
+++ b/data/ui/PlaylistControls.ui
@@ -62,7 +62,6 @@
                 <property name="receives_default">True</property>
                 <signal name="activate" handler="_on_playlist_renamed" swapped="no"/>
                 <signal name="changed" handler="_on_rename_entry_changed" swapped="no"/>
-                <signal name="key-press-event" handler="_on_rename_entry_key_pressed" swapped="no"/>
               </object>
             </child>
             <child>
@@ -136,4 +135,8 @@
       </packing>
     </child>
   </template>
+  <object class="GtkEventControllerKey" id="_rename_controller">
+    <property name="widget">_rename_entry</property>
+    <signal name="key-pressed" handler="_on_rename_entry_key_pressed" swapped="no"/>
+  </object>
 </interface>
diff --git a/gnomemusic/widgets/playlistcontrols.py b/gnomemusic/widgets/playlistcontrols.py
index d55291e39..9d5b9a821 100644
--- a/gnomemusic/widgets/playlistcontrols.py
+++ b/gnomemusic/widgets/playlistcontrols.py
@@ -38,6 +38,7 @@ class PlaylistControls(Gtk.Grid):
 
     _name_stack = Gtk.Template.Child()
     _name_label = Gtk.Template.Child()
+    _rename_controller = Gtk.Template.Child()
     _rename_entry = Gtk.Template.Child()
     _rename_done_button = Gtk.Template.Child()
     _songs_count_label = Gtk.Template.Child()
@@ -107,8 +108,7 @@ class PlaylistControls(Gtk.Grid):
         self._rename_done_button.props.sensitive = selection_length > 0
 
     @Gtk.Template.Callback()
-    def _on_rename_entry_key_pressed(self, widget, event):
-        (_, keyval) = event.get_keyval()
+    def _on_rename_entry_key_pressed(self, controller, keyval, keycode, state):
         if keyval == Gdk.KEY_Escape:
             self._disable_rename_playlist()
 


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