[pygobject] [API add] Override g_menu_item_set_attribute



commit dd31b67e821f92b5f1c2ee0382cac5edd477cd11
Author: Paolo Borelli <pborelli gnome org>
Date:   Wed Aug 22 10:45:39 2012 +0200

    [API add] Override g_menu_item_set_attribute
    
    This C utility API take a vararg, add a corresponding override that
    takes a list of tuples
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682436

 gi/overrides/Gio.py     |   10 ++++++++++
 tests/test_overrides.py |   11 +++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gio.py b/gi/overrides/Gio.py
index cc9cca9..7f6e5c7 100644
--- a/gi/overrides/Gio.py
+++ b/gi/overrides/Gio.py
@@ -50,6 +50,16 @@ FileEnumerator = override(FileEnumerator)
 __all__.append('FileEnumerator')
 
 
+class MenuItem(Gio.MenuItem):
+    def set_attribute(self, attributes):
+        for (name, format_string, value) in attributes:
+            self.set_attribute_value(name, GLib.Variant(format_string, value))
+
+
+MenuItem = override(MenuItem)
+__all__.append('MenuItem')
+
+
 class Settings(Gio.Settings):
     '''Provide dictionary-like access to GLib.Settings.'''
 
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index c9b8682..8665cec 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -2095,6 +2095,17 @@ class TestGio(unittest.TestCase):
 
         self.assertEqual(iter_info, next_info)
 
+    def test_menu_item(self):
+        menu = Gio.Menu()
+        item = Gio.MenuItem()
+        item.set_attribute([("label", "s", "Test"),
+                            ("action", "s", "app.test")])
+        menu.append_item(item)
+        value = menu.get_item_attribute_value(0, "label", GLib.VariantType.new("s"))
+        self.assertEqual("Test", value.unpack())
+        value = menu.get_item_attribute_value(0, "action", GLib.VariantType.new("s"))
+        self.assertEqual("app.test", value.unpack())
+
     def test_gsettings_native(self):
         self.assertTrue('test-array' in self.settings.list_keys())
 



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