[gnome-music/wip/jfelder/searchview-new-style: 3/14] searchview: Use Gtk.Builder



commit 4e61d47d37a0dfd72faba32100f83b17816fd8aa
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Aug 1 00:11:07 2019 +0200

    searchview: Use Gtk.Builder

 data/org.gnome.Music.gresource.xml |  1 +
 data/ui/SearchView.ui              | 48 ++++++++++++++++++++++++++++++++
 gnomemusic/views/searchview.py     | 57 ++++++++++----------------------------
 3 files changed, 64 insertions(+), 42 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 75d3e02f..8326914c 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -23,6 +23,7 @@
     <file preprocess="xml-stripblanks">ui/PlaylistDialogRow.ui</file>
     <file preprocess="xml-stripblanks">ui/PlaylistTile.ui</file>
     <file preprocess="xml-stripblanks">ui/SearchBar.ui</file>
+    <file preprocess="xml-stripblanks">ui/SearchView.ui</file>
     <file preprocess="xml-stripblanks">ui/SelectionBarMenuButton.ui</file>
     <file preprocess="xml-stripblanks">ui/SelectionToolbar.ui</file>
     <file preprocess="xml-stripblanks">ui/SongWidget.ui</file>
diff --git a/data/ui/SearchView.ui b/data/ui/SearchView.ui
new file mode 100644
index 00000000..f20bbead
--- /dev/null
+++ b/data/ui/SearchView.ui
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.18"/>
+  <template class="SearchView" parent="GtkStack">
+    <child>
+      <object class="GtkScrolledWindow" id="_search_results">
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkBox" id="container">
+            <property name="orientation">vertical</property>
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkFlowBox" id="_album_flowbox">
+                <property name="halign">fill</property>
+                <property name="hexpand">True</property>
+                <property name="valign">start</property>
+                <property name="homogeneous">True</property>
+                <property name="min_children_per_line">1</property>
+                <property name="max_children_per_line">20</property>
+                <property name="margin">18</property>
+                <property name="row_spacing">12</property>
+                <property name="column_spacing">6</property>
+                <property name="selection_mode">none</property>
+                <property name="visible">True</property>
+                <signal name="child-activated" handler="_on_album_activated" swapped="no"/>
+                <style>
+                  <class name="content-view"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkFlowBox" id="_artist_listbox">
+                <property name="visible">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkListBox" id="_songs_listbox">
+                <property name="visible">True</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 1900b5dd..a0f0437a 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -28,7 +28,6 @@ from gnomemusic import log
 from gnomemusic.player import PlayerPlaylist
 from gnomemusic.utils import View
 from gnomemusic.search import Search
-from gnomemusic.views.baseview import BaseView
 from gnomemusic.widgets.albumcover import AlbumCover
 from gnomemusic.widgets.albumwidget import AlbumWidget
 from gnomemusic.widgets.headerbar import HeaderBar
@@ -37,16 +36,24 @@ from gnomemusic.widgets.artisttile import ArtistTile
 from gnomemusic.widgets.songwidget import SongWidget
 
 
+@Gtk.Template(resource_path="/org/gnome/Music/ui/SearchView.ui")
 class SearchView(Gtk.Stack):
     """Gridlike view of search results.
 
     Three sections: artists, albums, songs.
     """
 
+    __gtype_name__ = "SearchView"
+
     search_state = GObject.Property(type=int, default=Search.State.NONE)
     selected_items_count = GObject.Property(type=int, default=0, minimum=0)
     selection_mode = GObject.Property(type=bool, default=False)
 
+    _album_flowbox = Gtk.Template.Child()
+    _artist_listbox = Gtk.Template.Child()
+    _search_results = Gtk.Template.Child()
+    _songs_listbox = Gtk.Template.Child()
+
     def __repr__(self):
         return '<SearchView>'
 
@@ -70,19 +77,9 @@ class SearchView(Gtk.Stack):
 
         self._player = self._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._window = application.props.window
         self._headerbar = self._window._headerbar
 
-        self.add(self._grid)
-
         self.connect("notify::selection-mode", self._on_selection_mode_changed)
 
         self.bind_property(
@@ -96,6 +93,7 @@ class SearchView(Gtk.Stack):
             "selection-mode", self, "selection-mode",
             GObject.BindingFlags.BIDIRECTIONAL)
 
+        self.show_all()
         self.add(self._album_widget)
 
         self._artist_albums_widget = None
@@ -103,37 +101,11 @@ class SearchView(Gtk.Stack):
         self._search_mode_active = False
         # self.connect("notify::search-state", self._on_search_state_changed)
 
-    @log
-    def _setup_view(self):
-        view_container = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
-        self._box.pack_start(view_container, True, True, 0)
-
-        self._songs_listbox = Gtk.ListBox()
+        self._artist_listbox.bind_model(
+            self._artist_model, self._create_artist_widget)
         self._songs_listbox.bind_model(self._model, self._create_song_widget)
-
-        self._album_flowbox = 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._album_flowbox.get_style_context().add_class('content-view')
         self._album_flowbox.bind_model(
             self._album_model, self._create_album_widget)
-        self._album_flowbox.connect(
-            "child-activated", self._on_album_activated)
-
-        self._artist_listbox = Gtk.ListBox()
-        self._artist_listbox.bind_model(
-            self._artist_model, self._create_artist_widget)
-
-        self._all_results_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
-        self._all_results_box.pack_start(self._album_flowbox, True, True, 0)
-        self._all_results_box.pack_start(self._artist_listbox, True, True, 0)
-        self._all_results_box.pack_start(self._songs_listbox, True, True, 0)
-
-        view_container.add(self._all_results_box)
-
-        self._box.show_all()
 
     def _create_song_widget(self, coresong):
         song_widget = SongWidget(coresong)
@@ -200,6 +172,7 @@ class SearchView(Gtk.Stack):
 
         return True
 
+    @Gtk.Template.Callback()
     def _on_album_activated(self, widget, child, user_data=None):
         corealbum = child.props.corealbum
         if self.props.selection_mode:
@@ -278,11 +251,11 @@ class SearchView(Gtk.Stack):
         if self.get_visible_child() == self._artist_albums_widget:
             self._artist_albums_widget.destroy()
             self._artist_albums_widget = None
-        elif self.get_visible_child() == self._grid:
+        elif self.get_visible_child() == self._search_results:
             self._window.views[View.ALBUM].set_visible_child(
                 self._window.views[View.ALBUM]._grid)
 
-        self.set_visible_child(self._grid)
+        self.set_visible_child(self._search_results)
         self.props.search_mode_active = True
         self._headerbar.props.state = HeaderBar.State.MAIN
 
@@ -319,5 +292,5 @@ class SearchView(Gtk.Stack):
         # the child views.
         self._search_mode_active = value
         if (not self._search_mode_active
-                and self.get_visible_child() == self._grid):
+                and self.get_visible_child() == self._search_results):
             self.props.search_state = Search.State.NONE


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