[pygobject] Move gobject static functions and constants to gi
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Move gobject static functions and constants to gi
- Date: Mon, 5 Nov 2012 08:32:33 +0000 (UTC)
commit da2106902eb3dabebdff1674743cb3040566a745
Author: Simon Feltman <sfeltman src gnome org>
Date: Sun Nov 4 02:57:29 2012 -0800
Move gobject static functions and constants to gi
Replace the following functions with gi and overrides:
type_children, type_interfaces, signal_list_ids, signal_list_names,
signal_lookup, signal_name, type_parent. Assign SIGNAL_* and
PARAM_* from gi SignalFlags and ParamFlags respectively.
Move module level assignments of a number of static functions to
the GObject.py overrides file.
https://bugzilla.gnome.org/show_bug.cgi?id=687487
docs/reference/pygobject-functions.xml | 25 ---
gi/_gobject/__init__.py | 72 +---------
gi/_gobject/gobjectmodule.c | 272 --------------------------------
gi/overrides/GObject.py | 208 ++++++++++++++++++++++++-
gi/overrides/__init__.py | 5 +-
tests/test_signal.py | 11 +-
6 files changed, 215 insertions(+), 378 deletions(-)
---
diff --git a/docs/reference/pygobject-functions.xml b/docs/reference/pygobject-functions.xml
index 1f50fbe..646b460 100644
--- a/docs/reference/pygobject-functions.xml
+++ b/docs/reference/pygobject-functions.xml
@@ -31,14 +31,6 @@ linkend="function-gobject--type-is-a">gobject.type_is_a</link></methodname>
<methodparam><parameter>parent_type</parameter></methodparam>
</methodsynopsis><methodsynopsis language="python">
<methodname><link
-linkend="function-gobject--type-children">gobject.type_children</link></methodname>
- <methodparam><parameter>type</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
-linkend="function-gobject--type-interfaces">gobject.type_interfaces</link></methodname>
- <methodparam><parameter>type</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
linkend="function-gobject--type-register">gobject.type_register</link></methodname>
<methodparam><parameter>class</parameter></methodparam>
</methodsynopsis><methodsynopsis language="python">
@@ -51,23 +43,6 @@ linkend="function-gobject--signal-new">gobject.signal_new</link></methodname>
<methodparam><parameter>param_types</parameter></methodparam>
</methodsynopsis><methodsynopsis language="python">
<methodname><link
-linkend="function-gobject--signal-list-names">gobject.signal_list_names</link></methodname>
- <methodparam><parameter role="keyword">type</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
-linkend="function-gobject--signal-list-ids">gobject.signal_list_ids</link></methodname>
- <methodparam><parameter role="keyword">type</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
-linkend="function-gobject--signal-lookup">gobject.signal_lookup</link></methodname>
- <methodparam><parameter role="keyword">name</parameter></methodparam>
- <methodparam><parameter role="keyword">type</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
-linkend="function-gobject--signal-name">gobject.signal_name</link></methodname>
- <methodparam><parameter role="keyword">signal_id</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
linkend="function-gobject--signal-query1">gobject.signal_query</link></methodname>
<methodparam><parameter role="keyword">name</parameter></methodparam>
<methodparam><parameter role="keyword">type</parameter></methodparam>
diff --git a/gi/_gobject/__init__.py b/gi/_gobject/__init__.py
index 1bd5e8f..67787c6 100644
--- a/gi/_gobject/__init__.py
+++ b/gi/_gobject/__init__.py
@@ -27,78 +27,18 @@ import sys
if 'gobject' in sys.modules:
raise ImportError('When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject".')
-from .. import _glib
from . import _gobject
from . import constants
from . import propertyhelper
from . import signalhelper
-GBoxed = _gobject.GBoxed
-GEnum = _gobject.GEnum
-GFlags = _gobject.GFlags
GInterface = _gobject.GInterface
GObject = _gobject.GObject
-GObjectWeakRef = _gobject.GObjectWeakRef
-GParamSpec = _gobject.GParamSpec
-GPointer = _gobject.GPointer
GType = _gobject.GType
-PARAM_CONSTRUCT = _gobject.PARAM_CONSTRUCT
-PARAM_CONSTRUCT_ONLY = _gobject.PARAM_CONSTRUCT_ONLY
-PARAM_LAX_VALIDATION = _gobject.PARAM_LAX_VALIDATION
-PARAM_READABLE = _gobject.PARAM_READABLE
-PARAM_READWRITE = _gobject.PARAM_READWRITE
-PARAM_WRITABLE = _gobject.PARAM_WRITABLE
-SIGNAL_ACTION = _gobject.SIGNAL_ACTION
-SIGNAL_DETAILED = _gobject.SIGNAL_DETAILED
-SIGNAL_NO_HOOKS = _gobject.SIGNAL_NO_HOOKS
-SIGNAL_NO_RECURSE = _gobject.SIGNAL_NO_RECURSE
-SIGNAL_RUN_CLEANUP = _gobject.SIGNAL_RUN_CLEANUP
-SIGNAL_RUN_FIRST = _gobject.SIGNAL_RUN_FIRST
-SIGNAL_RUN_LAST = _gobject.SIGNAL_RUN_LAST
-TYPE_GSTRING = _gobject.TYPE_GSTRING
TYPE_INVALID = _gobject.TYPE_INVALID
-Warning = _gobject.Warning
_PyGObject_API = _gobject._PyGObject_API
-add_emission_hook = _gobject.add_emission_hook
-features = _gobject.features
-list_properties = _gobject.list_properties
-new = _gobject.new
pygobject_version = _gobject.pygobject_version
-remove_emission_hook = _gobject.remove_emission_hook
-signal_accumulator_true_handled = _gobject.signal_accumulator_true_handled
-signal_list_ids = _gobject.signal_list_ids
-signal_list_names = _gobject.signal_list_names
-signal_lookup = _gobject.signal_lookup
-signal_name = _gobject.signal_name
-signal_new = _gobject.signal_new
-signal_query = _gobject.signal_query
-threads_init = _gobject.threads_init
-type_children = _gobject.type_children
-type_from_name = _gobject.type_from_name
-type_interfaces = _gobject.type_interfaces
-type_is_a = _gobject.type_is_a
-type_name = _gobject.type_name
-type_parent = _gobject.type_parent
-type_register = _gobject.type_register
-spawn_async = _glib.spawn_async
-Pid = _glib.Pid
-GError = _glib.GError
-OptionGroup = _glib.OptionGroup
-OptionContext = _glib.OptionContext
-
-OPTION_FLAG_HIDDEN = _glib.OPTION_FLAG_HIDDEN
-OPTION_FLAG_IN_MAIN = _glib.OPTION_FLAG_IN_MAIN
-OPTION_FLAG_REVERSE = _glib.OPTION_FLAG_REVERSE
-OPTION_FLAG_NO_ARG = _glib.OPTION_FLAG_NO_ARG
-OPTION_FLAG_FILENAME = _glib.OPTION_FLAG_FILENAME
-OPTION_FLAG_OPTIONAL_ARG = _glib.OPTION_FLAG_OPTIONAL_ARG
-OPTION_FLAG_NOALIAS = _glib.OPTION_FLAG_NOALIAS
-OPTION_ERROR_UNKNOWN_OPTION = _glib.OPTION_ERROR_UNKNOWN_OPTION
-OPTION_ERROR_BAD_VALUE = _glib.OPTION_ERROR_BAD_VALUE
-OPTION_ERROR_FAILED = _glib.OPTION_ERROR_FAILED
-OPTION_REMAINING = _glib.OPTION_REMAINING
-OPTION_ERROR = _glib.OPTION_ERROR
TYPE_NONE = constants.TYPE_NONE
TYPE_INTERFACE = constants.TYPE_INTERFACE
@@ -143,13 +83,6 @@ G_MAXSSIZE = constants.G_MAXSSIZE
G_MINOFFSET = constants.G_MINOFFSET
G_MAXOFFSET = constants.G_MAXOFFSET
-Property = propertyhelper.Property
-Signal = signalhelper.Signal
-SignalOverride = signalhelper.SignalOverride
-
-from .._glib import option
-sys.modules['gi._gobject.option'] = option
-
class GObjectMeta(type):
"Metaclass for automatically registering GObject classes"
@@ -169,9 +102,6 @@ class GObjectMeta(type):
if cls.__module__.startswith('gi.overrides.'):
return
- type_register(cls, namespace.get('__gtype_name__'))
+ _gobject.type_register(cls, namespace.get('__gtype_name__'))
_gobject._install_metaclass(GObjectMeta)
-
-# Deprecated naming still available for backwards compatibility.
-property = Property
diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c
index ebe49da..0d62a42 100644
--- a/gi/_gobject/gobjectmodule.c
+++ b/gi/_gobject/gobjectmodule.c
@@ -141,28 +141,6 @@ pyg_type_from_name (PyObject *self, PyObject *args)
}
static PyObject *
-pyg_type_parent (PyObject *self, PyObject *args)
-{
- PyObject *gtype;
- GType type, parent;
-#if 0
- if (PyErr_Warn(PyExc_DeprecationWarning,
- "gobject.type_parent is deprecated; "
- "use GType.parent instead"))
- return NULL;
-#endif
- if (!PyArg_ParseTuple(args, "O:gobject.type_parent", >ype))
- return NULL;
- if ((type = pyg_type_from_object(gtype)) == 0)
- return NULL;
- parent = g_type_parent(type);
- if (parent != 0)
- return pyg_type_wrapper_new(parent);
- PyErr_SetString(PyExc_RuntimeError, "no parent for type");
- return NULL;
-}
-
-static PyObject *
pyg_type_is_a (PyObject *self, PyObject *args)
{
PyObject *gtype, *gparent;
@@ -182,68 +160,6 @@ pyg_type_is_a (PyObject *self, PyObject *args)
return PyBool_FromLong(g_type_is_a(type, parent));
}
-static PyObject *
-pyg_type_children (PyObject *self, PyObject *args)
-{
- PyObject *gtype, *list;
- GType type, *children;
- guint n_children, i;
-#if 0
- if (PyErr_Warn(PyExc_DeprecationWarning,
- "gobject.type_children is deprecated; "
- "use GType.children instead"))
- return NULL;
-#endif
- if (!PyArg_ParseTuple(args, "O:gobject.type_children", >ype))
- return NULL;
- if ((type = pyg_type_from_object(gtype)) == 0)
- return NULL;
- children = g_type_children(type, &n_children);
- if (children) {
- list = PyList_New(0);
- for (i = 0; i < n_children; i++) {
- PyObject *o;
- PyList_Append(list, o=pyg_type_wrapper_new(children[i]));
- Py_DECREF(o);
- }
- g_free(children);
- return list;
- }
- PyErr_SetString(PyExc_RuntimeError, "invalid type, or no children");
- return NULL;
-}
-
-static PyObject *
-pyg_type_interfaces (PyObject *self, PyObject *args)
-{
- PyObject *gtype, *list;
- GType type, *interfaces;
- guint n_interfaces, i;
-#if 0
- if (PyErr_Warn(PyExc_DeprecationWarning,
- "gobject.type_interfaces is deprecated; "
- "use GType.interfaces instead"))
- return NULL;
-#endif
- if (!PyArg_ParseTuple(args, "O:gobject.type_interfaces", >ype))
- return NULL;
- if ((type = pyg_type_from_object(gtype)) == 0)
- return NULL;
- interfaces = g_type_interfaces(type, &n_interfaces);
- if (interfaces) {
- list = PyList_New(0);
- for (i = 0; i < n_interfaces; i++) {
- PyObject *o;
- PyList_Append(list, o=pyg_type_wrapper_new(interfaces[i]));
- Py_DECREF(o);
- }
- g_free(interfaces);
- return list;
- }
- PyErr_SetString(PyExc_RuntimeError, "invalid type, or no interfaces");
- return NULL;
-}
-
static void
pyg_object_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
@@ -1398,171 +1314,6 @@ pyg_signal_new(PyObject *self, PyObject *args)
}
static PyObject *
-pyg_signal_list_names (PyObject *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "type", NULL };
- PyObject *py_itype, *list;
- GObjectClass *class = NULL;
- GType itype;
- guint n;
- guint *ids;
- guint i;
- gpointer iface = NULL;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "O:gobject.signal_list_names",
- kwlist, &py_itype))
- return NULL;
- if ((itype = pyg_type_from_object(py_itype)) == 0)
- return NULL;
-
- if (G_TYPE_IS_INSTANTIATABLE(itype)) {
- class = g_type_class_ref(itype);
- if (!class) {
- PyErr_SetString(PyExc_RuntimeError,
- "could not get a reference to type class");
- return NULL;
- }
- } else if (!G_TYPE_IS_INTERFACE(itype)) {
- PyErr_SetString(PyExc_TypeError,
- "type must be instantiable or an interface");
- return NULL;
- } else {
- iface = g_type_default_interface_ref(itype);
- }
-
- ids = g_signal_list_ids(itype, &n);
-
- list = PyTuple_New((gint)n);
- if (list != NULL) {
- for (i = 0; i < n; i++)
- PyTuple_SetItem(list, i,
- PYGLIB_PyUnicode_FromString(g_signal_name(ids[i])));
- }
-
- g_free(ids);
- if (class)
- g_type_class_unref(class);
- else
- g_type_default_interface_unref(iface);
-
- return list;
-}
-
-static PyObject *
-pyg_signal_list_ids (PyObject *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "type", NULL };
- PyObject *py_itype, *list;
- GObjectClass *class = NULL;
- GType itype;
- guint n;
- guint *ids;
- guint i;
- gpointer iface = NULL;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "O:gobject.signal_list_ids",
- kwlist, &py_itype))
- return NULL;
- if ((itype = pyg_type_from_object(py_itype)) == 0)
- return NULL;
-
- if (G_TYPE_IS_INSTANTIATABLE(itype)) {
- class = g_type_class_ref(itype);
- if (!class) {
- PyErr_SetString(PyExc_RuntimeError,
- "could not get a reference to type class");
- return NULL;
- }
- } else if (!G_TYPE_IS_INTERFACE(itype)) {
- PyErr_SetString(PyExc_TypeError,
- "type must be instantiable or an interface");
- return NULL;
- } else {
- iface = g_type_default_interface_ref(itype);
- }
-
- ids = g_signal_list_ids(itype, &n);
-
- list = PyTuple_New((gint)n);
- if (list == NULL) {
- g_free(ids);
- g_type_class_unref(class);
- return NULL;
- }
-
- for (i = 0; i < n; i++)
- PyTuple_SetItem(list, i, PYGLIB_PyLong_FromLong(ids[i]));
- g_free(ids);
- if (class)
- g_type_class_unref(class);
- else
- g_type_default_interface_unref(iface);
-
- return list;
-}
-
-static PyObject *
-pyg_signal_lookup (PyObject *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "name", "type", NULL };
- PyObject *py_itype;
- GObjectClass *class = NULL;
- GType itype;
- gchar *signal_name;
- guint id;
- gpointer iface = NULL;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO:gobject.signal_lookup",
- kwlist, &signal_name, &py_itype))
- return NULL;
- if ((itype = pyg_type_from_object(py_itype)) == 0)
- return NULL;
-
- if (G_TYPE_IS_INSTANTIATABLE(itype)) {
- class = g_type_class_ref(itype);
- if (!class) {
- PyErr_SetString(PyExc_RuntimeError,
- "could not get a reference to type class");
- return NULL;
- }
- } else if (!G_TYPE_IS_INTERFACE(itype)) {
- PyErr_SetString(PyExc_TypeError,
- "type must be instantiable or an interface");
- return NULL;
- } else {
- iface = g_type_default_interface_ref(itype);
- }
-
- id = g_signal_lookup(signal_name, itype);
-
- if (class)
- g_type_class_unref(class);
- else
- g_type_default_interface_unref(iface);
- return PYGLIB_PyLong_FromLong(id);
-}
-
-static PyObject *
-pyg_signal_name (PyObject *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "signal_id", NULL };
- const gchar *signal_name;
- guint id;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:gobject.signal_name",
- kwlist, &id))
- return NULL;
- signal_name = g_signal_name(id);
- if (signal_name)
- return PYGLIB_PyUnicode_FromString(signal_name);
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
pyg_signal_query (PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist1[] = { "name", "type", NULL };
@@ -1987,20 +1738,9 @@ pyg__install_metaclass(PyObject *dummy, PyTypeObject *metaclass)
static PyMethodDef _gobject_functions[] = {
{ "type_name", pyg_type_name, METH_VARARGS },
{ "type_from_name", pyg_type_from_name, METH_VARARGS },
- { "type_parent", pyg_type_parent, METH_VARARGS },
{ "type_is_a", pyg_type_is_a, METH_VARARGS },
- { "type_children", pyg_type_children, METH_VARARGS },
- { "type_interfaces", pyg_type_interfaces, METH_VARARGS },
{ "type_register", _wrap_pyg_type_register, METH_VARARGS },
{ "signal_new", pyg_signal_new, METH_VARARGS },
- { "signal_list_names",
- (PyCFunction)pyg_signal_list_names, METH_VARARGS|METH_KEYWORDS },
- { "signal_list_ids",
- (PyCFunction)pyg_signal_list_ids, METH_VARARGS|METH_KEYWORDS },
- { "signal_lookup",
- (PyCFunction)pyg_signal_lookup, METH_VARARGS|METH_KEYWORDS },
- { "signal_name",
- (PyCFunction)pyg_signal_name, METH_VARARGS|METH_KEYWORDS },
{ "signal_query",
(PyCFunction)pyg_signal_query, METH_VARARGS|METH_KEYWORDS },
{ "list_properties",
@@ -2441,18 +2181,6 @@ pygobject_register_constants(PyObject *m)
PyModule_AddObject(m, "G_MAXOFFSET", PyLong_FromLongLong(G_MAXOFFSET));
PyModule_AddIntConstant(m, "SIGNAL_RUN_FIRST", G_SIGNAL_RUN_FIRST);
- PyModule_AddIntConstant(m, "SIGNAL_RUN_LAST", G_SIGNAL_RUN_LAST);
- PyModule_AddIntConstant(m, "SIGNAL_RUN_CLEANUP", G_SIGNAL_RUN_CLEANUP);
- PyModule_AddIntConstant(m, "SIGNAL_NO_RECURSE", G_SIGNAL_NO_RECURSE);
- PyModule_AddIntConstant(m, "SIGNAL_DETAILED", G_SIGNAL_DETAILED);
- PyModule_AddIntConstant(m, "SIGNAL_ACTION", G_SIGNAL_ACTION);
- PyModule_AddIntConstant(m, "SIGNAL_NO_HOOKS", G_SIGNAL_NO_HOOKS);
-
- PyModule_AddIntConstant(m, "PARAM_READABLE", G_PARAM_READABLE);
- PyModule_AddIntConstant(m, "PARAM_WRITABLE", G_PARAM_WRITABLE);
- PyModule_AddIntConstant(m, "PARAM_CONSTRUCT", G_PARAM_CONSTRUCT);
- PyModule_AddIntConstant(m, "PARAM_CONSTRUCT_ONLY", G_PARAM_CONSTRUCT_ONLY);
- PyModule_AddIntConstant(m, "PARAM_LAX_VALIDATION", G_PARAM_LAX_VALIDATION);
PyModule_AddIntConstant(m, "PARAM_READWRITE", G_PARAM_READWRITE);
/* The rest of the types are set in __init__.py */
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 49052dd..e3ee9df 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -19,11 +19,25 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
+import sys
+from collections import namedtuple
+
import gi.overrides
+import gi.module
from gi.repository import GLib
+from gi._gobject import _gobject
+from gi._gobject import propertyhelper
+from gi._gobject import signalhelper
+
+GObjectModule = gi.module.get_introspection_module('GObject')
__all__ = []
+
+from gi._glib import option
+sys.modules['gi._gobject.option'] = option
+
+
# API aliases for backwards compatibility
for name in ['markup_escape_text', 'get_application_name',
'set_application_name', 'get_prgname', 'set_prgname',
@@ -33,7 +47,8 @@ for name in ['markup_escape_text', 'get_application_name',
'MainLoop', 'MainContext', 'main_context_default',
'source_remove', 'Source', 'Idle', 'Timeout', 'PollFD',
'idle_add', 'timeout_add', 'timeout_add_seconds',
- 'io_add_watch', 'child_watch_add', 'get_current_time']:
+ 'io_add_watch', 'child_watch_add', 'get_current_time',
+ 'spawn_async']:
globals()[name] = gi.overrides.deprecated(getattr(GLib, name), 'GLib.' + name)
__all__.append(name)
@@ -50,7 +65,11 @@ for name in ['PRIORITY_DEFAULT', 'PRIORITY_DEFAULT_IDLE', 'PRIORITY_HIGH',
'SPAWN_SEARCH_PATH', 'SPAWN_STDOUT_TO_DEV_NULL',
'SPAWN_STDERR_TO_DEV_NULL', 'SPAWN_CHILD_INHERITS_STDIN',
'SPAWN_FILE_AND_ARGV_ZERO',
- 'glib_version']:
+ 'OPTION_FLAG_HIDDEN', 'OPTION_FLAG_IN_MAIN', 'OPTION_FLAG_REVERSE',
+ 'OPTION_FLAG_NO_ARG', 'OPTION_FLAG_FILENAME', 'OPTION_FLAG_OPTIONAL_ARG',
+ 'OPTION_FLAG_NOALIAS', 'OPTION_ERROR_UNKNOWN_OPTION',
+ 'OPTION_ERROR_BAD_VALUE', 'OPTION_ERROR_FAILED', 'OPTION_REMAINING',
+ 'OPTION_ERROR', 'glib_version']:
globals()[name] = getattr(GLib, name)
__all__.append(name)
@@ -70,3 +89,188 @@ G_MAXUINT64 = GLib.MAXUINT64
__all__ += ['G_MININT8', 'G_MAXINT8', 'G_MAXUINT8', 'G_MININT16',
'G_MAXINT16', 'G_MAXUINT16', 'G_MININT32', 'G_MAXINT32',
'G_MAXUINT32', 'G_MININT64', 'G_MAXINT64', 'G_MAXUINT64']
+
+
+TYPE_INVALID = GObjectModule.type_from_name('invalid')
+TYPE_NONE = GObjectModule.type_from_name('void')
+TYPE_INTERFACE = GObjectModule.type_from_name('GInterface')
+TYPE_CHAR = GObjectModule.type_from_name('gchar')
+TYPE_UCHAR = GObjectModule.type_from_name('guchar')
+TYPE_BOOLEAN = GObjectModule.type_from_name('gboolean')
+TYPE_INT = GObjectModule.type_from_name('gint')
+TYPE_UINT = GObjectModule.type_from_name('guint')
+TYPE_LONG = GObjectModule.type_from_name('glong')
+TYPE_ULONG = GObjectModule.type_from_name('gulong')
+TYPE_INT64 = GObjectModule.type_from_name('gint64')
+TYPE_UINT64 = GObjectModule.type_from_name('guint64')
+TYPE_ENUM = GObjectModule.type_from_name('GEnum')
+TYPE_FLAGS = GObjectModule.type_from_name('GFlags')
+TYPE_FLOAT = GObjectModule.type_from_name('gfloat')
+TYPE_DOUBLE = GObjectModule.type_from_name('gdouble')
+TYPE_STRING = GObjectModule.type_from_name('gchararray')
+TYPE_POINTER = GObjectModule.type_from_name('gpointer')
+TYPE_BOXED = GObjectModule.type_from_name('GBoxed')
+TYPE_PARAM = GObjectModule.type_from_name('GParam')
+TYPE_OBJECT = GObjectModule.type_from_name('GObject')
+TYPE_PYOBJECT = GObjectModule.type_from_name('PyObject')
+TYPE_GTYPE = GObjectModule.type_from_name('GType')
+TYPE_STRV = GObjectModule.type_from_name('GStrv')
+TYPE_VARIANT = GObjectModule.type_from_name('GVariant')
+TYPE_GSTRING = GObjectModule.type_from_name('GString')
+TYPE_UNICHAR = TYPE_UINT
+__all__ += ['TYPE_INVALID', 'TYPE_NONE', 'TYPE_INTERFACE', 'TYPE_CHAR',
+ 'TYPE_UCHAR', 'TYPE_BOOLEAN', 'TYPE_INT', 'TYPE_UINT', 'TYPE_LONG',
+ 'TYPE_ULONG', 'TYPE_INT64', 'TYPE_UINT64', 'TYPE_ENUM', 'TYPE_FLAGS',
+ 'TYPE_FLOAT', 'TYPE_DOUBLE', 'TYPE_STRING', 'TYPE_POINTER',
+ 'TYPE_BOXED', 'TYPE_PARAM', 'TYPE_OBJECT', 'TYPE_PYOBJECT',
+ 'TYPE_GTYPE', 'TYPE_STRV', 'TYPE_VARIANT', 'TYPE_GSTRING', 'TYPE_UNICHAR']
+
+
+# Deprecated, use GLib directly
+Pid = GLib.Pid
+GError = GLib.GError
+OptionGroup = GLib.OptionGroup
+OptionContext = GLib.OptionContext
+__all__ += ['Pid', 'GError', 'OptionGroup', 'OptionContext']
+
+
+# Deprecated, use: GObject.ParamFlags.* directly
+PARAM_CONSTRUCT = GObjectModule.ParamFlags.CONSTRUCT
+PARAM_CONSTRUCT_ONLY = GObjectModule.ParamFlags.CONSTRUCT_ONLY
+PARAM_LAX_VALIDATION = GObjectModule.ParamFlags.LAX_VALIDATION
+PARAM_READABLE = GObjectModule.ParamFlags.READABLE
+PARAM_WRITABLE = GObjectModule.ParamFlags.WRITABLE
+# PARAM_READWRITE should come from the gi module but cannot due to:
+# https://bugzilla.gnome.org/show_bug.cgi?id=687615
+PARAM_READWRITE = PARAM_READABLE | PARAM_WRITABLE
+__all__ += ['PARAM_CONSTRUCT', 'PARAM_CONSTRUCT_ONLY', 'PARAM_LAX_VALIDATION',
+ 'PARAM_READABLE', 'PARAM_WRITABLE', 'PARAM_READWRITE']
+
+
+# Deprecated, use: GObject.SignalFlags.* directly
+SIGNAL_ACTION = GObjectModule.SignalFlags.ACTION
+SIGNAL_DETAILED = GObjectModule.SignalFlags.DETAILED
+SIGNAL_NO_HOOKS = GObjectModule.SignalFlags.NO_HOOKS
+SIGNAL_NO_RECURSE = GObjectModule.SignalFlags.NO_RECURSE
+SIGNAL_RUN_CLEANUP = GObjectModule.SignalFlags.RUN_CLEANUP
+SIGNAL_RUN_FIRST = GObjectModule.SignalFlags.RUN_FIRST
+SIGNAL_RUN_LAST = GObjectModule.SignalFlags.RUN_LAST
+__all__ += ['SIGNAL_ACTION', 'SIGNAL_DETAILED', 'SIGNAL_NO_HOOKS',
+ 'SIGNAL_NO_RECURSE', 'SIGNAL_RUN_CLEANUP', 'SIGNAL_RUN_FIRST',
+ 'SIGNAL_RUN_LAST']
+
+
+# Static types
+GBoxed = _gobject.GBoxed
+GEnum = _gobject.GEnum
+GFlags = _gobject.GFlags
+GInterface = _gobject.GInterface
+GObject = _gobject.GObject
+GObjectWeakRef = _gobject.GObjectWeakRef
+GParamSpec = _gobject.GParamSpec
+GPointer = _gobject.GPointer
+GType = _gobject.GType
+Warning = _gobject.Warning
+__all__ += ['GBoxed', 'GEnum', 'GFlags', 'GInterface', 'GObject',
+ 'GObjectWeakRef', 'GParamSpec', 'GPointer', 'GType',
+ 'Warning']
+
+
+add_emission_hook = _gobject.add_emission_hook
+features = _gobject.features
+list_properties = _gobject.list_properties
+new = _gobject.new
+pygobject_version = _gobject.pygobject_version
+remove_emission_hook = _gobject.remove_emission_hook
+signal_accumulator_true_handled = _gobject.signal_accumulator_true_handled
+signal_new = _gobject.signal_new
+threads_init = _gobject.threads_init
+type_register = _gobject.type_register
+__all__ += ['add_emission_hook', 'features', 'list_properties',
+ 'new', 'pygobject_version', 'remove_emission_hook',
+ 'signal_accumulator_true_handled',
+ 'signal_new', 'threads_init', 'type_register']
+
+
+def type_from_name(name):
+ type_ = GObjectModule.type_from_name(name)
+ if type_ == TYPE_INVALID:
+ raise RuntimeError('unknown type name: %s' % name)
+ return type_
+
+__all__.append('type_from_name')
+
+
+def type_parent(type_):
+ parent = GObjectModule.type_parent(type_)
+ if parent == TYPE_INVALID:
+ raise RuntimeError('no parent for type')
+ return parent
+
+__all__.append('type_parent')
+
+
+def _validate_type_for_signal_method(type_):
+ if hasattr(type_, '__gtype__'):
+ type_ = type_.__gtype__
+ if not type_.is_instantiatable() and not type_.is_interface():
+ raise TypeError('type must be instantiable or an interface, got %s' % type_)
+
+
+def signal_list_ids(type_):
+ _validate_type_for_signal_method(type_)
+ return GObjectModule.signal_list_ids(type_)
+
+__all__.append('signal_list_ids')
+
+
+def signal_list_names(type_):
+ ids = signal_list_ids(type_)
+ return tuple(GObjectModule.signal_name(i) for i in ids)
+
+__all__.append('signal_list_names')
+
+
+def signal_lookup(name, type_):
+ _validate_type_for_signal_method(type_)
+ return GObjectModule.signal_lookup(name, type_)
+
+__all__.append('signal_lookup')
+
+
+def signal_query(id_or_name, type_=None):
+ SignalQuery = namedtuple('SignalQuery',
+ ['signal_id',
+ 'signal_name',
+ 'itype',
+ 'signal_flags',
+ 'return_type',
+ # n_params',
+ 'param_types'])
+
+ # signal_query needs to use a static method until the following bugs are fixed:
+ # https://bugzilla.gnome.org/show_bug.cgi?id=687550
+ # https://bugzilla.gnome.org/show_bug.cgi?id=687545
+ # https://bugzilla.gnome.org/show_bug.cgi?id=687541
+ if type_ is not None:
+ id_or_name = signal_lookup(id_or_name, type_)
+
+ res = _gobject.signal_query(id_or_name)
+ if res is None:
+ return None
+
+ # Return a named tuple which allows indexing like the static bindings
+ # along with field like access of the gi struct.
+ # Note however that the n_params was not returned from the static bindings.
+ return SignalQuery(*res)
+
+__all__.append('signal_query')
+
+
+Property = propertyhelper.Property
+Signal = signalhelper.Signal
+SignalOverride = signalhelper.SignalOverride
+# Deprecated naming "property" available for backwards compatibility.
+# Keep this at the end of the file to avoid clobbering the builtin.
+property = Property
+__all__ += ['Property', 'Signal', 'SignalOverride', 'property']
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index 3570c95..4487d7c 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -1,5 +1,6 @@
import types
import warnings
+import functools
from gi import _gobject, PyGIDeprecationWarning
@@ -74,11 +75,9 @@ def override(type_):
def deprecated(fn, replacement):
'''Decorator for marking methods and classes as deprecated'''
+ @functools.wraps(fn)
def wrapped(*args, **kwargs):
warnings.warn('%s is deprecated; use %s instead' % (fn.__name__, replacement),
PyGIDeprecationWarning, stacklevel=2)
return fn(*args, **kwargs)
- wrapped.__name__ = fn.__name__
- wrapped.__doc__ = fn.__doc__
- wrapped.__dict__.update(fn.__dict__)
return wrapped
diff --git a/tests/test_signal.py b/tests/test_signal.py
index 8f0a2e7..f4396ce 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -735,9 +735,10 @@ class TestPython3Signals(unittest.TestCase):
class TestSignalModuleLevelFunctions(unittest.TestCase):
- @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=687492
+ @unittest.skipIf(sys.version_info < (2, 7), 'Requires Python >= 2.7')
def test_signal_list_ids_with_invalid_type(self):
- self.assertRaises(TypeError, GObject.signal_list_ids, GObject.TYPE_INVALID)
+ with self.assertRaisesRegexp(TypeError, 'type must be instantiable or an interface.*'):
+ GObject.signal_list_ids(GObject.TYPE_INVALID)
@unittest.skipIf(sys.version_info < (2, 7), 'Requires Python >= 2.7')
def test_signal_list_ids(self):
@@ -751,10 +752,10 @@ class TestSignalModuleLevelFunctions(unittest.TestCase):
# There is no signal 0 in gobject
self.assertEqual(GObject.signal_name(0), None)
- @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=687492
+ @unittest.skipIf(sys.version_info < (2, 7), 'Requires Python >= 2.7')
def test_signal_lookup_with_invalid_type(self):
- self.assertRaises(TypeError, GObject.signal_lookup,
- 'NOT_A_SIGNAL_NAME', GObject.TYPE_INVALID)
+ with self.assertRaisesRegexp(TypeError, 'type must be instantiable or an interface.*'):
+ GObject.signal_lookup('NOT_A_SIGNAL_NAME', GObject.TYPE_INVALID)
@unittest.skipIf(sys.version_info < (2, 7), 'Requires Python >= 2.7')
def test_signal_lookup(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]