diff options
| author | Johan Dahlin <jdahlin@src.gnome.org> | 2004-06-04 16:01:30 +0000 |
|---|---|---|
| committer | Johan Dahlin <jdahlin@src.gnome.org> | 2004-06-04 16:01:30 +0000 |
| commit | cf0d95e330244e4434dbea63a4260cf6e6498591 (patch) | |
| tree | 4a56f5555308b00cac718adda2bddf0b75e17ddb /gobject | |
| parent | 64c298cb4a8ba1be1bc5da6d7c3d6fa4398a6e7c (diff) | |
| download | pygobject-cf0d95e330244e4434dbea63a4260cf6e6498591.tar.gz pygobject-cf0d95e330244e4434dbea63a4260cf6e6498591.tar.xz pygobject-cf0d95e330244e4434dbea63a4260cf6e6498591.zip | |
Impl
* gtk/gtkwidget.override (_wrap_gtk_widget_class_install_style_property): Impl
* gtk/gtkcontainer.override
(_wrap_gtk_container_class_list_child_properties): Rename first
kwlist argument to klass (from widget), class should be a
GObjectClass and not a GtkWidgetClass
(_wrap_gtk_container_class_install_child_property): Impl.
* gtk/gtk.defs: Change a couple of methods to functions and set
correct class
* pygobject.h: Add pyg_param_spec_from_object
* gobjectmodule.c (create_property): Don't install the property
here, return it instead. And don't require a GObjectClass as argument
(pyg_param_spec_from_object): New function
(add_properties): Update to new create_property
(pygobject_api_functions): Export pyg_param_spec_from_object
Diffstat (limited to 'gobject')
| -rw-r--r-- | gobject/gobjectmodule.c | 119 | ||||
| -rw-r--r-- | gobject/pygobject.h | 3 |
2 files changed, 92 insertions, 30 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index c9322f6..45b8460 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -869,10 +869,13 @@ add_signals (GType instance_type, PyObject *signals) return ret; } -static gboolean -create_property (GObjectClass *oclass, const gchar *prop_name, - GType prop_type, const gchar *nick, const gchar *blurb, - PyObject *args, GParamFlags flags) +static GParamSpec * +create_property (const gchar *prop_name, + GType prop_type, + const gchar *nick, + const gchar *blurb, + PyObject *args, + GParamFlags flags) { GParamSpec *pspec = NULL; @@ -883,7 +886,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, if (!PyArg_ParseTuple(args, "ccc", &minimum, &maximum, &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_char (prop_name, nick, blurb, minimum, maximum, default_value, flags); } @@ -894,7 +897,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, if (!PyArg_ParseTuple(args, "ccc", &minimum, &maximum, &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_uchar (prop_name, nick, blurb, minimum, maximum, default_value, flags); } @@ -904,7 +907,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, gboolean default_value; if (!PyArg_ParseTuple(args, "i", &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_boolean (prop_name, nick, blurb, default_value, flags); } @@ -915,7 +918,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, if (!PyArg_ParseTuple(args, "iii", &minimum, &maximum, &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_int (prop_name, nick, blurb, minimum, maximum, default_value, flags); } @@ -926,7 +929,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, if (!PyArg_ParseTuple(args, "iii", &minimum, &maximum, &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_uint (prop_name, nick, blurb, minimum, maximum, default_value, flags); } @@ -937,7 +940,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, if (!PyArg_ParseTuple(args, "lll", &minimum, &maximum, &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_long (prop_name, nick, blurb, minimum, maximum, default_value, flags); } @@ -948,7 +951,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, if (!PyArg_ParseTuple(args, "lll", &minimum, &maximum, &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_ulong (prop_name, nick, blurb, minimum, maximum, default_value, flags); } @@ -959,7 +962,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, if (!PyArg_ParseTuple(args, "LLL", &minimum, &maximum, &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_int64 (prop_name, nick, blurb, minimum, maximum, default_value, flags); } @@ -970,7 +973,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, if (!PyArg_ParseTuple(args, "LLL", &minimum, &maximum, &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_uint64 (prop_name, nick, blurb, minimum, maximum, default_value, flags); } @@ -980,7 +983,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, gint default_value; if (!PyArg_ParseTuple(args, "i", &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_enum (prop_name, nick, blurb, prop_type, default_value, flags); } @@ -990,7 +993,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, guint default_value; if (!PyArg_ParseTuple(args, "i", &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_flags (prop_name, nick, blurb, prop_type, default_value, flags); } @@ -1001,7 +1004,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, if (!PyArg_ParseTuple(args, "fff", &minimum, &maximum, &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_float (prop_name, nick, blurb, minimum, maximum, default_value, flags); } @@ -1012,7 +1015,7 @@ create_property (GObjectClass *oclass, const gchar *prop_name, if (!PyArg_ParseTuple(args, "ddd", &minimum, &maximum, &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_double (prop_name, nick, blurb, minimum, maximum, default_value, flags); } @@ -1022,29 +1025,29 @@ create_property (GObjectClass *oclass, const gchar *prop_name, const gchar *default_value; if (!PyArg_ParseTuple(args, "z", &default_value)) - return FALSE; + return NULL; pspec = g_param_spec_string (prop_name, nick, blurb, default_value, flags); } break; case G_TYPE_PARAM: if (!PyArg_ParseTuple(args, "")) - return FALSE; + return NULL; pspec = g_param_spec_param (prop_name, nick, blurb, prop_type, flags); break; case G_TYPE_BOXED: if (!PyArg_ParseTuple(args, "")) - return FALSE; + return NULL; pspec = g_param_spec_boxed (prop_name, nick, blurb, prop_type, flags); break; case G_TYPE_POINTER: if (!PyArg_ParseTuple(args, "")) - return FALSE; + return NULL; pspec = g_param_spec_pointer (prop_name, nick, blurb, flags); break; case G_TYPE_OBJECT: if (!PyArg_ParseTuple(args, "")) - return FALSE; + return NULL; pspec = g_param_spec_object (prop_name, nick, blurb, prop_type, flags); break; default: @@ -1058,10 +1061,60 @@ create_property (GObjectClass *oclass, const gchar *prop_name, g_snprintf(buf, sizeof(buf), "could not create param spec for type %s", g_type_name(prop_type)); PyErr_SetString(PyExc_TypeError, buf); - return FALSE; + return NULL; } - g_object_class_install_property(oclass, 1, pspec); - return TRUE; + + return pspec; +} + +GParamSpec * +pyg_param_spec_from_object (PyObject *tuple) +{ + gint val_length; + const gchar *prop_name; + GType prop_type; + const gchar *nick, *blurb; + PyObject *slice, *item, *py_prop_type; + GParamSpec *pspec; + + val_length = PyTuple_Size(tuple); + if (val_length < 4) { + PyErr_SetString(PyExc_TypeError, + "paramspec tuples must be at least 4 elements long"); + return NULL; + } + + slice = PySequence_GetSlice(tuple, 0, 4); + if (!slice) { + return NULL; + } + + if (!PyArg_ParseTuple(slice, "sOzz", &prop_name, &py_prop_type, &nick, &blurb)) { + Py_DECREF(slice); + return NULL; + } + + Py_DECREF(slice); + + prop_type = pyg_type_from_object(py_prop_type); + if (!prop_type) { + return NULL; + } + + item = PyTuple_GetItem(tuple, val_length-1); + if (!PyInt_Check(item)) { + PyErr_SetString(PyExc_TypeError, + "last element in tuple must be an int"); + return NULL; + } + + /* slice is the extra items in the tuple */ + slice = PySequence_GetSlice(tuple, 4, val_length-1); + pspec = create_property(prop_name, prop_type, + nick, blurb, slice, + PyInt_AsLong(item)); + + return pspec; } static gboolean @@ -1080,6 +1133,8 @@ add_properties (GType instance_type, PyObject *properties) GParamFlags flags; gint val_length; PyObject *slice, *item, *py_prop_type; + GParamSpec *pspec; + /* values are of format (type,nick,blurb, type_specific_args, flags) */ if (!PyString_Check(key)) { @@ -1131,13 +1186,18 @@ add_properties (GType instance_type, PyObject *properties) /* slice is the extra items in the tuple */ slice = PySequence_GetSlice(value, 3, val_length-1); - ret = create_property(oclass, prop_name, prop_type, nick, blurb, - slice, flags); + pspec = create_property(prop_name, prop_type, nick, blurb, + slice, flags); Py_DECREF(slice); - - if (!ret) + + if (pspec) { + g_object_class_install_property(oclass, 1, pspec); + } else { + ret = FALSE; break; + } } + g_type_class_unref(oclass); return ret; } @@ -2001,6 +2061,7 @@ struct _PyGObject_Functions pygobject_api_functions = { &PyGParamSpec_Type, pyg_param_spec_new, + pyg_param_spec_from_object }; DL_EXPORT(void) diff --git a/gobject/pygobject.h b/gobject/pygobject.h index e65611d..a4cdfce 100644 --- a/gobject/pygobject.h +++ b/gobject/pygobject.h @@ -109,6 +109,7 @@ struct _PyGObject_Functions { PyGThreadBlockFunc unblock_threads; PyTypeObject *paramspec_type; PyObject *(* paramspec_new)(GParamSpec *spec); + GParamSpec *(*paramspec_get)(PyObject *tuple); }; #ifndef _INSIDE_PYGOBJECT_ @@ -148,7 +149,7 @@ struct _PyGObject_Functions *_PyGObject_API; #define pyg_set_thread_block_funcs (_PyGObject_API->set_thread_block_funcs) #define PyGParamSpec_Type (*_PyGObject_API->paramspec_type) #define pyg_param_spec_new (_PyGObject_API->paramspec_new) - +#define pyg_param_spec_from_object (_PyGObject_API->paramspec_get) #define pyg_block_threads() G_STMT_START { \ if (_PyGObject_API->block_threads != NULL) \ (* _PyGObject_API->block_threads)(); \ |
