[gnome-music] notificationspopup: Port PlaylistNotification to GtkTemplate



commit 368548db0cb5174dc4ed6d51a759e44c5bdf28c7
Author: Atharva Veer <adveer_b17 it vjti ac in>
Date:   Tue Mar 31 20:52:34 2020 +0530

    notificationspopup: Port PlaylistNotification to GtkTemplate

 data/org.gnome.Music.gresource.xml       |  1 +
 data/ui/PlaylistNotification.ui          | 39 ++++++++++++++++++++++++++++++++
 gnomemusic/widgets/notificationspopup.py | 24 ++++++++------------
 po/POTFILES.in                           |  1 +
 4 files changed, 50 insertions(+), 15 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 999cac2a..4e088e1c 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -25,6 +25,7 @@
     <file preprocess="xml-stripblanks">ui/PlaylistControls.ui</file>
     <file preprocess="xml-stripblanks">ui/PlaylistDialog.ui</file>
     <file preprocess="xml-stripblanks">ui/PlaylistDialogRow.ui</file>
+    <file preprocess="xml-stripblanks">ui/PlaylistNotification.ui</file>
     <file preprocess="xml-stripblanks">ui/PlaylistsView.ui</file>
     <file preprocess="xml-stripblanks">ui/PlaylistsWidget.ui</file>
     <file preprocess="xml-stripblanks">ui/PlaylistTile.ui</file>
diff --git a/data/ui/PlaylistNotification.ui b/data/ui/PlaylistNotification.ui
new file mode 100644
index 00000000..b10ee723
--- /dev/null
+++ b/data/ui/PlaylistNotification.ui
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkImage" id="close_notification_window">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="icon_name">window-close-symbolic</property>
+    <property name="icon_size">1</property>
+  </object>
+  <template class="PlaylistNotification" parent="GtkGrid">
+    <property name="visible">True</property>
+    <property name="column_spacing">18</property>
+    <child>
+      <object class="GtkLabel" id="_label">
+        <property name="visible">True</property>
+        <property name="halign">start</property>
+        <property name="hexpand">True</property>
+        <property name="label" translatable="yes"></property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkButton">
+        <property name="label" translatable="yes">_Undo</property>
+        <property name="use_underline">True</property>
+        <property name="visible">True</property>
+        <signal name="clicked" handler="_undo_deletion" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkButton">
+        <property name="always_show_image">True</property>
+        <property name="image">close_notification_window</property>
+        <property name="image_position">right</property>
+        <property name="relief">none</property>
+        <property name="visible">True</property>
+        <signal name="clicked" handler="_close_notification" swapped="no"/>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gnomemusic/widgets/notificationspopup.py b/gnomemusic/widgets/notificationspopup.py
index 36791b57..1827153f 100644
--- a/gnomemusic/widgets/notificationspopup.py
+++ b/gnomemusic/widgets/notificationspopup.py
@@ -165,6 +165,7 @@ class LoadingNotification(Gtk.Grid):
         self._counter = self._counter + 1
 
 
+@Gtk.Template(resource_path="/org/gnome/Music/ui/PlaylistNotification.ui")
 class PlaylistNotification(Gtk.Grid):
     """Show a notification on playlist or song deletion.
 
@@ -172,6 +173,10 @@ class PlaylistNotification(Gtk.Grid):
     to the NotificationsPopup.
     """
 
+    __gtype_name__ = "PlaylistNotification"
+
+    _label = Gtk.Template.Child()
+
     class Type(IntEnum):
         """Enum for Playlists Notifications"""
         PLAYLIST = 0
@@ -189,7 +194,7 @@ class PlaylistNotification(Gtk.Grid):
         :param int position: position of the object to delete
         :param object coresong: CoreSong for song deletion
         """
-        super().__init__(column_spacing=18)
+        super().__init__()
         self._notifications_popup = notifications_popup
         self._coregrilo = application.props.coregrilo
         self.type_ = type_
@@ -198,20 +203,7 @@ class PlaylistNotification(Gtk.Grid):
         self._coresong = coresong
 
         message = self._create_notification_message()
-        self._label = Gtk.Label(
-            label=message, halign=Gtk.Align.START, hexpand=True)
-        self.add(self._label)
-
-        close_button = Gtk.Button.new_from_icon_name(
-            "window-close-symbolic", Gtk.IconSize.BUTTON)
-        close_button.connect("clicked", self._close_notification)
-        close_button.props.relief = Gtk.ReliefStyle.NONE
-
-        undo_button = Gtk.Button.new_with_mnemonic(_("_Undo"))
-        undo_button.connect("clicked", self._undo_deletion)
-        self.add(undo_button)
-        self.add(close_button)
-        self.show_all()
+        self._label.props.label = message
 
         if self.type_ == PlaylistNotification.Type.PLAYLIST:
             self._coregrilo.stage_playlist_deletion(self._playlist)
@@ -232,6 +224,7 @@ class PlaylistNotification(Gtk.Grid):
 
         return msg
 
+    @Gtk.Template.Callback()
     def _undo_deletion(self, widget_):
         """Undo deletion and remove notification"""
         if self._timeout_id > 0:
@@ -245,6 +238,7 @@ class PlaylistNotification(Gtk.Grid):
             self._playlist.undo_pending_song_deletion(
                 self._coresong, self._position)
 
+    @Gtk.Template.Callback()
     def _close_notification(self, widget_):
         if self._timeout_id > 0:
             GLib.source_remove(self._timeout_id)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a01d6928..dc53fe14 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,6 +14,7 @@ data/ui/PlayerToolbar.ui
 data/ui/PlaylistContextMenu.ui
 data/ui/PlaylistControls.ui
 data/ui/PlaylistDialog.ui
+data/ui/PlaylistNotification.ui
 data/ui/SearchHeaderBar.ui
 data/ui/SearchView.ui
 data/ui/SelectionBarMenuButton.ui


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