[pygobject] Add override for TreeModel implementing __len__()



commit daca09dc2c2306d4fa82a68bbdd147d4b170a1e7
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Tue Jun 29 16:37:36 2010 +0100

    Add override for TreeModel implementing __len__()
    
    Closes: bgo#622882

 gi/overrides/Gtk.py     |   11 +++++++++--
 tests/test_overrides.py |    5 +++++
 2 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 0c3dcc5..0c2d1d9 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -340,7 +340,14 @@ class TextBuffer(Gtk.TextBuffer):
 TextBuffer = override(TextBuffer)
 __all__.append('TextBuffer')
 
-class ListStore(Gtk.ListStore):
+class TreeModel(Gtk.TreeModel):
+    def __len__(self):
+        return self.iter_n_children(None)
+
+TreeModel = override(TreeModel)
+__all__.append('TreeModel')
+
+class ListStore(Gtk.ListStore, TreeModel):
     def __init__(self, *column_types):
         Gtk.ListStore.__init__(self)
         self.set_column_types(column_types)
@@ -362,7 +369,7 @@ class ListStore(Gtk.ListStore):
 ListStore = override(ListStore)
 __all__.append('ListStore')
 
-class TreeStore(Gtk.TreeStore):
+class TreeStore(Gtk.TreeStore, TreeModel):
 
     def __init__(self, *column_types):
         Gtk.TreeStore.__init__(self)
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 0509cfa..7255a5f 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -159,6 +159,7 @@ class TestGtk(unittest.TestCase):
     def test_tree_api(self):
         self.assertEquals(Gtk.TreeStore, overrides.Gtk.TreeStore)
         self.assertEquals(Gtk.ListStore, overrides.Gtk.ListStore)
+        self.assertEquals(Gtk.TreeModel, overrides.Gtk.TreeModel)
         self.assertEquals(Gtk.TreeViewColumn, overrides.Gtk.TreeViewColumn)
 
         class TestClass(GObject.GObject):
@@ -183,6 +184,8 @@ class TestGtk(unittest.TestCase):
             testobj = TestClass(self, i, label)
             parent = tree_store.append(parent, (i, label, testobj))
 
+        self.assertEquals(len(tree_store), 100)
+
         # walk the tree to see if the values were stored correctly
         iter = Gtk.TreeIter()
         parent = None
@@ -205,6 +208,8 @@ class TestGtk(unittest.TestCase):
             testobj = TestClass(self, i, label)
             parent = list_store.append((i, label, testobj))
 
+        self.assertEquals(len(list_store), 100)
+
         # walk the list to see if the values were stored correctly
         iter = Gtk.TreeIter()
         i = 0



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]