Use list.sort's keyword parameters
[joel/kofoto.git] / src / packages / kofoto / gkofoto / mysortedmodel.py
1 import gtk
2
3 class MySortedModel(gtk.TreeModelSort):
4
5     def __init__(self, model):
6         gtk.TreeModelSort.__init__(self, model)
7         self._model = model
8
9     def __getitem__(self, path):
10         child_path = self.convert_path_to_child_path(path)
11         if child_path:
12             return self._model[child_path]
13         else:
14             raise IndexError
15
16     def __delitem__(self, path):
17         child_path = self.convert_path_to_child_path(path)
18         if child_path:
19             del self._model[child_path]
20         else:
21             raise IndexError
22
23     def set_value(self, iterator, column, value):
24         childIter = self._model.get_iter_first()
25         self.convert_iter_to_child_iter(childIter, iterator)
26         self._model.set_value(childIter, column, value)
27
28     # Workaround until http://bugzilla.gnome.org/show_bug.cgi?id=121633 is solved.
29     def get_iter_first(self):
30         if len(self) > 0:
31             return gtk.TreeModelSort.get_iter_first(self)
32         else:
33             return None
34
35     # Workaround until http://bugzilla.gnome.org/show_bug.cgi?id=121633 is solved.
36     def __iter__(self):
37         if len(self._model) > 0:
38             return gtk.TreeModelSort.__iter__(self)
39         else:
40             return self._model.__iter__()