[gnome-music/wip/mschraal/window-template: 4/6] playertoolbar: Make player argument a property
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/window-template: 4/6] playertoolbar: Make player argument a property
- Date: Mon, 27 May 2019 21:36:43 +0000 (UTC)
commit 19b6bc570acd8b8827abb1067be6e3c97f341c68
Author: Marinus Schraal <mschraal gnome org>
Date: Sun May 5 00:20:38 2019 +0200
playertoolbar: Make player argument a property
gnomemusic/widgets/playertoolbar.py | 34 +++++++++++++++++++++++++++++-----
gnomemusic/window.py | 3 ++-
2 files changed, 31 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index c0ee9f83..cd650ad2 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -28,7 +28,7 @@ from gi.repository import GObject, Gtk
from gnomemusic import log
from gnomemusic.albumartcache import Art
from gnomemusic.gstplayer import Playback
-from gnomemusic.player import RepeatMode
+from gnomemusic.player import Player, RepeatMode
from gnomemusic.widgets.coverstack import CoverStack # noqa: F401
from gnomemusic.widgets.smoothscale import SmoothScale # noqa: F401
from gnomemusic.widgets.twolinetip import TwoLineTip
@@ -66,24 +66,48 @@ class PlayerToolbar(Gtk.ActionBar):
return '<PlayerToolbar>'
@log
- def __init__(self, player):
+ def __init__(self):
super().__init__()
- self._player = player
- self._progress_scale.props.player = self._player
+ self._player = None
self._cover_stack.props.size = Art.Size.XSMALL
self._cover_stack.connect('updated', self._on_cover_stack_updated)
self._tooltip = TwoLineTip()
- self._sync_repeat_image()
+ # FIXME: This is a workaround for not being able to pass the player
+ # object via init when using Gtk.Builder.
+ @GObject.Property(type=Player, default=None)
+ def player(self):
+ """The GstPlayer object used
+
+ :return: player object
+ :rtype: GstPlayer
+ """
+ return self._player
+
+ @player.setter
+ def player(self, player):
+ """Set the GstPlayer object used
+
+ :param GstPlayer player: The GstPlayer to use
+ """
+ if (player is None
+ or (self._player is not None
+ and self._player != player)):
+ return
+
+ self._player = player
+ self._progress_scale.props.player = self._player
self._player.connect('song-changed', self._update_view)
self._player.connect(
'notify::repeat-mode', self._on_repeat_mode_changed)
self._player.connect('notify::state', self._sync_playing)
+ self._sync_repeat_image()
+
@Gtk.Template.Callback()
@log
def _on_progress_value_changed(self, progress_scale):
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 2c6c9932..a9712690 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -142,7 +142,8 @@ class Window(Gtk.ApplicationWindow):
"state", self._searchbar, "search-state",
GObject.BindingFlags.SYNC_CREATE)
- self._player_toolbar = PlayerToolbar(self._player)
+ self._player_toolbar = PlayerToolbar()
+ self._player_toolbar.props.player = self._player
self.views = [None] * len(View)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]