[gnome-music/wip/jfelder/playback-status-v4: 1/5] songwidget: Factor out songwidget state
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/playback-status-v4: 1/5] songwidget: Factor out songwidget state
- Date: Tue, 30 Jun 2020 18:38:10 +0000 (UTC)
commit 3fc21bf04c4bc10a27a6f32a2fa2f41546ea7cb8
Author: Jean Felder <jfelder src gnome org>
Date: Fri Jan 10 00:52:18 2020 +0100
songwidget: Factor out songwidget state
And rename it to SongState as it is more like a CoreSong state in
relation to a playlist.
SongState will be used by TwoLineWidget introduced in the next
commit.
gnomemusic/coremodel.py | 14 +++++++-------
gnomemusic/mpris.py | 6 +++---
gnomemusic/player.py | 18 +++++++++---------
gnomemusic/utils.py | 7 +++++++
gnomemusic/widgets/songwidget.py | 25 ++++++++-----------------
5 files changed, 34 insertions(+), 36 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 3e8a5bc9..c967fb02 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -34,7 +34,7 @@ from gnomemusic.coresong import CoreSong
from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
from gnomemusic.player import PlayerPlaylist
from gnomemusic.songliststore import SongListStore
-from gnomemusic.widgets.songwidget import SongWidget
+from gnomemusic.utils import SongState
import gnomemusic.utils as utils
@@ -196,8 +196,8 @@ class CoreModel(GObject.GObject):
"""
if model is self._previous_playlist_model:
for song in self._playlist_model:
- if song.props.state == SongWidget.State.PLAYING:
- song.props.state = SongWidget.State.PLAYED
+ if song.props.state == SongState.PLAYING:
+ song.props.state = SongState.PLAYED
self.emit("playlist-loaded", playlist_type)
return
@@ -219,10 +219,10 @@ class CoreModel(GObject.GObject):
self._playlist_model.splice(position, removed, songs_list)
- played_states = [SongWidget.State.PLAYING, SongWidget.State.PLAYED]
+ played_states = [SongState.PLAYING, SongState.PLAYED]
for song in self._playlist_model:
if song.props.state in played_states:
- song.props.state = SongWidget.State.UNPLAYED
+ song.props.state = SongState.UNPLAYED
if self._player_signal_id is not None:
self._current_playlist_model.disconnect(self._player_signal_id)
@@ -268,8 +268,8 @@ class CoreModel(GObject.GObject):
for song in self._songliststore.props.model:
songs_added.append(song)
- if song.props.state == SongWidget.State.PLAYING:
- song.props.state = SongWidget.State.PLAYED
+ if song.props.state == SongState.PLAYING:
+ song.props.state = SongState.PLAYED
elif playlist_type == PlayerPlaylist.Type.SEARCH_RESULT:
self._current_playlist_model = self._songs_search_flatten
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 4c10bc39..10d04463 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -31,7 +31,7 @@ from gnomemusic.albumartcache import lookup_art_file_from_cache
from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
from gnomemusic.gstplayer import Playback
from gnomemusic.player import PlayerPlaylist, RepeatMode
-from gnomemusic.widgets.songwidget import SongWidget
+from gnomemusic.utils import SongState
class DBusInterface:
@@ -734,8 +734,8 @@ class MPRIS(DBusInterface):
new_coresong = self._player_model[goto_index]
self._player.play(new_coresong)
- current_coresong.props.state = SongWidget.State.PLAYED
- new_coresong.props.state = SongWidget.State.PLAYING
+ current_coresong.props.state = SongState.PLAYED
+ new_coresong.props.state = SongState.PLAYING
def _track_list_replaced(self, tracks, current_song):
parameters = {
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 0462eb48..cd425b66 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -32,7 +32,7 @@ from gi.repository import GObject, GstPbutils
from gnomemusic.coresong import CoreSong
from gnomemusic.gstplayer import GstPlayer, Playback
-from gnomemusic.widgets.songwidget import SongWidget
+from gnomemusic.utils import SongState
import gnomemusic.utils as utils
@@ -144,7 +144,7 @@ class PlayerPlaylist(GObject.GObject):
else:
next_position = self.props.position + 1
- self._model[self.props.position].props.state = SongWidget.State.PLAYED
+ self._model[self.props.position].props.state = SongState.PLAYED
self._position = next_position
next_song = self._model[next_position]
@@ -152,7 +152,7 @@ class PlayerPlaylist(GObject.GObject):
return self.next()
self._update_model_recent()
- next_song.props.state = SongWidget.State.PLAYING
+ next_song.props.state = SongState.PLAYING
self._validate_next_song()
return True
@@ -173,7 +173,7 @@ class PlayerPlaylist(GObject.GObject):
else:
previous_position = self.props.position - 1
- self._model[self.props.position].props.state = SongWidget.State.PLAYED
+ self._model[self.props.position].props.state = SongState.PLAYED
self._position = previous_position
previous_song = self._model[previous_position]
@@ -181,7 +181,7 @@ class PlayerPlaylist(GObject.GObject):
return self.previous()
self._update_model_recent()
- self._model[previous_position].props.state = SongWidget.State.PLAYING
+ self._model[previous_position].props.state = SongState.PLAYING
self._validate_previous_song()
return True
@@ -206,11 +206,11 @@ class PlayerPlaylist(GObject.GObject):
if (n_items != 0
and n_items > self._position):
current_song = self._model[self._position]
- if current_song.props.state == SongWidget.State.PLAYING:
+ if current_song.props.state == SongState.PLAYING:
return current_song
for idx, coresong in enumerate(self._model):
- if coresong.props.state == SongWidget.State.PLAYING:
+ if coresong.props.state == SongState.PLAYING:
self._position = idx
self._update_model_recent()
return coresong
@@ -235,7 +235,7 @@ class PlayerPlaylist(GObject.GObject):
else:
position = 0
song = self._model.get_item(position)
- song.props.state = SongWidget.State.PLAYING
+ song.props.state = SongState.PLAYING
self._position = position
self._validate_song(song)
self._validate_next_song()
@@ -244,7 +244,7 @@ class PlayerPlaylist(GObject.GObject):
for idx, coresong in enumerate(self._model):
if coresong == song:
- coresong.props.state = SongWidget.State.PLAYING
+ coresong.props.state = SongState.PLAYING
self._position = idx
self._validate_song(song)
self._validate_next_song()
diff --git a/gnomemusic/utils.py b/gnomemusic/utils.py
index b00f5ec1..a7b0e9f1 100644
--- a/gnomemusic/utils.py
+++ b/gnomemusic/utils.py
@@ -31,6 +31,13 @@ from gi.repository import Gio
from gi._gi import pygobject_new_full
+class SongState(IntEnum):
+ """The state of a CoreSong"""
+ PLAYED = 0
+ PLAYING = 1
+ UNPLAYED = 2
+
+
class SongStateIcon(Enum):
"""Enum for icons used in song playing and validation"""
ERROR = "dialog-error-symbolic"
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 8846e876..7e58c2e4 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -22,8 +22,6 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
-from enum import IntEnum
-
import gi
gi.require_version('Dazzle', '1.0')
from gi.repository import Gdk, GObject, Gtk
@@ -31,7 +29,7 @@ from gi.repository.Dazzle import BoldingLabel # noqa: F401
from gnomemusic import utils
from gnomemusic.coresong import CoreSong
-from gnomemusic.utils import SongStateIcon
+from gnomemusic.utils import SongState, SongStateIcon
from gnomemusic.widgets.starimage import StarImage # noqa: F401
@@ -75,13 +73,6 @@ class SongWidget(Gtk.EventBox):
_play_icon = Gtk.Template.Child()
_size_group = Gtk.Template.Child()
- class State(IntEnum):
- """The state of the SongWidget
- """
- PLAYED = 0
- PLAYING = 1
- UNPLAYED = 2
-
def __init__(self, coresong, can_dnd=False, show_artist_and_album=False):
"""Instanciates a SongWidget
@@ -93,7 +84,7 @@ class SongWidget(Gtk.EventBox):
self.props.coresong = coresong
self._selection_mode = False
- self._state = SongWidget.State.UNPLAYED
+ self._state = SongState.UNPLAYED
self.props.coresong.bind_property(
"track-number", self, "song-number",
@@ -257,19 +248,19 @@ class SongWidget(Gtk.EventBox):
def state(self):
"""State of the widget
- :returns: Widget state
- :rtype: SongWidget.State
+ :returns: CoreSong state
+ :rtype: SongState
"""
return self._state
@state.setter
def state(self, value):
- """Set state of the of widget
+ """Set state of the widget
This influences the look of the widgets label and if there is a
song play indicator being shown.
- :param SongWidget.State value: Widget state
+ :param SongState value: CoreSong state
"""
self._state = value
@@ -285,9 +276,9 @@ class SongWidget(Gtk.EventBox):
style_ctx.add_class("dim-label")
return
- if value == SongWidget.State.PLAYED:
+ if value == SongState.PLAYED:
style_ctx.add_class('dim-label')
- elif value == SongWidget.State.PLAYING:
+ elif value == SongState.PLAYING:
self._play_icon.set_visible(True)
style_ctx.add_class('playing-song-label')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]