[gnome-music/wip/jfelder/playback-status-v4: 6/9] songwidget: Introduce TwoLineWidget
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/playback-status-v4: 6/9] songwidget: Introduce TwoLineWidget
- Date: Mon, 1 Jun 2020 00:39:41 +0000 (UTC)
commit 3ab874f71042963d5c1c22b32961038e494c9d1a
Author: Jean Felder <jfelder src gnome org>
Date: Sat Mar 14 17:06:22 2020 +0100
songwidget: Introduce TwoLineWidget
data/org.gnome.Music.gresource.xml | 1 +
data/ui/TwoLineWidget.ui | 71 +++++++++++++++++++++++++++
gnomemusic/widgets/twolinewidget.py | 96 +++++++++++++++++++++++++++++++++++++
3 files changed, 168 insertions(+)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index efae8f4e..79208751 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -38,6 +38,7 @@
<file preprocess="xml-stripblanks">ui/SongsView.ui</file>
<file preprocess="xml-stripblanks">ui/SongWidget.ui</file>
<file preprocess="xml-stripblanks">ui/TwoLineTip.ui</file>
+ <file preprocess="xml-stripblanks">ui/TwoLineWidget.ui</file>
<file preprocess="xml-stripblanks">ui/Window.ui</file>
</gresource>
</gresources>
diff --git a/data/ui/TwoLineWidget.ui b/data/ui/TwoLineWidget.ui
new file mode 100644
index 00000000..93ee5b02
--- /dev/null
+++ b/data/ui/TwoLineWidget.ui
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="TwoLineWidget" parent="GtkListBoxRow">
+ <property name="can_focus">False</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkBox">
+ <property name="can_focus">False</property>
+ <property name="hexpand">False</property>
+ <property name="orientation">horizontal</property>
+ <property name="visible">True</property>
+ <property name="margin">6</property>
+ <property name="spacing">8</property>
+ <child>
+ <object class="GtkImage" id="_play_icon">
+ <property name="icon_size">4</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <property name="halign">fill</property>
+ <property name="hexpand">True</property>
+ <property name="visible">True</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="CoverStack" id="_cover_stack">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="_main_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">fill</property>
+ <property name="hexpand">true</property>
+ <property name="valign">start</property>
+ <property name="xalign">0</property>
+ <property name="ellipsize">middle</property>
+ <property name="width_chars">8</property>
+ <property name="max_width_chars">42</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="_secondary_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="valign">start</property>
+ <property name="xalign">0</property>
+ <property name="ellipsize">middle</property>
+ <property name="width_chars">8</property>
+ <property name="max_width_chars">42</property>
+ <style>
+ <class name="player-artist-label"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/gnomemusic/widgets/twolinewidget.py b/gnomemusic/widgets/twolinewidget.py
new file mode 100644
index 00000000..66c74143
--- /dev/null
+++ b/gnomemusic/widgets/twolinewidget.py
@@ -0,0 +1,96 @@
+# 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 GObject, Gtk
+
+from gnomemusic.albumartcache import Art
+from gnomemusic.coresong import CoreSong
+from gnomemusic.widgets.songwidget import WidgetState
+
+
+@Gtk.Template(resource_path="/org/gnome/Music/ui/TwoLineWidget.ui")
+class TwoLineWidget(Gtk.ListBoxRow):
+
+ __gtype_name__ = "TwoLineWidget"
+
+ coresong = GObject.Property(type=CoreSong, default=None)
+
+ _cover_stack = Gtk.Template.Child()
+ _main_label = Gtk.Template.Child()
+ _play_icon = Gtk.Template.Child()
+ _secondary_label = Gtk.Template.Child()
+
+ def __init__(self, coresong):
+ """Instantiate a TwoLineWidget
+
+ :param Corsong coresong: song associated with the widget
+ """
+ super().__init__()
+
+ self.props.coresong = coresong
+
+ self._main_label.props.label = coresong.props.title
+ self._secondary_label.props.label = coresong.props.artist
+
+ self._cover_stack.props.size = Art.Size.SMALL
+ self._cover_stack.update(coresong)
+
+ self.props.coresong.bind_property(
+ "state", self, "state",
+ GObject.BindingFlags.SYNC_CREATE)
+
+ @GObject.Property
+ def state(self):
+ """State of the widget
+
+ :returns: Widget state
+ :rtype: WidgetState
+ """
+ return self._state
+
+ @state.setter
+ def state(self, value):
+ """Set state of the of widget
+
+ This influences the look of the widgets label and if there is a
+ song play indicator being shown.
+
+ :param WidgetState value: Widget state
+ """
+ self._state = value
+
+ main_style_ctx = self._main_label.get_style_context()
+ secondary_style_ctx = self._secondary_label.get_style_context()
+
+ main_style_ctx.remove_class("dim-label")
+ main_style_ctx.remove_class("playing-song-label")
+ secondary_style_ctx.remove_class("dim-label")
+ self._play_icon.props.icon_name = ""
+
+ if value == WidgetState.PLAYED:
+ main_style_ctx.add_class("dim-label")
+ secondary_style_ctx.add_class("dim-label")
+ elif value == WidgetState.PLAYING:
+ self._play_icon.props.icon_name = "media-playback-start-symbolic"
+ main_style_ctx.add_class("playing-song-label")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]