[gnome-music/wip/jfelder/3-34-searchview-flowbox-allocations] searchview: Fix crash in FlowBox allocations



commit dbda7b775a2d83f26e829cde6cd7652ff3d52f98
Author: Weifeng Lai <laiweifeng51 gmail com>
Date:   Mon Mar 9 11:52:27 2020 +0800

    searchview: Fix crash in FlowBox allocations
    
    If a search is performed and allocation occurs and hides some results,
    the 'visible' property of the widget in the FlowBox will be assigned
    False. However, when a new search is performed, this property is not
    updated to True, but the old value is kept. So, if the search results
    for artist or albums happen to overlap with previously hidden results,
    then last_child in _on_artist_flowbox_size_allocate() and
    last_visible_child in _on_album_flowbox_size_allocate() can be None,
    which will cause a crash.
    
    To fix this, every time a new search is triggered all FlowBox widgets
    set 'visible' to True.
    
    Fixes #372

 gnomemusic/views/searchview.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
---
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 1e7f823b..ea91711f 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -206,6 +206,11 @@ class SearchView(Gtk.Stack):
         nr_albums = self._album_model.get_n_items()
         self._view_all_albums.props.visible = (nr_albums > model.get_n_items())
 
+        def set_child_visible(child):
+            child.props.visible = True
+
+        self._album_flowbox.foreach(set_child_visible)
+
     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
@@ -216,6 +221,11 @@ class SearchView(Gtk.Stack):
         self._view_all_artists.props.visible = (
             nr_artists > model.get_n_items())
 
+        def set_child_visible(child):
+            child.props.visible = True
+
+        self._artist_flowbox.foreach(set_child_visible)
+
     def _on_model_items_changed(self, model, position, removed, added):
         items_found = model.get_n_items() > 0
         self._songs_header.props.visible = items_found


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