[gnome-music/wip/jfelder/playback-status-v4: 4/9] repeatbox: Introduce RepeatBox widget
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/playback-status-v4: 4/9] repeatbox: Introduce RepeatBox widget
- Date: Mon, 1 Jun 2020 00:35:35 +0000 (UTC)
commit 7e62c807b5b0a4a01895a3b5443706b38d250e39
Author: Jean Felder <jfelder src gnome org>
Date: Mon Sep 10 08:40:52 2018 +0200
repeatbox: Introduce RepeatBox widget
This widget displays all the possible repeat mode into a single
horizontal box. It allows to change the repeat mode by pressing on the
corresponding button. It will be used by PlaybackPopover widget.
data/org.gnome.Music.gresource.xml | 1 +
data/ui/RepeatBox.ui | 71 +++++++++++++++++++++++++++++++++
gnomemusic/widgets/repeatbox.py | 80 ++++++++++++++++++++++++++++++++++++++
3 files changed, 152 insertions(+)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 4ef28690..efae8f4e 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -30,6 +30,7 @@
<file preprocess="xml-stripblanks">ui/PlaylistsView.ui</file>
<file preprocess="xml-stripblanks">ui/PlaylistsWidget.ui</file>
<file preprocess="xml-stripblanks">ui/PlaylistTile.ui</file>
+ <file preprocess="xml-stripblanks">ui/RepeatBox.ui</file>
<file preprocess="xml-stripblanks">ui/SearchHeaderBar.ui</file>
<file preprocess="xml-stripblanks">ui/SearchView.ui</file>
<file preprocess="xml-stripblanks">ui/SelectionBarMenuButton.ui</file>
diff --git a/data/ui/RepeatBox.ui b/data/ui/RepeatBox.ui
new file mode 100644
index 00000000..b42c30b1
--- /dev/null
+++ b/data/ui/RepeatBox.ui
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="RepeatBox" parent="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">horizontal</property>
+ <property name="homogeneous">True</property>
+ <property name="halign">center</property>
+ <property name="margin_top">6</property>
+ <property name="margin_bottom">6</property>
+ <child>
+ <object class="GtkToggleButton" id="_linear_mode_button">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">True</property>
+ <property name="image">linear_mode_image</property>
+ <property name="always_show_image">True</property>
+ <signal name="toggled" handler="_repeat_button_clicked" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="_repeat_song_mode_button">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">True</property>
+ <property name="image">repeat_song_mode_image</property>
+ <property name="always_show_image">True</property>
+ <signal name="toggled" handler="_repeat_button_clicked" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="_repeat_all_mode_button">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">True</property>
+ <property name="image">repeat_all_mode_image</property>
+ <property name="always_show_image">True</property>
+ <signal name="toggled" handler="_repeat_button_clicked" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="_shuffle_mode_button">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">True</property>
+ <property name="image">shuffle_mode_image</property>
+ <property name="always_show_image">True</property>
+ <signal name="toggled" handler="_repeat_button_clicked" swapped="no"/>
+ </object>
+ </child>
+ </template>
+ <object class="GtkImage" id="linear_mode_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">media-playlist-consecutive-symbolic</property>
+ </object>
+ <object class="GtkImage" id="shuffle_mode_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">media-playlist-shuffle-symbolic</property>
+ </object>nn
+ <object class="GtkImage" id="repeat_all_mode_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">media-playlist-repeat-symbolic</property>
+ </object>
+ <object class="GtkImage" id="repeat_song_mode_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">media-playlist-repeat-song-symbolic</property>
+ </object>
+</interface>
diff --git a/gnomemusic/widgets/repeatbox.py b/gnomemusic/widgets/repeatbox.py
new file mode 100644
index 00000000..747d32f0
--- /dev/null
+++ b/gnomemusic/widgets/repeatbox.py
@@ -0,0 +1,80 @@
+# Copyright 2020 The GNOME Music developers
+#
+# GNOME Music is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# GNOME Music is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with GNOME Music; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# The GNOME Music authors hereby grant permission for non-GPL compatible
+# GStreamer plugins to be used and distributed together with GStreamer
+# and GNOME Music. This permission is above and beyond the permissions
+# granted by the GPL license by which GNOME Music is covered. If you
+# modify this code, you may extend this exception to your version of the
+# 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 gi.repository import Gtk
+
+from gnomemusic.player import RepeatMode
+
+
+@Gtk.Template(resource_path="/org/gnome/Music/ui/RepeatBox.ui")
+class RepeatBox(Gtk.Box):
+
+ __gtype_name__ = "RepeatBox"
+
+ _linear_mode_button = Gtk.Template.Child()
+ _shuffle_mode_button = Gtk.Template.Child()
+ _repeat_all_mode_button = Gtk.Template.Child()
+ _repeat_song_mode_button = Gtk.Template.Child()
+
+ def __init__(self, player):
+ """Initialize the object
+
+ :param Player player: Player object
+ """
+ super().__init__()
+
+ self._player = player
+ self._player.connect(
+ "notify::repeat-mode", self._on_repeat_mode_changed)
+
+ self._buttons = {
+ self._linear_mode_button: RepeatMode.NONE,
+ self._shuffle_mode_button: RepeatMode.SHUFFLE,
+ self._repeat_all_mode_button: RepeatMode.ALL,
+ self._repeat_song_mode_button: RepeatMode.SONG
+ }
+ self._on_repeat_mode_changed(self._player)
+
+ def _on_repeat_mode_changed(self, klass, param=None):
+ repeat_mode = self._player.props.repeat_mode
+ button_index = list(self._buttons.values()).index(repeat_mode)
+ button = list(self._buttons.keys())[button_index]
+ self._activate_button(button)
+
+ @Gtk.Template.Callback()
+ def _repeat_button_clicked(self, klass):
+ self._activate_button(klass)
+ self._player.props.repeat_mode = self._buttons[klass]
+
+ def _activate_button(self, button_to_activate):
+ for button in self._buttons:
+ button.handler_block_by_func(self._repeat_button_clicked)
+ if (button != button_to_activate
+ and button.props.active):
+ button.props.active = False
+
+ button_to_activate.props.active = True
+
+ for button in self._buttons:
+ button.handler_unblock_by_func(self._repeat_button_clicked)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]