views:

17

answers:

1

I have a global set of values, e.g. ["Foo", "Bar", "Baz", "Quux"]. Each row in my TreeView represents an entity that can only deal with a subset of these values. For example, the first row might deal with "Foo" and "Bar", and the second, "Bar" and "Quux". I want a ComboBox column to allow each row to select one of the values it can deal with.

However, from the code I have now, the entire column can only have one model for the ComboBox:

            crc = gtk.CellRendererCombo()
            crc.set_property('model', fooValuesModel)
            crc.set_property('text-column', 0)
            crc.set_property('editable', True)
            crc.set_property('has_entry', False)

            cl = gtk.TreeViewColumn(ctitle, crc, text=i)
            treeView.append_column(cl)

I have only one opportunity to set a model for the entire column. Is there any way to have different stores for each row, or to filter values somehow?

+1  A: 

What you are looking for is gtk.TreeModelFilter. It is a tree model containing filtered values of another underlying tree model. You can decide which rows should be visible by calling set_visible_func() on the filtered model.

ptomato
How to trigger the model change? Anything better than `cursor-changed` on the `TreeView`?
bobince
@bobince, unfortunately not as far as I can think of. You can call `refilter()` on the model whenever you want to change it but I think `cursor-changed` is the best option as to which signal handler to do that in.
ptomato