[gnome-music/wip/mschraal/albumsview-drop-baseview: 3/4] albumsview: Use Gtk.Builder



commit fd48ce6fd78b3c3a3b1dd103a38af2605e6f1a10
Author: Marinus Schraal <mschraal gnome org>
Date:   Mon Jul 29 16:25:55 2019 +0200

    albumsview: Use Gtk.Builder

 data/org.gnome.Music.gresource.xml |  1 +
 data/ui/AlbumsView.ui              | 29 ++++++++++++++++++++
 gnomemusic/views/albumsview.py     | 55 +++++++++++---------------------------
 3 files changed, 46 insertions(+), 39 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 7b64dd1f..75d3e02f 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -7,6 +7,7 @@
     <file preprocess="xml-stripblanks">ui/AboutDialog.ui</file>
     <file preprocess="xml-stripblanks">ui/AlbumCover.ui</file>
     <file preprocess="xml-stripblanks">ui/AlbumWidget.ui</file>
+    <file preprocess="xml-stripblanks">ui/AlbumsView.ui</file>
     <file preprocess="xml-stripblanks">ui/AppMenu.ui</file>
     <file preprocess="xml-stripblanks">ui/ArtistAlbumWidget.ui</file>
     <file preprocess="xml-stripblanks">ui/ArtistTile.ui</file>
diff --git a/data/ui/AlbumsView.ui b/data/ui/AlbumsView.ui
new file mode 100644
index 00000000..116231fe
--- /dev/null
+++ b/data/ui/AlbumsView.ui
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.18"/>
+  <template class="AlbumsView" parent="GtkStack">
+    <child>
+      <object class="GtkScrolledWindow" id="_all_albums">
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkFlowBox" id="_flowbox">
+            <property name="column_spacing">6</property>
+            <property name="halign">fill</property>
+            <property name="hexpand">True</property>
+            <property name="homogeneous">True</property>
+            <property name="margin">18</property>
+            <property name="max-children-per-line">20</property>
+            <property name="min-children-per-line">1</property>
+            <property name="row_spacing">12</property>
+            <property name="selection-mode">none</property>
+            <property name="valign">start</property>
+            <property name="visible">True</property>
+            <style>
+              <class name="content-view"/>
+            </style>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index bcb4114b..d583399a 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -31,16 +31,22 @@ from gnomemusic.widgets.albumcover import AlbumCover
 from gnomemusic.widgets.albumwidget import AlbumWidget
 
 
+@Gtk.Template(resource_path="/org/gnome/Music/ui/AlbumsView.ui")
 class AlbumsView(Gtk.Stack):
     """Gridlike view of all albums
 
     Album activation switches to AlbumWidget.
     """
 
+    __gtype_name__ = "AlbumsView"
+
     search_mode_active = GObject.Property(type=bool, default=False)
     selected_items_count = GObject.Property(type=int, default=0, minimum=0)
     selection_mode = GObject.Property(type=bool, default=False)
 
+    _all_albums = Gtk.Template.Child()
+    _flowbox = Gtk.Template.Child()
+
     def __repr__(self):
         return '<AlbumsView>'
 
@@ -57,29 +63,19 @@ class AlbumsView(Gtk.Stack):
         self.title = _("Albums")
 
         self._window = application.props.window
-        player = application.props.player
-
-        self._grid = Gtk.Grid(orientation=Gtk.Orientation.HORIZONTAL)
-        self._box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
-
-        # Setup the main view
-        self._setup_view()
-
-        self._grid.add(self._box)
-
         self._headerbar = self._window._headerbar
 
-        self.add(self._grid)
-        self.show_all()
+        model = self._window._app.props.coremodel.props.albums_sort
+        self._flowbox.bind_model(model, self._create_widget)
+        self._flowbox.connect("child-activated", self._on_child_activated)
 
-        self._selection_mode_id = self.connect(
-            "notify::selection-mode", self._on_selection_mode_changed)
+        self.connect("notify::selection-mode", self._on_selection_mode_changed)
 
         self.bind_property(
             'selection-mode', self._window, 'selection-mode',
             GObject.BindingFlags.BIDIRECTIONAL)
 
-        self._album_widget = AlbumWidget(player, self)
+        self._album_widget = AlbumWidget(application.props.player, self)
         self._album_widget.bind_property(
             "selection-mode", self, "selection-mode",
             GObject.BindingFlags.BIDIRECTIONAL)
@@ -89,6 +85,8 @@ class AlbumsView(Gtk.Stack):
         self.connect(
             "notify::search-mode-active", self._on_search_mode_changed)
 
+        self.show_all()
+
     @log
     def _on_selection_mode_changed(self, widget, data=None):
         if not self.props.selection_mode:
@@ -101,28 +99,6 @@ class AlbumsView(Gtk.Stack):
                 and self.get_visible_child() == self._album_widget):
             self._set_album_headerbar(self._album_widget.props.album)
 
-    @log
-    def _setup_view(self):
-        self._view = Gtk.FlowBox(
-            homogeneous=True, hexpand=True, halign=Gtk.Align.FILL,
-            valign=Gtk.Align.START, selection_mode=Gtk.SelectionMode.NONE,
-            margin=18, row_spacing=12, column_spacing=6,
-            min_children_per_line=1, max_children_per_line=20, visible=True)
-
-        self._view.get_style_context().add_class('content-view')
-        self._view.connect('child-activated', self._on_child_activated)
-
-        scrolledwin = Gtk.ScrolledWindow()
-        scrolledwin.add(self._view)
-        scrolledwin.show()
-
-        self._box.add(scrolledwin)
-
-        self._model = self._window._app.props.coremodel.props.albums_sort
-        self._view.bind_model(self._model, self._create_widget)
-
-        self._view.show()
-
     @log
     def _create_widget(self, corealbum):
         album_widget = AlbumCover(corealbum)
@@ -144,7 +120,8 @@ class AlbumsView(Gtk.Stack):
     @log
     def _back_button_clicked(self, widget, data=None):
         self._headerbar.state = HeaderBar.State.MAIN
-        self.set_visible_child(self._grid)
+        # self.set_visible_child(self._grid)
+        self.props.visible_child = self._all_albums
 
     @log
     def _on_child_activated(self, widget, child, user_data=None):
@@ -170,7 +147,7 @@ class AlbumsView(Gtk.Stack):
         signal for performance purposes.
         """
         with self._window._app.props.coreselection.freeze_notify():
-            for child in self._view.get_children():
+            for child in self._flowbox.get_children():
                 child.props.selected = selected
                 child.props.corealbum.props.selected = selected
 


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