[pygobject/pygobject-2-28] [gi-overrides] add an override for Gdk.RGBA



commit 1b4ac8bef90ed1d3d51d45dafa61bfd70c6f9eb7
Author: John (J5) Palmieri <johnp redhat com>
Date:   Thu Mar 3 16:47:51 2011 -0500

    [gi-overrides] add an override for Gdk.RGBA

 gi/overrides/Gdk.py     |   18 ++++++++++++++++++
 tests/test_overrides.py |   10 ++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py
index 16a0548..e346f55 100644
--- a/gi/overrides/Gdk.py
+++ b/gi/overrides/Gdk.py
@@ -45,6 +45,24 @@ class Color(Gdk.Color):
 Color = override(Color)
 __all__.append('Color')
 
+if Gdk._version == '3.0':
+    class RGBA(Gdk.RGBA):
+        def __init__(self, red=1.0, green=1.0, blue=1.0, alpha=1.0):
+            Gdk.RGBA.__init__(self)
+            self.red = red
+            self.green = green
+            self.blue = blue
+            self.alpha = alpha
+
+        def __new__(cls, *args, **kwargs):
+            return Gdk.RGBA.__new__(cls)
+
+        def __repr__(self):
+            return '<Gdk.Color(red=%f, green=%f, blue=%f, alpha=%f)>' % (self.red, self.green, self.blue, self.alpha)
+
+    RGBA = override(RGBA)
+    __all__.append('RGBA')
+
 if Gdk._version == '2.0':
     class Rectangle(Gdk.Rectangle):
 
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index aaf593e..83c4944 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -345,6 +345,16 @@ class TestGdk(unittest.TestCase):
         self.assertEquals(color.green, 200)
         self.assertEquals(color.blue, 300)
 
+    def test_rgba(self):
+        self.assertEquals(Gdk.RGBA, overrides.Gdk.RGBA)
+        rgba = Gdk.RGBA(0.1, 0.2, 0.3, 0.4)
+        self.assertEquals(rgba.red, 0.1)
+        self.assertEquals(rgba.green, 0.2)
+        self.assertEquals(rgba.blue, 0.3)
+        self.assertEquals(rgba.alpha, 0.4)
+        rgba.green = 0.9
+        self.assertEquals(rgba.green, 0.9)
+
     def test_event(self):
         event = Gdk.Event.new(Gdk.EventType.CONFIGURE)
         self.assertEquals(event.type, Gdk.EventType.CONFIGURE)



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