[gnome-music/wip/mschraal/searchview-rework: 2/15] searchview: Use Gtk.Builder
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/searchview-rework: 2/15] searchview: Use Gtk.Builder
- Date: Sat, 3 Aug 2019 10:28:39 +0000 (UTC)
commit 2e78e9fa57e565624c12a9c5fd91790c686338a7
Author: Marinus Schraal <mschraal gnome org>
Date: Mon Jul 29 22:22:25 2019 +0200
searchview: Use Gtk.Builder
data/org.gnome.Music.gresource.xml | 1 +
data/ui/SearchView.ui | 40 ++++++++++++++++++++++++++
gnomemusic/views/searchview.py | 58 +++++++++++---------------------------
3 files changed, 58 insertions(+), 41 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..7af27eea
--- /dev/null
+++ b/data/ui/SearchView.ui
@@ -0,0 +1,40 @@
+<?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="visible">True</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkFlowBox" id="_album_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>
+ <child>
+ <object class="GtkListBox" id="_artist_listbox"/>
+ </child>
+ <child>
+ <object class="GtkListBox" id="_songs_listbox"/>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index eabce4cc..9d3e72fe 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -36,6 +36,7 @@ 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):
"""Search view
"""
@@ -46,6 +47,11 @@ class SearchView(Gtk.Stack):
selected_items_count = GObject.Property(type=int, default=0, minimum=0)
selection_mode = GObject.Property(type=bool, default=False)
+ _search_results = Gtk.Template.Child()
+ _album_flowbox = Gtk.Template.Child()
+ _artist_listbox = Gtk.Template.Child()
+ _songs_listbox = Gtk.Template.Child()
+
def __repr__(self):
return '<SearchView>'
@@ -67,14 +73,16 @@ class SearchView(Gtk.Stack):
self._artist_model = self._coremodel.props.artists_search
self._player = self._application.props.player
- self._grid = Gtk.Grid(orientation=Gtk.Orientation.HORIZONTAL)
- self._box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ self._songs_listbox.bind_model(self._model, self._create_song_widget)
+
+ self._album_flowbox.bind_model(
+ self._album_model, self._create_album_widget)
+ self._album_flowbox.connect(
+ "child-activated", self._on_album_activated)
- # Setup the main view
- self._setup_view()
+ self._artist_listbox.bind_model(
+ self._artist_model, self._create_artist_widget)
- self._grid.add(self._box)
- self.add(self._grid)
self.show_all()
self._window = application.props.window
@@ -101,38 +109,6 @@ class SearchView(Gtk.Stack):
# 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._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)
@@ -276,11 +252,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.props.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.props.visible_child = self._search_results
self.props.search_mode_active = True
self._headerbar.props.state = HeaderBar.State.MAIN
@@ -317,5 +293,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.props.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]