[pygobject/pygobject-3-2] Add GtkComboBoxEntry compatibility



commit 216c88a80ed762b69a175f8771492ee53738d461
Author: Paolo Borelli <pborelli gnome org>
Date:   Wed Mar 21 21:09:24 2012 +0100

    Add GtkComboBoxEntry compatibility
    
    This widget has been removed in Gtk+ 3, add a small wrapper to the
    compat module to make at least basic pygtk programs that use it work.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672589

 gi/pygtkcompat.py         |   19 +++++++++++++++++++
 tests/test_pygtkcompat.py |   22 ++++++++++++++++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygtkcompat.py b/gi/pygtkcompat.py
index 26f803a..c855a68 100644
--- a/gi/pygtkcompat.py
+++ b/gi/pygtkcompat.py
@@ -260,6 +260,25 @@ def enable_gtk(version='2.0'):
         orig_combo_row_separator_func(self, callback, user_data)
     Gtk.ComboBox.set_row_separator_func = combo_row_separator_func
 
+    # ComboBoxEntry
+
+    class ComboBoxEntry(Gtk.ComboBox):
+        def __init__(self, **kwds):
+            Gtk.ComboBox.__init__(self, has_entry=True, **kwds)
+        def set_text_column (self, text_column):
+            self.set_entry_text_column(text_column)
+        def get_text_column (self):
+            return self.get_entry_text_column()
+    Gtk.ComboBoxEntry = ComboBoxEntry
+
+    def combo_box_entry_new():
+        return Gtk.ComboBoxEntry()
+    Gtk.combo_box_entry_new = combo_box_entry_new
+
+    def combo_box_entry_new_with_model(model):
+        return Gtk.ComboBoxEntry(model=model)
+    Gtk.combo_box_entry_new_with_model = combo_box_entry_new_with_model
+
     # Container
 
     def install_child_property(container, flag, pspec):
diff --git a/tests/test_pygtkcompat.py b/tests/test_pygtkcompat.py
index b9765c3..82948e2 100644
--- a/tests/test_pygtkcompat.py
+++ b/tests/test_pygtkcompat.py
@@ -70,6 +70,28 @@ class TestGTKCompat(unittest.TestCase):
         self.assertEquals(padding, 0)
         self.assertEquals(pack_type, gtk.PACK_END)
 
+    def testComboBoxEntry(self):
+        liststore = gtk.ListStore(int, str)
+        liststore.append((1, 'One'))
+        liststore.append((2, 'Two'))
+        liststore.append((3, 'Three'))
+        combo = gtk.ComboBoxEntry(model=liststore)
+        combo.set_text_column(1)
+        combo.set_active(0)
+        self.assertEquals(combo.get_text_column(), 1)
+        self.assertEquals(combo.get_child().get_text(), 'One')
+        combo = gtk.combo_box_entry_new()
+        combo.set_model(liststore)
+        combo.set_text_column(1)
+        combo.set_active(0)
+        self.assertEquals(combo.get_text_column(), 1)
+        self.assertEquals(combo.get_child().get_text(), 'One')
+        combo = gtk.combo_box_entry_new_with_model(liststore)
+        combo.set_text_column(1)
+        combo.set_active(0)
+        self.assertEquals(combo.get_text_column(), 1)
+        self.assertEquals(combo.get_child().get_text(), 'One')
+
     def testPixbuf(self):
         gtk.gdk.Pixbuf()
 



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