[gnome-music/wip/jfelder/playback-status-v4: 5/9] 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: 5/9] songwidget: Factor out songwidget state
- Date: Mon, 1 Jun 2020 00:35:40 +0000 (UTC)
commit 47bf270f5d882b698c76de66655a578836fb91d7
Author: Jean Felder <jfelder src gnome org>
Date: Fri Jan 10 00:52:18 2020 +0100
songwidget: Factor out songwidget state
WidgetState will be used by TwoLineWidget introduced in the next
commit.
gnomemusic/coremodel.py | 14 +++++++-------
gnomemusic/mpris.py | 6 +++---
gnomemusic/player.py | 18 +++++++++---------
gnomemusic/widgets/songwidget.py | 24 ++++++++++++------------
4 files changed, 31 insertions(+), 31 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 16861383..8f5a90e2 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -35,7 +35,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.widgets.songwidget import WidgetState
import gnomemusic.utils as utils
@@ -197,8 +197,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 == WidgetState.PLAYING:
+ song.props.state = WidgetState.PLAYED
self.emit("playlist-loaded", playlist_type)
return
@@ -220,10 +220,10 @@ class CoreModel(GObject.GObject):
self._playlist_model.splice(position, removed, songs_list)
- played_states = [SongWidget.State.PLAYING, SongWidget.State.PLAYED]
+ played_states = [WidgetState.PLAYING, WidgetState.PLAYED]
for song in self._playlist_model:
if song.props.state in played_states:
- song.props.state = SongWidget.State.UNPLAYED
+ song.props.state = WidgetState.UNPLAYED
if self._player_signal_id is not None:
self._current_playlist_model.disconnect(self._player_signal_id)
@@ -269,8 +269,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 == WidgetState.PLAYING:
+ song.props.state = WidgetState.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..e34f0cdc 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.widgets.songwidget import WidgetState
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 = WidgetState.PLAYED
+ new_coresong.props.state = WidgetState.PLAYING
def _track_list_replaced(self, tracks, current_song):
parameters = {
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 0148ef1d..7b41f0c5 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.widgets.songwidget import WidgetState
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 = WidgetState.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 = WidgetState.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 = WidgetState.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 = WidgetState.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 == WidgetState.PLAYING:
return current_song
for idx, coresong in enumerate(self._model):
- if coresong.props.state == SongWidget.State.PLAYING:
+ if coresong.props.state == WidgetState.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 = WidgetState.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 = WidgetState.PLAYING
self._position = idx
self._validate_song(song)
self._validate_next_song()
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 9500a051..b536cc95 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -35,6 +35,13 @@ from gnomemusic.utils import SongStateIcon
from gnomemusic.widgets.starimage import StarImage # noqa: F401
+class WidgetState(IntEnum):
+ """The state of the SongWidget"""
+ PLAYED = 0
+ PLAYING = 1
+ UNPLAYED = 2
+
+
@Gtk.Template(resource_path='/org/gnome/Music/ui/SongWidget.ui')
class SongWidget(Gtk.EventBox):
"""The single song widget used in DiscListBox
@@ -75,13 +82,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 +93,7 @@ class SongWidget(Gtk.EventBox):
self.props.coresong = coresong
self._selection_mode = False
- self._state = SongWidget.State.UNPLAYED
+ self._state = WidgetState.UNPLAYED
song_number = self.props.coresong.props.track_number
if song_number == 0:
@@ -254,7 +254,7 @@ class SongWidget(Gtk.EventBox):
"""State of the widget
:returns: Widget state
- :rtype: SongWidget.State
+ :rtype: WidgetState
"""
return self._state
@@ -265,7 +265,7 @@ class SongWidget(Gtk.EventBox):
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 WidgetState value: Widget state
"""
self._state = value
@@ -281,9 +281,9 @@ class SongWidget(Gtk.EventBox):
style_ctx.add_class("dim-label")
return
- if value == SongWidget.State.PLAYED:
+ if value == WidgetState.PLAYED:
style_ctx.add_class('dim-label')
- elif value == SongWidget.State.PLAYING:
+ elif value == WidgetState.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]