Commits

Ali Afshar  committed 8461f94

Added API for getting items before and after other items, with tests.

  • Participants
  • Parent commits b33ec34

Comments (0)

Files changed (2)

File pygtkhelpers/ui/objectlist.py

         if prev_iter is not None:
             self.model.swap(prev_iter, self._iter_for(item))
 
+    def item_after(self, item):
+        """The item after an item
+        """
+        next_iter = self._next_iter_for(item)
+        if next_iter is not None:
+            return self._object_at_iter(next_iter)
+
+    def item_before(self, item):
+        """The item before an item
+
+        :param item: The item to get the previous item relative to
+        """
+        prev_iter = self._prev_iter_for(item)
+        if prev_iter is not None:
+            return self._object_at_iter(prev_iter)
+
+
     def set_visible_func(self, visible_func):
         """Set the function to decide visibility of an item
 

File tests/test_objectlist.py

     searchcheck.ol.search_by(_search_missing_func)
     searchcheck.assert_selects('z', None)
 
+def test_item_after(items, user, user2, user3):
+    items.extend([user, user2, user3])
+    assert items.item_after(user) is user2
+    assert items.item_after(user2) is user3
+
+def test_item_before(items, user, user2, user3):
+    items.extend([user, user2, user3])
+    assert items.item_before(user2) is user
+    assert items.item_before(user3) is user2
+