[gnome-music/wip/jfelder/songwidget-coreson-bind-properties] songwidget: Bind coresong properties



commit 935be6b9d7fc0b2e955374f9d875d32003dda0ba
Author: Jean Felder <jfelder src gnome org>
Date:   Sat Feb 29 21:48:15 2020 +0100

    songwidget: Bind coresong properties
    
    A SongWiget is not updated when a song title, number, artist or album
    changes.
    
    Fix the issue by creating some binding between some SongWidget
    labels (song_number, title, artist and album) and their corresponding
    property from the CoreSong.

 gnomemusic/widgets/songwidget.py | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index e6eccd77..8af44bb6 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -97,25 +97,29 @@ class SongWidget(Gtk.EventBox):
         self._selection_mode = False
         self._state = SongWidget.State.UNPLAYED
 
-        song_number = self.props.coresong.props.track_number
-        if song_number == 0:
-            song_number = ""
-        self._number_label.set_text(str(song_number))
+        self.props.coresong.bind_property(
+            "track-number", self, "song-number",
+            GObject.BindingFlags.SYNC_CREATE)
 
-        title = self.props.coresong.props.title
         self._title_label.set_max_width_chars(50)
-        self._title_label.set_text(title)
-        self._title_label.props.tooltip_text = title
+        self.props.coresong.bind_property(
+            "title", self._title_label, "label",
+            GObject.BindingFlags.SYNC_CREATE)
+        self.props.coresong.bind_property(
+            "title", self._title_label, "tooltip-text",
+            GObject.BindingFlags.SYNC_CREATE)
 
         time = utils.seconds_to_string(self.props.coresong.props.duration)
         self._duration_label.props.label = time
 
         if show_artist_and_album is True:
-            album = self.props.coresong.props.album
-            self._album_label.props.label = album
+            self.props.coresong.bind_property(
+                "album", self._album_label, "label",
+                GObject.BindingFlags.SYNC_CREATE)
             self._album_label.props.visible = True
-            artist = self.props.coresong.props.artist
-            self._artist_label.props.label = artist
+            self.props.coresong.bind_property(
+                "artist", self._artist_label, "label",
+                GObject.BindingFlags.SYNC_CREATE)
             self._artist_box.props.visible = True
         else:
             self._size_group.remove_widget(self._album_duration_box)


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