[pygobject] Deprecate Gdk.Cursor constructor dispatching
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Deprecate Gdk.Cursor constructor dispatching
- Date: Tue, 12 Nov 2013 12:44:07 +0000 (UTC)
commit 795201873a3aae530598f5e16470b6a8d2d55c23
Author: Simon Feltman <sfeltman src gnome org>
Date: Thu Aug 15 20:01:48 2013 -0700
Deprecate Gdk.Cursor constructor dispatching
Give deprecation warning for the overridden __new__ method on
Gdk.Cursor when more than one argument is used. Recommend using
Gdk.Cursor.new_for_display, new_from_pixbuf, and new_from_pixmap
instead.
https://bugzilla.gnome.org/show_bug.cgi?id=705810
gi/overrides/Gdk.py | 48 +++++++++++++++++++++++++-----------------
tests/test_overrides_gdk.py | 17 +++++++++++---
2 files changed, 41 insertions(+), 24 deletions(-)
---
diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py
index 381e797..d979746 100644
--- a/gi/overrides/Gdk.py
+++ b/gi/overrides/Gdk.py
@@ -19,10 +19,12 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
+import sys
+import warnings
+
from ..overrides import override, strip_boolean_result
from ..module import get_introspection_module
-
-import sys
+from gi import PyGIDeprecationWarning
Gdk = get_introspection_module('Gdk')
@@ -275,34 +277,40 @@ class Cursor(Gdk.Cursor):
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
+ # Since g_object_newv (super.__new__) does not seem valid for
+ # direct use with GdkCursor, we must assume usage of at least
+ # one of the C constructors to be valid.
+ return cls.new(*args, **kwds)
+
elif total_len == 2:
- _constructor = _new_for_display
+ warnings.warn('Calling "Gdk.Cursor(display, cursor_type)" has been deprecated. '
+ 'Please use Gdk.Cursor.new_for_display(display, cursor_type). '
+ 'See: https://wiki.gnome.org/PyGObject/InitializerDeprecations',
+ PyGIDeprecationWarning)
+ return cls.new_for_display(*args, **kwds)
+
elif total_len == 4:
- _constructor = _new_from_pixbuf
+ warnings.warn('Calling "Gdk.Cursor(display, pixbuf, x, y)" has been deprecated. '
+ 'Please use Gdk.Cursor.new_from_pixbuf(display, pixbuf, x, y). '
+ 'See: https://wiki.gnome.org/PyGObject/InitializerDeprecations',
+ PyGIDeprecationWarning)
+ return cls.new_from_pixbuf(*args, **kwds)
+
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
+
+ warnings.warn('Calling "Gdk.Cursor(source, mask, fg, bg, x, y)" has been deprecated. '
+ 'Please use Gdk.Cursor.new_from_pixmap(source, mask, fg, bg, x, y). '
+ 'See: https://wiki.gnome.org/PyGObject/InitializerDeprecations',
+ PyGIDeprecationWarning)
+ return cls.new_from_pixmap(*args, **kwds)
+
else:
raise ValueError("Wrong number of parameters")
- return _constructor(*args, **kwds)
Cursor = override(Cursor)
__all__.append('Cursor')
diff --git a/tests/test_overrides_gdk.py b/tests/test_overrides_gdk.py
index 46f0a38..648597e 100644
--- a/tests/test_overrides_gdk.py
+++ b/tests/test_overrides_gdk.py
@@ -2,8 +2,10 @@
# vim: tabstop=4 shiftwidth=4 expandtab
import unittest
+import warnings
import gi.overrides
+from gi import PyGIDeprecationWarning
try:
from gi.repository import Gdk, GdkPixbuf, Gtk
@@ -111,11 +113,18 @@ class TestGdk(unittest.TestCase):
5,
10)
- c = Gdk.Cursor(display,
- test_pixbuf,
- y=0, x=0)
+ with warnings.catch_warnings(record=True) as warn:
+ warnings.simplefilter('always')
+ c = Gdk.Cursor(display,
+ test_pixbuf,
+ y=0, x=0)
+ self.assertNotEqual(c, None)
+
+ self.assertEqual(len(warn), 1)
+ self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
+ self.assertRegexpMatches(str(warn[0].message),
+ '.*new_from_pixbuf.*')
- self.assertNotEqual(c, None)
self.assertRaises(ValueError, Gdk.Cursor, 1, 2, 3)
def test_flags(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]