[gnome-music/wip/jfelder/playback-status-v4: 20/22] linearplaybackwidget: Introduce LinearPlaybackWidget



commit 80515d3426a2dd412976d1e6a03f2463ff4897db
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Sep 13 19:55:00 2018 +0200

    linearplaybackwidget: Introduce LinearPlaybackWidget
    
    This widget is designed to display a list of songs. Each row is a
    TwoLineWidget which displays the album cover, song title and the
    artist.
    It will be used by PlaybackPopover widget to display a playlist from
    Artists, Songs and Playlists views.

 data/org.gnome.Music.gresource.xml    |  1 +
 data/ui/LinearPlaybackWidget.ui       | 20 +++++++++
 gnomemusic/widgets/playbackpopover.py | 79 +++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 79208751..04ffc19f 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -19,6 +19,7 @@
     <file preprocess="xml-stripblanks">ui/FilterView.ui</file>
     <file preprocess="xml-stripblanks">ui/HeaderBar.ui</file>
     <file preprocess="xml-stripblanks">ui/LastfmDialog.ui</file>
+    <file preprocess="xml-stripblanks">ui/LinearPlaybackWidget.ui</file>
     <file preprocess="xml-stripblanks">ui/LoadingNotification.ui</file>
     <file preprocess="xml-stripblanks">ui/NotificationsPopup.ui</file>
     <file preprocess="xml-stripblanks">ui/PlayerToolbar.ui</file>
diff --git a/data/ui/LinearPlaybackWidget.ui b/data/ui/LinearPlaybackWidget.ui
new file mode 100644
index 00000000..ab136423
--- /dev/null
+++ b/data/ui/LinearPlaybackWidget.ui
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="LinearPlaybackWidget" parent="GtkScrolledWindow">
+    <property name="width_request">600</property>
+    <property name="height_request">400</property>
+    <property name="hexpand">True</property>
+    <property name="vexpand">True</property>
+    <child>
+      <object class="GtkListBox" id="_listbox">
+        <property name="selection_mode">none</property>
+       <property name="visible">True</property>
+        <signal name="row-activated" handler="_on_row_activated" swapped="no" />
+       <style>
+         <class name="view"/>
+         <class name="content-view"/>
+       </style>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gnomemusic/widgets/playbackpopover.py b/gnomemusic/widgets/playbackpopover.py
new file mode 100644
index 00000000..a7a9b8f9
--- /dev/null
+++ b/gnomemusic/widgets/playbackpopover.py
@@ -0,0 +1,79 @@
+# 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.utils import SongState
+from gnomemusic.widgets.twolinewidget import TwoLineWidget
+
+
+@Gtk.Template(resource_path="/org/gnome/Music/ui/LinearPlaybackWidget.ui")
+class LinearPlaybackWidget(Gtk.ScrolledWindow):
+
+    __gtype_name__ = "LinearPlaybackWidget"
+
+    _listbox = Gtk.Template.Child()
+
+    _current_index = 0
+    _playlist_type = None
+    _playlist_id = None
+    _window_height = 0.0
+    _row_height = 0.0
+
+    def __init__(self, application):
+        """Instantiate LinearPlaybackWidget
+
+        :param Application application: Application object
+        """
+        super().__init__()
+
+        self._player = application.props.player
+
+        coremodel = application.props.coremodel
+        self._model = coremodel.props.recent_playlist
+        self._listbox.bind_model(self._model, self._create_twoline_widget)
+
+        self.props.vadjustment.connect(
+            "changed", self._vertical_adjustment_changed)
+
+    def _create_twoline_widget(self, coresong):
+        row = TwoLineWidget(coresong)
+        return row
+
+    def _vertical_adjustment_changed(self, klass):
+        v_adjust = self.props.vadjustment
+        if v_adjust.props.upper != self._window_height:
+            self._window_height = v_adjust.props.upper
+            self._row_height = self._window_height / len(self._listbox)
+            v_adjust.props.value = (self._current_index * self._row_height
+                                    + self._row_height / 2
+                                    - v_adjust.props.page_size / 2)
+
+    @Gtk.Template.Callback()
+    def _on_row_activated(self, klass, row):
+        coresong = row.props.coresong
+        current_coresong = self._player.props.current_song
+        self._player.play(coresong)
+        current_coresong.props.state = SongState.PLAYED
+        coresong.props.state = SongState.PLAYING


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]