pygtk r3119 - in trunk: . gtk
- From: gianmt svn gnome org
- To: svn-commits-list gnome org
- Subject: pygtk r3119 - in trunk: . gtk
- Date: Wed, 25 Mar 2009 20:57:38 +0000 (UTC)
Author: gianmt
Date: Wed Mar 25 20:57:38 2009
New Revision: 3119
URL: http://svn.gnome.org/viewvc/pygtk?rev=3119&view=rev
Log:
2009-03-25 Gian Mario Tagliaretti <gianmt gnome org>
* gtk/gtkbuilder.override: Wrap gtk_builder_add_objects_from_string
and gtk_builder_add_objects_from_file, add a convenience function
pylist_to_strv which gets a list of strings and returns an array.
Modified:
trunk/ChangeLog
trunk/gtk/gtkbuilder.override
Modified: trunk/gtk/gtkbuilder.override
==============================================================================
--- trunk/gtk/gtkbuilder.override (original)
+++ trunk/gtk/gtkbuilder.override Wed Mar 25 20:57:38 2009
@@ -23,6 +23,59 @@
%%
headers
+static gboolean
+pylist_to_strv (PyObject *list,
+ char ***strvp)
+{
+ int i, len;
+ char **ret;
+
+ *strvp = NULL;
+
+ if (list == Py_None)
+ return TRUE;
+
+ if (!PySequence_Check (list))
+ {
+ PyErr_Format (PyExc_TypeError,
+ "argument must be a list or tuple of strings");
+ return FALSE;
+ }
+
+ if ((len = PySequence_Size (list)) < 0)
+ return FALSE;
+
+ ret = g_new (char*, len + 1);
+ for (i = 0; i <= len; ++i)
+ ret[i] = NULL;
+
+ for (i = 0; i < len; ++i)
+ {
+ PyObject *item = PySequence_GetItem (list, i);
+
+ if (!item)
+ {
+ g_strfreev (ret);
+ return FALSE;
+ }
+
+ if (!PyString_Check (item))
+ {
+ Py_DECREF (item);
+ g_strfreev (ret);
+ PyErr_Format (PyExc_TypeError,
+ "argument must be a list of strings");
+ return FALSE;
+ }
+
+ ret[i] = g_strdup (PyString_AsString (item));
+ Py_DECREF (item);
+ }
+
+ *strvp = ret;
+ return TRUE;
+}
+
typedef struct{
PyObject *obj;
PyObject *data;
@@ -160,3 +213,69 @@
return pyobjects;
}
+
+%%
+override gtk_builder_add_objects_from_file kwargs
+static PyObject *
+_wrap_gtk_builder_add_objects_from_file(PyGObject *self,
+ PyObject *args,
+ PyObject *kwargs)
+{
+ static char *kwlist[] = { "filename", "object_ids", NULL };
+ const gchar *filename;
+ PyObject *py_obj_ids;
+ char **object_ids;
+ guint ret;
+ GError *error = NULL;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "sO:GtkBuilder.add_objects_from_file",
+ kwlist, &filename, &py_obj_ids))
+ return NULL;
+
+ if (!pylist_to_strv (py_obj_ids, &object_ids))
+ return NULL;
+
+ ret = gtk_builder_add_objects_from_file (GTK_BUILDER (self->obj),
+ filename, object_ids, &error);
+ g_strfreev (object_ids);
+
+ if (pyg_error_check(&error))
+ return NULL;
+
+ return PyInt_FromLong(ret);
+}
+
+%%
+override gtk_builder_add_objects_from_string kwargs
+static PyObject *
+_wrap_gtk_builder_add_objects_from_string(PyGObject *self,
+ PyObject *args,
+ PyObject *kwargs)
+{
+ static char *kwlist[] = { "buffer", "object_ids", NULL };
+ const gchar *buffer;
+ gsize lenght = -1;
+ PyObject *py_obj_ids;
+ char **object_ids;
+ guint ret;
+ GError *error = NULL;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "sO:GtkBuilder.add_objects_from_string",
+ kwlist, &buffer, &py_obj_ids))
+ return NULL;
+
+ if (!pylist_to_strv (py_obj_ids, &object_ids))
+ return NULL;
+
+ ret = gtk_builder_add_objects_from_string (GTK_BUILDER (self->obj),
+ buffer, lenght,
+ object_ids, &error);
+ g_strfreev (object_ids);
+
+ if (pyg_error_check(&error))
+ return NULL;
+
+ return PyInt_FromLong(ret);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]