comparison finch/libgnt/pygnt/gnttree.override @ 18556:5e1412f4e67a

Do some work to make pygnt more useful. The dbus-gnt script works fairly well now.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 17 Jul 2007 11:09:03 +0000
parents
children 6b16fca71f8b
comparison
equal deleted inserted replaced
18554:ab58b55f38b0 18556:5e1412f4e67a
1 /**
2 * pygnt- Python bindings for the GNT toolkit.
3 * Copyright (C) 2007 Sadrul Habib Chowdhury <sadrul@pidgin.im>
4 *
5 * gnttree.override: overrides for the tree widget.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 */
22 %%
23 headrs
24 #include "common.h"
25 %%
26 ignore
27 gnt_tree_create_row
28 gnt_tree_create_row_from_list
29 %%
30 override gnt_tree_get_selection_text_list noargs
31 static PyObject *
32 _wrap_gnt_tree_get_selection_text_list(PyGObject *self)
33 {
34 GList *list = gnt_tree_get_selection_text_list(GNT_TREE(self->obj));
35 return create_pyobject_from_string_list(list);
36 }
37 %%
38 override gnt_tree_get_rows noargs
39 static PyObject *
40 _wrap_gnt_tree_get_rows(PyGObject *self)
41 {
42 GList *list = gnt_tree_get_rows(GNT_TREE(self->obj));
43 PyObject *py_list;
44 if (list == NULL) {
45 Py_INCREF(Py_None);
46 return Py_None;
47 }
48 if ((py_list = PyList_New(0)) == NULL) {
49 return NULL;
50 }
51 while (list) {
52 PyObject *obj = pyg_pointer_new(G_TYPE_POINTER, list->data);
53 PyList_Append(py_list, obj);
54 Py_DECREF(obj);
55 list = list->next;
56 }
57 return py_list;
58 }
59 %%
60 override gnt_tree_add_row_after
61 static PyObject *
62 _wrap_gnt_tree_add_row_after(PyGObject *self, PyObject *args)
63 {
64 static char *kwlist[] = {"key", "row", "parent", "bigbro", NULL};
65 PyObject *py_list;
66 gpointer key, parent, bigbro;
67 int len, i;
68 GList *list = NULL;
69 GntTreeRow *row;
70
71 if (!PyArg_ParseTuple(args,
72 "OOOO:GntTree.add_row_after",
73 &key,
74 &py_list,
75 &parent,
76 &bigbro))
77 return NULL;
78
79 len = PySequence_Length(py_list);
80 for (i = 0; i < len; i++) {
81 PyObject *item = PySequence_GetItem(py_list, i);
82 if (!pygobject_check(item, &PyString_Type)) {
83 PyErr_SetString(PyExc_TypeError,
84 "column_list members must be strings");
85 Py_DECREF(item);
86 return NULL;
87 }
88 list = g_list_prepend(list, PyString_AsString(item));
89 Py_DECREF(item);
90 }
91
92 list = g_list_reverse(list);
93 row = gnt_tree_create_row_from_list(GNT_TREE(self->obj), list);
94 gnt_tree_add_row_after(GNT_TREE(self->obj),
95 key,
96 row,
97 parent, bigbro);
98 g_list_free(list);
99
100 Py_INCREF(Py_None);
101 return Py_None;
102 }
103