[gnome-music/wip/mschraal/gtk4-v3] artistsview: Cleanup



commit 73d017bd298fcf36e691065854e0486115d188cf
Author: Marinus Schraal <mschraal gnome org>
Date:   Mon Feb 14 13:41:47 2022 +0100

    artistsview: Cleanup
    
    Remove stack related code.

 data/ui/ArtistsView.ui          |   8 +---
 gnomemusic/views/artistsview.py | 103 +++++++++-------------------------------
 2 files changed, 24 insertions(+), 87 deletions(-)
---
diff --git a/data/ui/ArtistsView.ui b/data/ui/ArtistsView.ui
index d612ca2a5..5d01c08ee 100644
--- a/data/ui/ArtistsView.ui
+++ b/data/ui/ArtistsView.ui
@@ -18,15 +18,9 @@
       </object>
     </child>
     <child>
-      <object class="GtkScrolledWindow" id="_artist_container">
+      <object class="GtkScrolledWindow" id="_artist_view">
         <property name="hexpand">True</property>
         <property name="vexpand">True</property>
-        <child>
-          <object class="GtkStack" id="_artist_view">
-            <property name="transition-type">crossfade</property>
-            <property name="vhomogeneous">False</property>
-          </object>
-        </child>
       </object>
     </child>
   </template>
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index 18e9a32a8..b4c928099 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -22,11 +22,16 @@
 # 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 __future__ import annotations
+import typing
+
 from gettext import gettext as _
 from gi.repository import GObject, Gtk
 
 from gnomemusic.widgets.artistalbumswidget import ArtistAlbumsWidget
 from gnomemusic.widgets.artisttile import ArtistTile
+if typing.TYPE_CHECKING:
+    from gnomemusic.application import Application
 
 
 @Gtk.Template(resource_path="/org/gnome/Music/ui/ArtistsView.ui")
@@ -45,11 +50,10 @@ class ArtistsView(Gtk.Paned):
     title = GObject.Property(
         type=str, default=_("Artists"), flags=GObject.ParamFlags.READABLE)
 
-    _artist_container = Gtk.Template.Child()
     _artist_view = Gtk.Template.Child()
     _sidebar = Gtk.Template.Child()
 
-    def __init__(self, application):
+    def __init__(self, application: Application) -> None:
         """Initialize
 
         :param GtkApplication application: The application object
@@ -58,9 +62,6 @@ class ArtistsView(Gtk.Paned):
 
         self.props.name = "artists"
 
-        self._application = application
-        self._loaded_artists = []
-
         # This indicates if the current list has been empty and has
         # had no user interaction since.
         self._untouched_list = True
@@ -76,16 +77,23 @@ class ArtistsView(Gtk.Paned):
         artist_item_factory.connect("bind", self._on_list_view_bind)
         self._sidebar.props.factory = artist_item_factory
 
+        self._artist_album = ArtistAlbumsWidget(application)
+        self._artist_view.props.child = self._artist_album
+
+        self.bind_property(
+            "selection-mode", self._artist_album, "selection-mode",
+            GObject.BindingFlags.SYNC_CREATE
+            | GObject.BindingFlags.BIDIRECTIONAL)
+        self._window.bind_property(
+            "selection-mode", self, "selection-mode",
+            GObject.BindingFlags.BIDIRECTIONAL)
+
         self._selection_model.connect_after(
             "items-changed", self._on_model_items_changed)
         self._on_model_items_changed(self._selection_model, 0, 0, 0)
 
         self._selection_mode = False
 
-        self._window.bind_property(
-            "selection-mode", self, "selection-mode",
-            GObject.BindingFlags.BIDIRECTIONAL)
-
     def _on_list_view_setup(
             self, factory: Gtk.SignalListItemFactory,
             list_item: Gtk.ListItem) -> None:
@@ -96,7 +104,6 @@ class ArtistsView(Gtk.Paned):
             list_item: Gtk.ListItem) -> None:
         coreartist = list_item.props.item
         artist_tile = list_item.props.child
-
         artist_tile.props.coreartist = coreartist
 
     def _on_model_items_changed(
@@ -104,81 +111,17 @@ class ArtistsView(Gtk.Paned):
             added: int) -> None:
         if model.get_n_items() == 0:
             self._untouched_list = True
-            return
+            # FIXME: Add an empty state.
         elif self._untouched_list is True:
-            first_artist = model.get_item(0)
-            if first_artist is None:
-                return
-
-            model.props.selected = 0
-            self._on_artist_activated(self._sidebar, 0, True)
-            return
-
-        if removed == 0:
-            return
-
-        removed_artist = None
-        artists = [coreartist.props.artist for coreartist in model]
-        for artist in self._loaded_artists:
-            if artist not in artists:
-                removed_artist = artist
-                break
-
-        if removed_artist is None:
-            return
-
-        self._loaded_artists.remove(removed_artist)
-        if self._artist_view.get_visible_child_name() == removed_artist:
-            new_position = min(position, model.get_n_items() - 1)
-            if new_position >= 0:
-                model.props.selected = new_position
-                self._on_artist_activated(self._sidebar, new_position, True)
-
-        removed_artist_page = self._artist_view.get_child_by_name(
-            removed_artist)
-        self._artist_view.remove(removed_artist_page)
+            self._untouched_list = False
+            self._sidebar.emit("activate", 0)
 
     @Gtk.Template.Callback()
     def _on_artist_activated(
-            self, sidebar: Gtk.ListView, position: int,
-            untouched: bool = False) -> None:
+            self, sidebar: Gtk.ListView, position: int) -> None:
         """Initializes new artist album widgets"""
-        # On application start the first row of ArtistView is activated
-        # to show an intial artist. When this happens while any of the
-        # views are in selection mode, this artist will be incorrectly
-        # selected.
-        # When selecting items check that the current visible view is
-        # ArtistsView, to circumvent this issue.
-        if (self.props.selection_mode
-                and self._window.props.active_view is self):
-            return
-
-        if untouched is False:
-            self._untouched_list = False
-
-        coreartist = sidebar.get_model().get_item(position)
-
-        # Prepare a new artist_albums_widget here
-        if coreartist.props.artist in self._loaded_artists:
-            scroll_vadjustment = self._artist_container.props.vadjustment
-            scroll_vadjustment.props.value = 0.
-            self._artist_view.set_visible_child_name(coreartist.props.artist)
-            return
-
-        artist_albums = ArtistAlbumsWidget(self._application)
-        artist_albums.props.coreartist = coreartist
-
-        self.bind_property(
-            "selection-mode", artist_albums, "selection-mode",
-            GObject.BindingFlags.SYNC_CREATE
-            | GObject.BindingFlags.BIDIRECTIONAL)
-
-        self._artist_view.add_named(artist_albums, coreartist.props.artist)
-        scroll_vadjustment = self._artist_container.props.vadjustment
-        scroll_vadjustment.props.value = 0.
-        self._artist_view.set_visible_child(artist_albums)
-
-        self._loaded_artists.append(coreartist.props.artist)
+        coreartist = self._selection_model.get_item(position)
+        self._artist_album.props.coreartist = coreartist
 
     @GObject.Property(type=bool, default=False)
     def selection_mode(self):


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