[POS-commit] r6384 - in kiwi/trunk: . kiwi/ui

Johan Dahlin jdahlin at async.com.br
Wed Apr 18 10:33:14 BRT 2007


Author: jdahlin
Date: Wed Apr 18 10:33:14 2007
New Revision: 6384

Modified:
   kiwi/trunk/ChangeLog
   kiwi/trunk/kiwi/ui/objectlist.py

Log:
    * kiwi/ui/objectlist.py (ObjectList.sort_by_attribute): 
    Add. Fixes #3311, based on patch by Ali Afshar.



Modified: kiwi/trunk/ChangeLog
==============================================================================
--- kiwi/trunk/ChangeLog	(original)
+++ kiwi/trunk/ChangeLog	Wed Apr 18 10:33:14 2007
@@ -1,3 +1,8 @@
+2007-04-18  Johan Dahlin  <jdahlin at async.com.br>
+
+	* kiwi/ui/objectlist.py (ObjectList.sort_by_attribute): 
+	Add. Fixes #3311, based on patch by Ali Afshar.
+
 2007-04-16  Ali Afshar <aafshar at gmail.com>
 
 	reviewed by: Johan Dahlin  <jdahlin at async.com.br>

Modified: kiwi/trunk/kiwi/ui/objectlist.py
==============================================================================
--- kiwi/trunk/kiwi/ui/objectlist.py	(original)
+++ kiwi/trunk/kiwi/ui/objectlist.py	Wed Apr 18 10:33:14 2007
@@ -708,6 +708,23 @@
         cmp(x, y) -> -1, 0, 1"""
         raise NotImplementedError
 
+    def sort_by_attribute(self, attribute, order=gtk.SORT_ASCENDING):
+        """
+        Sort by an attribute in the object model.
+
+        @param attribute: attribute to sort on
+        @type attribute: string
+        @param order: one of gtk.SORT_ASCENDING, gtk.SORT_DESCENDING
+        @type order: gtk.SortType
+        """
+        def _sort_func(model, iter1, iter2):
+            return cmp(
+                getattr(model[iter1][0], attribute, None),
+                getattr(model[iter2][0], attribute, None))
+        unused_sort_col_id = len(self._columns)
+        self._model.set_sort_func(unused_sort_col_id, _sort_func)
+        self._model.set_sort_column_id(unused_sort_col_id, order)
+
     # Properties
 
     def prop_set_selection_mode(self, mode):


More information about the POS-commit mailing list