Repository: lutris/lutris

Issue:
The Icon View can't be sorted and filtered at the same time
Making the store both filtered and sortable works for the TreeView but not the IconView which gets glitchy when using the search field. The error reported is
"Gtk-CRITICAL **: gtk_cell_area_render: assertion `GTK_IS_CELL_AREA_CONTEXT (context)' failed"

But in [this tutorial](http://python-gtk-3-tutorial.readthedocs.org/en/latest/iconview.html) it reads "Instead of using cell renderers, Gtk.IconView requires (blablabla)". So, is your use of a cell renderer in the IconView at fault? Well, not so sure. I've got rid of that text label using a cell renderer and it didn't change a thing.

Maybe it's just that sortable _and_ filtered IconViews are not meant to exist...

A workaround is to only apply the TreeModelSort model to the TreeView. But we'll certainly want to sort the IconView too in the future (e.g. sort by 'last played' would be relevant for the icon view).

[[strycore replied](https://github.com/lutris/lutris/pull/2#issuecomment-30055943): I still haven't had the time to have a look at this but the CellRenderer is, if I remember correctly, the way to fix the extra large padding between icons. This trick comes from [Rhythmbox's Cover Art browser plugin](https://github.com/fossfreedom/coverart-browser), it also uses an icon view so there may be some more code snippets to pick from this project.] 



Discussion:
For the record, I have a project which could be useful for these kind of tasks : 
https://github.com/strycore/pygobject-demos 
You can try coding a minimal solution: one that does only filtering and sorting, and nothing else.
That's how I coded some features in the UI, it's easier to take the experimentation outside the project and integrate it after it as been proved to work.

It can be handy, thanks. 
I'll check the Rhythmbox plugin, it seems they found a way.

I've had a better look at the coverart-browser plugin. If I'm correct, their solution is what I was thinking about doing : they made a sort function from scratch, thus didn't wrap the ListStore in a TreeModelSort.
You can see this in their [AlbumsModel](https://github.com/fossfreedom/coverart-browser/blob/master/coverart_album.py#L647). It looks too complicated for me, I'm afraid...


Resolving patch:
diff --git a/lutris/gui/widgets.py b/lutris/gui/widgets.py
--- a/lutris/gui/widgets.py
+++ b/lutris/gui/widgets.py
@@ -190,7 +190,7 @@ def update_filter(self, widget, data=None):
 
     def filter_view(self):
         self.game_store.filter_text = self.filter_text
-        self.get_model().refilter()
+        self.game_store.modelfilter.refilter()
 
     def update_image(self, game_slug, is_installed=False):
         row = self.get_row_by_slug(game_slug)
@@ -224,8 +224,10 @@ class GameTreeView(Gtk.TreeView, GameView):
     def __init__(self, games, filter_text=""):
         self.filter_text = filter_text
         self.game_store = GameStore(games, filter_text=self.filter_text)
-        super(GameTreeView, self).__init__(self.game_store.modelfilter)
+        self.model = self.game_store.modelfilter.sort_new_with_model()
+        super(GameTreeView, self).__init__(self.model)
         self.set_rules_hint(True)
+        self.model.set_sort_column_id(1, Gtk.SortType.ASCENDING)
 
         # Icon column
         image_cell = Gtk.CellRendererPixbuf()
@@ -258,16 +260,6 @@ def setup_text_column(self, header, column_id):
         column.set_reorderable(True)
         return column
 
-    def remove_row(self, model_iter):
-        """Remove a game from the treeview."""
-        model = self.get_model()
-        model.remove(model_iter)
-
-    def sort_rows(self):
-        """Sort the game list."""
-        model = self.get_model()
-        Gtk.TreeModel.sort_new_with_model(model)
-
     def get_selected_game(self, widget, line=None, column=None, launch=False):
         selection = self.get_selection()
         if not selection:
@@ -289,7 +281,8 @@ def __init__(self, games, filter_text=""):
         self.filter_text = filter_text
         self.game_store = GameStore(games, icon_size=ICON_SIZE,
                                     filter_text=self.filter_text)
-        super(GameIconView, self).__init__(model=self.game_store.modelfilter)
+        self.model = self.game_store.modelfilter
+        super(GameIconView, self).__init__(model=self.model)
         self.set_columns(1)
         self.set_column_spacing(1)
         self.set_pixbuf_column(COL_ICON)


Test patch: