[pygobject] [gi-overrides] add cursor overrides
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] [gi-overrides] add cursor overrides
- Date: Wed, 16 Feb 2011 22:57:45 +0000 (UTC)
commit 6025b62ee662af347e48b6752e6d5be74b4a8215
Author: John (J5) Palmieri <johnp redhat com>
Date: Wed Feb 16 17:52:38 2011 -0500
[gi-overrides] add cursor overrides
https://bugzilla.gnome.org/show_bug.cgi?id=635947
gi/overrides/Gdk.py | 41 +++++++++++++++++++++++++++++++++++++++++
tests/test_overrides.py | 23 +++++++++++++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py
index 70bd495..2c26767 100644
--- a/gi/overrides/Gdk.py
+++ b/gi/overrides/Gdk.py
@@ -149,6 +149,47 @@ class DragContext(Gdk.DragContext):
DragContext = override(DragContext)
__all__.append('DragContext')
+class Cursor(Gdk.Cursor):
+ def __new__(cls, *args, **kwds):
+ arg_len = len(args)
+ kwd_len = len(kwds)
+ total_len = arg_len + kwd_len
+
+ def _new(cursor_type):
+ return cls.new(cursor_type)
+
+ def _new_for_display(display, cursor_type):
+ return cls.new_for_display(display, cursor_type)
+
+ def _new_from_pixbuf(display, pixbuf, x, y):
+ return cls.new_from_pixbuf(display, pixbuf, x, y)
+
+ def _new_from_pixmap(source, mask, fg, bg, x, y):
+ return cls.new_from_pixmap(source, mask, fg, bg, x, y)
+
+ _constructor = None
+ if total_len == 1:
+ _constructor = _new
+ elif total_len == 2:
+ _constructor = _new_for_display
+ elif total_len == 4:
+ _constructor = _new_from_pixbuf
+ elif total_len == 6:
+ if Gdk._version != '2.0':
+ # pixmaps don't exist in Gdk 3.0
+ raise ValueError("Wrong number of parameters")
+ _constructor = _new_from_pixmap
+ else:
+ raise ValueError("Wrong number of parameters")
+
+ return _constructor(*args, **kwds)
+
+ def __init__(self, *args, **kwargs):
+ Gdk.Cursor.__init__(self)
+
+Cursor = override(Cursor)
+__all__.append('Cursor')
+
import sys
initialized, argv = Gdk.init_check(sys.argv)
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index f25fb07..0ab1968 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -359,6 +359,29 @@ class TestGdk(unittest.TestCase):
event.type = Gdk.EventType.SCROLL
self.assertRaises(AttributeError, lambda: getattr(event, 'foo_bar'))
+ def test_cursor(self):
+ self.assertEquals(Gdk.Cursor, overrides.Gdk.Cursor)
+ c = Gdk.Cursor(Gdk.CursorType.WATCH)
+ self.assertNotEqual(c, None)
+ c = Gdk.Cursor(cursor_type = Gdk.CursorType.WATCH)
+ self.assertNotEqual(c, None)
+
+ display_manager = Gdk.DisplayManager.get()
+ display = display_manager.get_default_display()
+
+ test_pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB,
+ False,
+ 8,
+ 5,
+ 10)
+
+ c = Gdk.Cursor(display,
+ test_pixbuf,
+ y=0, x=0)
+
+ self.assertNotEqual(c, None)
+ self.assertRaises(ValueError, Gdk.Cursor, 1, 2, 3)
+
class TestGtk(unittest.TestCase):
def test_container(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]