[gnome-music/gbsneto/untangle-player-window-mpris: 6/6] window: Move Player to Application
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/gbsneto/untangle-player-window-mpris: 6/6] window: Move Player to Application
- Date: Fri, 12 Apr 2019 13:13:50 +0000 (UTC)
commit f097c7f8b54a0044539dcaded0fc4d4ab332c0e0
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Apr 10 12:32:46 2019 -0300
window: Move Player to Application
Architecturally-wise, the music player object is not
tied to the active window in any form. So holding it
in Window is an anti-pattern - Window is not the right
place for Player to be.
Move Player to Application, and make it a property so
that it can be accessed as application.props.player.
It is a readable property, since there is no reason
to change it.
At last, add docstrings to the init method.
gnomemusic/application.py | 15 ++++++++++++++-
gnomemusic/mpris.py | 2 +-
gnomemusic/player.py | 4 ++++
gnomemusic/window.py | 4 ++--
4 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index 59e7e66c..9d78fb7e 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -33,10 +33,11 @@
from gettext import gettext as _
import logging
-from gi.repository import Gtk, Gio, GLib, Gdk
+from gi.repository import Gtk, Gio, GLib, Gdk, GObject
from gnomemusic import log
from gnomemusic.mpris import MediaPlayer2Service
+from gnomemusic.player import Player
from gnomemusic.widgets.aboutdialog import AboutDialog
from gnomemusic.window import Window
@@ -59,6 +60,8 @@ class Application(Gtk.Application):
self._init_style()
self._window = None
+ self._player = Player(self)
+
def _init_style(self):
css_provider = Gtk.CssProvider()
css_provider.load_from_resource('/org/gnome/Music/org.gnome.Music.css')
@@ -67,6 +70,16 @@ class Application(Gtk.Application):
style_context.add_provider_for_screen(
screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
+ @GObject.Property(
+ type=Player, default=None, flags=GObject.ParamFlags.READABLE)
+ def player(self):
+ """Get application-wide music player.
+
+ :returns: the player
+ :rtype: Player
+ """
+ return self._player
+
@log
def _build_app_menu(self):
action_entries = [
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 6639c080..a00b6f60 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -219,7 +219,7 @@ class MediaPlayer2Service(Server):
super().__init__(self.con, '/org/mpris/MediaPlayer2')
self.app = app
- self.player = app.get_active_window()._player
+ self.player = app.props.player
self.player.connect(
'song-changed', self._on_current_song_changed)
self.player.connect('notify::state', self._on_player_state_changed)
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 762f955e..bc362d1d 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -572,6 +572,10 @@ class Player(GObject.GObject):
@log
def __init__(self, application):
+ """Initialize the player
+
+ :param Application application: Application object
+ """
super().__init__()
self._playlist = PlayerPlaylist()
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 462e5c2f..02f13cb3 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -35,7 +35,7 @@ from gettext import gettext as _
from gnomemusic import log
from gnomemusic.grilo import grilo
from gnomemusic.mediakeys import MediaKeys
-from gnomemusic.player import Player, RepeatMode
+from gnomemusic.player import RepeatMode
from gnomemusic.playlists import Playlists
from gnomemusic.query import Query
from gnomemusic.search import Search
@@ -87,7 +87,7 @@ class Window(Gtk.ApplicationWindow):
self.prev_view = None
self.curr_view = None
- self._player = Player(app)
+ self._player = app.props.player
self.notifications_popup = NotificationsPopup()
self._setup_view()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]