[gnome-music/wip/jfelder/playlistview-random-song: 4/7] player: Automatically select a song if none is requested
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/playlistview-random-song: 4/7] player: Automatically select a song if none is requested
- Date: Wed, 24 Apr 2019 21:18:01 +0000 (UTC)
commit dd0c277d5c049faee28df35df371c412706c8e4d
Author: Jean Felder <jfelder src gnome org>
Date: Thu Apr 18 16:06:10 2019 +0200
player: Automatically select a song if none is requested
When clicking on the play button from PlaylistView, no song is
selected. By default, the first song is automatically selected and
provided as parameter to the set_playlist method of Player. This
choice makes sense if the repeat mode is in a linear mode. However, in
shuffle mode, it is more logic to select a random song.
This commit adds the automatic selection to the set_playlist
method in PlayerPlaylist. The next one will remove the automatic
selection of the first song in PlaylistView.
gnomemusic/player.py | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index dcf42621..a1592a1b 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -115,9 +115,14 @@ class PlayerPlaylist(GObject.GObject):
self.connect("notify::repeat-mode", self._on_repeat_mode_changed)
@log
- def set_playlist(self, playlist_type, playlist_id, model, model_iter):
+ def set_playlist(self, playlist_type, playlist_id, model, model_iter=None):
"""Set a new playlist or change the song being played
+ If no song is requested (through model_iter), a song will be
+ automatically selected:
+ * the first song in a linear mode
+ * a random song in shuffle mode
+
:param PlayerPlaylist.Type playlist_type: playlist type
:param string playlist_id: unique identifer to recognize the playlist
:param GtkListStore model: list of songs to play
@@ -126,6 +131,13 @@ class PlayerPlaylist(GObject.GObject):
:return: True if the playlist has been updated. False otherwise
:rtype: bool
"""
+ if not model_iter:
+ if self.props.repeat_mode == RepeatMode.SHUFFLE:
+ index = randrange(len(model))
+ model_iter = model.get_iter_from_string(str(index))
+ else:
+ model_iter = model.get_iter_first()
+
path = model.get_path(model_iter)
self._current_index = int(path.to_string())
@@ -690,7 +702,7 @@ class Player(GObject.GObject):
self.play()
@log
- def set_playlist(self, playlist_type, playlist_id, model, iter_):
+ def set_playlist(self, playlist_type, playlist_id, model, iter_=None):
"""Set a new playlist or change the song being played.
:param PlayerPlaylist.Type playlist_type: playlist type
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]