1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3
* Utility functions for Python bindings.
4
* Stolen from Epiphany.
6
* Copyright (C) 2005 Adam Hooper <adamh@cvs.gnome.org>
7
* Copyright (C) 2005 Christian Persch <chpe@cvs.gnome.org>
8
* Copyright (C) 2005 Crispin Flowerday <gnome@flowerday.cx>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2, or (at your option)
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26
#define NO_IMPORT_PYGOBJECT
27
#include "pygobject.h"
28
#include <pygtk/pygtk.h>
30
#include "override_common.h"
33
_helper_wrap_gobject_glist (const GList *list)
38
if ((py_list = PyList_New(0)) == NULL) {
41
for (tmp = list; tmp != NULL; tmp = tmp->next) {
42
PyObject *py_obj = pygobject_new(G_OBJECT(tmp->data));
48
PyList_Append(py_list, py_obj);
55
_helper_wrap_pointer_glist (const GList *list, GType boxed_type)
60
if ((py_list = PyList_New(0)) == NULL) {
63
for (tmp = list; tmp != NULL; tmp = tmp->next) {
64
PyObject *py_obj = pyg_pointer_new(boxed_type, tmp->data);
70
PyList_Append(py_list, py_obj);
77
_helper_wrap_boxed_glist (const GList *list,
85
if ((py_list = PyList_New(0)) == NULL) {
88
for (tmp = list; tmp != NULL; tmp = tmp->next) {
89
PyObject *py_obj = pyg_boxed_new(boxed_type, G_OBJECT(tmp->data), copy_boxed, own_ref);
95
PyList_Append(py_list, py_obj);
102
_helper_wrap_string_glist (const GList *list)
107
if ((py_list = PyList_New(0)) == NULL) {
110
for (tmp = list; tmp != NULL; tmp = tmp->next) {
111
PyObject *str_obj = PyString_FromString ((char*)tmp->data);
113
if (str_obj == NULL) {
117
PyList_Append(py_list, str_obj);
124
_helper_wrap_boxed_gptrarray (GPtrArray *list, GType type, gboolean own_ref, gboolean dealloc)
129
if ((py_list = PyList_New(0)) == NULL) {
132
for( i = 0; i < list->len; i++ ) {
133
PyObject *obj = pyg_boxed_new (type, g_ptr_array_index(list,i), FALSE, own_ref);
134
PyList_Append(py_list, obj);
137
if (dealloc) g_ptr_array_free (list, TRUE);
142
_helper_unwrap_pointer_pylist (PyObject *py_list, GType type)
147
size = PyList_Size (py_list);
148
for (i = 0; i < size; i++) {
152
py_ptr = PyList_GetItem (py_list, i);
153
if (!pyg_pointer_check (py_ptr, type)) {
157
ptr = pyg_pointer_get (py_ptr, void);
158
list = g_list_prepend (list, ptr);
161
list = g_list_reverse (list);
166
_helper_unwrap_string_pylist (PyObject *py_list)
171
size = PyList_Size (py_list);
172
for (i = 0; i < size; i++) {
176
py_str = PyList_GetItem (py_list, i);
177
str = PyString_AsString (py_str);
178
list = g_list_prepend (list, str);
181
list = g_list_reverse (list);