[gnome-music/wip/mschraal/core: 86/164] different selection approaches combined



commit b0799bde72ed59c4357b46898b65bff76cf9123c
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu Jun 20 23:33:01 2019 +0200

    different selection approaches combined

 gnomemusic/coregrilo.py                      |  5 ++--
 gnomemusic/coremodel.py                      | 41 ++++++++++++++++++++++++++--
 gnomemusic/grilowrappers/grltrackersource.py |  6 +++-
 3 files changed, 47 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index a9de748e..e65b5e13 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -15,10 +15,11 @@ class CoreGrilo(GObject.GObject):
 
     def __init__(
             self, coremodel, model, _hash, url_hash, albums_model,
-            artists_model):
+            artists_model, coreselection):
         super().__init__()
 
         self._coremodel = coremodel
+        self._coreselection = coreselection
         self._model = model
         self._albums_model = albums_model
         self._artists_model = artists_model
@@ -45,7 +46,7 @@ class CoreGrilo(GObject.GObject):
         if source.props.source_id == "grl-tracker-source":
             self._tracker_source = GrlTrackerSource(
                 source, self._hash, self._model, self._albums_model,
-                self._artists_model, self._coremodel)
+                self._artists_model, self._coremodel, self._coreselection)
             # self._tracker_source = source
             print(self._tracker_source, "added")
 
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 0799a1b8..fe3d1c91 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -1,6 +1,6 @@
 import gi
 gi.require_version('Dazzle', '1.0')
-from gi.repository import Dazzle, GObject, Gio, Gfm, Grl
+from gi.repository import Dazzle, GObject, Gio, Gfm, Grl, GLib
 from gi._gi import pygobject_new_full
 
 from gnomemusic import log
@@ -25,6 +25,30 @@ from gnomemusic.widgets.songwidget import SongWidget
 # flattened and recreated as a new model. This is to allow for multiple
 # occurences of the same song: same grilo id, but unique object.
 
+
+class CoreSelection(GObject.GObject):
+
+    def __init__(self):
+        super().__init__()
+
+        self._selected_items = []
+
+    def blah(self, coresong, value):
+        if coresong.props.selected:
+            self.props.selected_items.append(coresong)
+        else:
+            try:
+                self.props.selected_items.remove(coresong)
+            except ValueError as e:
+                pass
+
+        print(self.props.selected_items)
+
+    @GObject.property
+    def selected_items(self):
+        return self._selected_items
+
+
 class CoreDisc(GObject.GObject):
 
     duration = GObject.Property(type=int, default=None)
@@ -69,6 +93,8 @@ class CoreModel(GObject.GObject):
 
         self._model = Gio.ListStore.new(CoreSong)
 
+        self._core_selection = CoreSelection()
+
         self._album_model = Gio.ListStore()
         self._album_model_sort = Gfm.SortListModel.new(self._album_model)
         self._album_model_sort.set_sort_func(
@@ -79,13 +105,24 @@ class CoreModel(GObject.GObject):
         self._playlist_model = Gio.ListStore.new(CoreSong)
         self._playlist_model_sort = Gfm.SortListModel.new(self._playlist_model)
 
+        self._selection_model = Dazzle.ListModelFilter.new(self._model)
+        self._selection_model.set_filter_func(self._filter_selected)
+
         self._album_store = None
         self._hash = {}
         self._url_hash = {}
         print("PLAYLIST_MODEL", self._playlist_model)
         self._grilo = CoreGrilo(
             self, self._model, self._hash, self._url_hash, self._album_model,
-            self._artist_model)
+            self._artist_model, self._core_selection)
+
+        self._selection_model.connect("items-changed", self._on_sel_changed)
+
+    def _on_sel_changed(self, model, position, added, removed):
+        print("selection changed", model.get_n_items())
+
+    def _filter_selected(self, coresong):
+        return coresong.props.selected
 
     def _albums_sort(self, album_a, album_b):
         return album_b.props.title.lower() < album_a.props.title.lower()
diff --git a/gnomemusic/grilowrappers/grltrackersource.py b/gnomemusic/grilowrappers/grltrackersource.py
index 4ecc5f16..59434d5d 100644
--- a/gnomemusic/grilowrappers/grltrackersource.py
+++ b/gnomemusic/grilowrappers/grltrackersource.py
@@ -31,10 +31,12 @@ class GrlTrackerSource(GObject.GObject):
         return "<GrlTrackerSource>"
 
     def __init__(
-            self, source, _hash, model, albums_model, artists_model, coremodel):
+            self, source, _hash, model, albums_model, artists_model, coremodel,
+            core_selection):
         super().__init__()
 
         self._coremodel = coremodel
+        self._core_selection = core_selection
         self._source = source
         self._model = model
         self._albums_model = albums_model
@@ -164,6 +166,8 @@ class GrlTrackerSource(GObject.GObject):
         song = CoreSong(media)
         self._model.append(song)
         self._hash[media.get_id()] = song
+
+        song.connect("notify::selected", self._core_selection.blah)
         # self._url_table[media.get_url()] = song
 
     def _initial_albums_fill(self, source):


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