Hi James,
I added the ref/unref of the class. Okay to commit this?
-Jonathan
? examples/gobject/core.1209
? examples/gobject/core.4087
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/ChangeLog,v
retrieving revision 1.421
diff -u -p -r1.421 ChangeLog
--- ChangeLog 23 Jun 2002 14:12:03 -0000 1.421
+++ ChangeLog 23 Jun 2002 17:48:27 -0000
@@ -1,3 +1,10 @@
+Sun Jun 23 11:10:30 2002 Jonathan Blandford <[EMAIL PROTECTED]>
+
+ * pygboxed.c: Add GBoxed::copy
+
+ * pygobject.c (pygobject_init): take kwargs so we can pass
+ construct-only arguments to our initialization function.
+
2002-06-23 James Henstridge <[EMAIL PROTECTED]>
* examples/simple/scribble.py: update example to work with current
Index: pygboxed.c
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/pygboxed.c,v
retrieving revision 1.2
diff -u -p -r1.2 pygboxed.c
--- pygboxed.c 5 Feb 2002 07:13:20 -0000 1.2
+++ pygboxed.c 23 Jun 2002 17:48:27 -0000
@@ -61,6 +61,21 @@ pyg_boxed_free(PyObject *op)
PyObject_FREE(op);
}
+static PyObject *
+pyg_boxed_copy(PyGBoxed *self)
+{
+ return pyg_boxed_new (self->gtype, self->boxed, TRUE, TRUE);
+}
+
+
+
+static PyMethodDef pygboxed_methods[] = {
+ { "copy", (PyCFunction) pyg_boxed_copy, METH_NOARGS },
+ { NULL, NULL, 0 }
+};
+
+
+
PyTypeObject PyGBoxed_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
@@ -91,7 +106,7 @@ PyTypeObject PyGBoxed_Type = {
0, /* tp_weaklistoffset */
(getiterfunc)0, /* tp_iter */
(iternextfunc)0, /* tp_iternext */
- 0, /* tp_methods */
+ pygboxed_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
(PyTypeObject *)0, /* tp_base */
Index: pygobject.c
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/pygobject.c,v
retrieving revision 1.3
diff -u -p -r1.3 pygobject.c
--- pygobject.c 23 Jun 2002 13:56:46 -0000 1.3
+++ pygobject.c 23 Jun 2002 17:48:27 -0000
@@ -229,10 +229,27 @@ pygobject_free(PyObject *op)
/* ---------------- PyGObject methods ----------------- */
+static void
+parameter_list_free (GParameter *parameters, guint n_parameters)
+{
+ gint i;
+ for (i = 0; i < n_parameters; i ++){
+ g_free ((char *)parameters[i].name);
+ g_value_unset (&(parameters[i].value));
+ }
+ g_free (parameters);
+}
+
static int
pygobject_init(PyGObject *self, PyObject *args, PyObject *kwargs)
{
GType object_type;
+ guint n_parameters = 0;
+ GParameter *parameters = NULL;
+ PyObject *key, *item;
+ gint pos = 0;
+ GObjectClass *class;
+ gint retval = 0;
if (!PyArg_ParseTuple(args, ":GObject.__init__", &object_type))
return -1;
@@ -241,7 +258,56 @@ pygobject_init(PyGObject *self, PyObject
if (!object_type)
return -1;
- self->obj = g_object_new(object_type, NULL);
+ if ((class = g_type_class_ref (object_type)) == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "could not get a reference to type class");
+ return -1;
+ }
+
+
+ while (kwargs && PyDict_Next(kwargs, &pos, &key, &item)) {
+ gchar *param_name;
+ GParamSpec *pspec;
+ GValue value = { 0, };
+
+ param_name = PyString_AsString(key);
+ pspec = g_object_class_find_property(class, param_name);
+
+ if (pspec == NULL) {
+ gchar buf[128];
+
+ g_snprintf(buf, sizeof(buf),
+ "Unknown parameter '%s' used in type initialization arguments",
+ param_name);
+ PyErr_SetString(PyExc_AttributeError, buf);
+ parameter_list_free (parameters, n_parameters);
+ g_type_class_unref(class);
+ return -1;
+ }
+ g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(pspec));
+ if (pyg_value_from_pyobject(&value, item) < 0) {
+ PyErr_SetString(PyExc_TypeError,
+ "could not convert argument to correct param type");
+ parameter_list_free (parameters, n_parameters);
+ g_type_class_unref(class);
+ return -1;
+ }
+
+ n_parameters ++;
+ if (parameters == NULL) {
+ parameters = g_new (GParameter, 1);
+ } else {
+ parameters = g_renew (GParameter, parameters, n_parameters);
+ }
+ parameters[n_parameters - 1].name = g_strdup (param_name);
+ parameters[n_parameters - 1].value = value;
+ }
+
+ self->obj = g_object_newv(object_type, n_parameters, parameters);
+ parameter_list_free (parameters, n_parameters);
+
+ g_type_class_unref(class);
+
if (!self->obj) {
PyErr_SetString(PyExc_RuntimeError, "could not create object");
return -1;