title: How to filter a GTK tree view that uses a TreeStore (and not a ListStore)?
body: <p>I am using a <code>Gtk.TreeView</code> with a <code>Gtk.TreeStore</code> as a model for hierarchical data. As an example, let's take a music database organized into three levels: <em>artist</em>/<em>album</em>/<em>title</em>. I would like to filter this tree using a textual search field. For example, typing &quot;Five&quot; into the search field should give a result along the path &quot;Hank Marvin/Heartbeat/Take Five&quot;.</p>
  <p>My understanding is that I need to create a callback function and register it using <code>Gtk.TreeModelFilter.set_visible_func()</code>. The problem is that making the line for &quot;Take Five&quot; visible is not enough to make it appear, I also have to set all of its parents visible as well. However, that would require me to traverse the tree up to its root and actively make each node visible along that path, which does not fit into the callback pattern.</p>
  <p>One way I see to make this logic work with the callback pattern is to check the whole subtree in the callback function, but that way each leaf node would get checked three times. Even though the performance penalty would be acceptable with such a shallow tree, this hack gives me the goosebumps and I would like to refrain from using it:</p>
  <pre class="lang-py prettyprint-override"><code>def visible_callback(self, model, iter, _data=None):
      search_query = self.entry.get_text().lower()
      if search_query == &quot;&quot;:
          return True
  
      text = model.get_value(iter, 0).lower()
      if search_query in text:
          return True
  
      # Horrible hack
      for i in range(model.iter_n_children(iter)):
          if self.visible_callback(model, model.iter_nth_child(iter, i)):
              return True
  
      return False
  </code></pre>
  <p>What is the intended way to filter a tree view in GTK? (My example is written in Python, but a solution for any language binding of GTK would be fine.)</p>