[gnome-music/wip/jfelder/searchview-new-style: 11/13] searchview: Hide a section if it has no search results
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/searchview-new-style: 11/13] searchview: Hide a section if it has no search results
- Date: Sun, 4 Aug 2019 09:53:25 +0000 (UTC)
commit 3ea59e456a0be7d187fb96c6f73ef0c5b1eb483f
Author: Jean Felder <jfelder src gnome org>
Date: Sun Aug 4 02:03:44 2019 +0200
searchview: Hide a section if it has no search results
data/ui/SearchView.ui | 6 +++---
gnomemusic/views/searchview.py | 27 +++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/SearchView.ui b/data/ui/SearchView.ui
index 35460787..ae443837 100644
--- a/data/ui/SearchView.ui
+++ b/data/ui/SearchView.ui
@@ -19,7 +19,7 @@
<property name="orientation">vertical</property>
<property name="visible">True</property>
<child>
- <object class="GtkBox">
+ <object class="GtkBox" id="_artist_header">
<property name="halign">fill</property>
<property name="hexpand">True</property>
<property name="homogeneous">True</property>
@@ -65,7 +65,7 @@
</object>
</child>
<child>
- <object class="GtkBox">
+ <object class="GtkBox" id="_album_header">
<property name="halign">fill</property>
<property name="hexpand">True</property>
<property name="homogeneous">True</property>
@@ -111,7 +111,7 @@
</object>
</child>
<child>
- <object class="GtkBox">
+ <object class="GtkBox" id="_songs_header">
<property name="halign">fill</property>
<property name="hexpand">True</property>
<property name="homogeneous">True</property>
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index e51c1d73..9ea44a70 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -49,9 +49,12 @@ class SearchView(Gtk.Stack):
selected_items_count = GObject.Property(type=int, default=0, minimum=0)
selection_mode = GObject.Property(type=bool, default=False)
+ _album_header = Gtk.Template.Child()
_album_flowbox = Gtk.Template.Child()
+ _artist_header = Gtk.Template.Child()
_artist_flowbox = Gtk.Template.Child()
_search_results = Gtk.Template.Child()
+ _songs_header = Gtk.Template.Child()
_songs_listbox = Gtk.Template.Child()
def __repr__(self):
@@ -82,13 +85,22 @@ class SearchView(Gtk.Stack):
self._artist_filter.set_filter_func(
self._core_filter, self._artist_model, 6)
+ self._model.connect_after(
+ "items-changed", self._on_model_items_changed)
self._songs_listbox.bind_model(self._model, self._create_song_widget)
+ self._on_model_items_changed(self._model, 0, 0, 0)
+ self._album_filter.connect_after(
+ "items-changed", self._on_album_model_items_changed)
self._album_flowbox.bind_model(
self._album_filter, self._create_album_widget)
+ self._on_album_model_items_changed(self._album_filter, 0, 0, 0)
+ self._artist_filter.connect_after(
+ "items-changed", self._on_artist_model_items_changed)
self._artist_flowbox.bind_model(
self._artist_filter, self._create_artist_widget)
+ self._on_artist_model_items_changed(self._artist_filter, 0, 0, 0)
self._player = self._application.props.player
@@ -165,6 +177,21 @@ class SearchView(Gtk.Stack):
return artist_tile
+ def _on_album_model_items_changed(self, model, position, removed, added):
+ items_found = model.get_n_items() > 0
+ self._album_header.props.visible = items_found
+ self._album_flowbox.props.visible = items_found
+
+ def _on_artist_model_items_changed(self, model, position, removed, added):
+ items_found = model.get_n_items() > 0
+ self._artist_header.props.visible = items_found
+ self._artist_flowbox.props.visible = items_found
+
+ def _on_model_items_changed(self, model, position, removed, added):
+ items_found = model.get_n_items() > 0
+ self._songs_header.props.visible = items_found
+ self._songs_listbox.props.visible = items_found
+
def _song_activated(self, widget, event):
mod_mask = Gtk.accelerator_get_default_mod_mask()
if ((event.get_state() & mod_mask) == Gdk.ModifierType.CONTROL_MASK
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]