[gnome-music/wip/jfelder/playback-status-v3: 9/12] repeatbox: Introduce RepeatBox widget
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/playback-status-v3: 9/12] repeatbox: Introduce RepeatBox widget
- Date: Wed, 30 Jan 2019 22:44:24 +0000 (UTC)
commit 986e033a754f7882542616805f04c9b69b4a0a61
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 | 83 ++++++++++++++++++++++++++++++++++++++
3 files changed, 155 insertions(+)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 200159ae..97e2dfbd 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -19,6 +19,7 @@
<file preprocess="xml-stripblanks">ui/PlaylistContextMenu.ui</file>
<file preprocess="xml-stripblanks">ui/PlaylistControls.ui</file>
<file preprocess="xml-stripblanks">ui/PlaylistDialog.ui</file>
+ <file preprocess="xml-stripblanks">ui/RepeatBox.ui</file>
<file preprocess="xml-stripblanks">ui/Searchbar.ui</file>
<file preprocess="xml-stripblanks">ui/SelectionBarMenuButton.ui</file>
<file preprocess="xml-stripblanks">ui/SelectionToolbar.ui</file>
diff --git a/data/ui/RepeatBox.ui b/data/ui/RepeatBox.ui
new file mode 100644
index 00000000..4b9b3b8a
--- /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-rtl</property>
+ </object>
+</interface>
diff --git a/gnomemusic/widgets/repeatbox.py b/gnomemusic/widgets/repeatbox.py
new file mode 100644
index 00000000..2d72204a
--- /dev/null
+++ b/gnomemusic/widgets/repeatbox.py
@@ -0,0 +1,83 @@
+# Copyright 2019 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 import log
+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 __repr__(self):
+ return '<RepeatBox>'
+
+ def __init__(self, player):
+ 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)
+
+ @log
+ 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()
+ @log
+ def _repeat_button_clicked(self, klass):
+ self._activate_button(klass)
+ self._player.props.repeat_mode = self._buttons[klass]
+
+ @log
+ 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]