summaryrefslogtreecommitdiff
path: root/gtk/gtkclist.override
blob: 9be0744e8c7f0953f3644b27345264318ab7ba32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/* -*- Mode: C; c-basic-offset: 4 -*-
 * pygtk- Python bindings for the GTK toolkit.
 * Copyright (C) 1998-2003  James Henstridge
 *
 *   gtkclist.override: overrides for the gtk.CList type.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 * USA
 */
%%
ignore 
  gtk_clist_new
  gtk_clist_set_row_data_full
  gtk_clist_set_compare_func
%%
override gtk_clist_new_with_titles kwargs
static int
_wrap_gtk_clist_new_with_titles(PyGObject *self, PyObject *args,
                                PyObject *kwargs)
{
    static char *kwlist[] = { "count", "titles", NULL };
    int count = 1, i;
    PyObject *py_list = NULL;

    if (PyErr_Warn(PyExc_DeprecationWarning, "use gtk.TreeView") < 0)
        return -1;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO:GtkCList.__init__",
                                     kwlist, &count, &py_list))
        return -1;
    if (py_list) {
        gchar **list;

        if (!PySequence_Check(py_list)) {
            PyErr_SetString(PyExc_TypeError,"2nd argument not a sequence");
            return -1;
        }
        if (PySequence_Length(py_list) < count) {
            PyErr_SetString(PyExc_TypeError, "sequence not long enough");
            return -1;
        }
        list = g_new(gchar *, count);
        for (i = 0; i < count; i++) {
            PyObject *item = PySequence_GetItem(py_list, i);

            Py_DECREF(item); /* PySequence_GetItem INCREF's */
            if (!PyString_Check(item) && !PyUnicode_Check(item)) {
                PyErr_SetString(PyExc_TypeError,
                                "sequence item not a string or unicode object");
                g_free(list);
                return -1;
            }
            list[i] = PyString_AsString(item);
        }
        self->obj = (GObject *)gtk_clist_new_with_titles(count, list);
        g_free(list);
    } else
        self->obj = (GObject *)gtk_clist_new(count);
    if (!self->obj) {
        PyErr_SetString(PyExc_RuntimeError,"could not create GtkCList object");
        return -1;
    }
    pygobject_register_wrapper((PyObject *)self);
    return 0;
}
%%
override gtk_clist_get_text kwargs
static PyObject *
_wrap_gtk_clist_get_text(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "row", "column", NULL };
    int r, c;
    char *text = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:GtkCList.get_text",
                                     kwlist, &r, &c))
        return NULL;
    if (!gtk_clist_get_text(GTK_CLIST(self->obj), r, c, &text) || text==NULL) {
        PyErr_SetString(PyExc_ValueError, "can't get text value");
        return NULL;
    }
    return PyString_FromString(text);
}
%%
override gtk_clist_get_pixmap kwargs
static PyObject *
_wrap_gtk_clist_get_pixmap(PyGObject *self, PyObject *args, PyObject*kwargs)
{
    static char *kwlist[] = { "row", "column", NULL };
    int r, c;
    GdkPixmap *pixmap;
    GdkBitmap *mask;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:GtkCList.get_pixmap",
                                     kwlist, &r, &c))
        return NULL;
    if (!gtk_clist_get_pixmap(GTK_CLIST(self->obj), r, c,
                              &pixmap, &mask)) {
        PyErr_SetString(PyExc_ValueError, "can't get pixmap value");
        return NULL;
    }
    return Py_BuildValue("(NN)", pygobject_new((GObject *)pixmap),
                         pygobject_new((GObject *)mask));
}
%%
override gtk_clist_get_pixtext kwargs
static PyObject *
_wrap_gtk_clist_get_pixtext(PyGObject *self, PyObject *args, PyObject*kwargs)
{
    static char *kwlist[] = { "row", "column", NULL };
    int r, c;
    gchar *text;
    guint8 spacing;
    GdkPixmap *pixmap;
    GdkBitmap *mask;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:GtkCList.get_pixtext",
                                     kwlist, &r, &c))
        return NULL;
    if (!gtk_clist_get_pixtext(GTK_CLIST(self->obj), r, c,
                              &text, &spacing, &pixmap, &mask)) {
        PyErr_SetString(PyExc_ValueError, "can't get pixtext value");
        return NULL;
    }
    return Py_BuildValue("(ziNN)", text, (gint)spacing,
                         pygobject_new((GObject *)pixmap),
                         pygobject_new((GObject *)mask));
}
%%
override gtk_clist_prepend kwargs
static PyObject *
_wrap_gtk_clist_prepend(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "text", NULL };
    int col, i;
    PyObject *py_list;
    gchar **list;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GtkCList.prepend",
                                     kwlist, &py_list))
        return NULL;
    if (!PySequence_Check(py_list)) {
        PyErr_SetString(PyExc_TypeError, "argument not a sequence");
        return NULL;
    }
    col = GTK_CLIST(self->obj)->columns;
    if (PySequence_Length(py_list) < col) {
        PyErr_SetString(PyExc_TypeError, "sequence too short");
        return NULL;
    }
    list = g_new(gchar *, col);
    for (i = 0; i < col; i++) {
        PyObject *item = PySequence_GetItem(py_list, i);

        Py_DECREF(item);
        if (!PyString_Check(item) && !PyUnicode_Check(item)) {
            PyErr_SetString(PyExc_TypeError,
                            "sequence item not a string or unicode object");
            g_free(list);
            return NULL;
        }
        list[i] = PyString_AsString(item);
    }
    i = gtk_clist_prepend(GTK_CLIST(self->obj), list);
    g_free(list);
    return PyInt_FromLong(i);
}
%%
override gtk_clist_append kwargs
static PyObject *
_wrap_gtk_clist_append(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "text", NULL };
    int col, i;
    PyObject *py_list;
    gchar **list;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GtkCList.append",
                                     kwlist, &py_list))
        return NULL;
    if (!PySequence_Check(py_list)) {
        PyErr_SetString(PyExc_TypeError, "argument not a sequence");
        return NULL;
    }
    col = GTK_CLIST(self->obj)->columns;
    if (PySequence_Length(py_list) < col) {
        PyErr_SetString(PyExc_TypeError, "sequence too short");
        return NULL;
    }
    list = g_new(gchar *, col);
    for (i = 0; i < col; i++) {
        PyObject *item = PySequence_GetItem(py_list, i);

        Py_DECREF(item);
        if (!PyString_Check(item) && !PyUnicode_Check(item)) {
            PyErr_SetString(PyExc_TypeError,
                            "sequence item not a string or unicode object");
            g_free(list);
            return NULL;
        }
        list[i] = PyString_AsString(item);
    }
    i = gtk_clist_append(GTK_CLIST(self->obj), list);
    g_free(list);
    return PyInt_FromLong(i);
}
%%
override gtk_clist_insert kwargs
static PyObject *
_wrap_gtk_clist_insert(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "row", "text", NULL };
    int col, row, i;
    PyObject *py_list;
    gchar **list;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO:GtkCList.insert",
                                     kwlist, &row, &py_list))
        return NULL;
    if (!PySequence_Check(py_list)) {
        PyErr_SetString(PyExc_TypeError, "argument not a sequence");
        return NULL;
    }
    col = GTK_CLIST(self->obj)->columns;
    if (PySequence_Length(py_list) < col) {
        PyErr_SetString(PyExc_TypeError, "sequence too short");
        return NULL;
    }
    list = g_new(gchar *, col);
    for (i = 0; i < col; i++) {
        PyObject *item = PySequence_GetItem(py_list, i);

        Py_DECREF(item);
        if (!PyString_Check(item) && !PyUnicode_Check(item)) {
            PyErr_SetString(PyExc_TypeError,
                            "sequence item not a string or unicode object");
            g_free(list);
            return NULL;
        }
        list[i] = PyString_AsString(item);
    }
    i = gtk_clist_insert(GTK_CLIST(self->obj), row, list);
    g_free(list);
    return PyInt_FromLong(i);
}
%%
override gtk_clist_set_row_data kwargs
static PyObject *
_wrap_gtk_clist_set_row_data(PyGObject *self, PyObject *args,
                             PyObject *kwargs)
{
    static char *kwlist[] = { "row", "data", NULL };
    int row;
    PyObject *data;
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO:GtkCList.set_row_data",
                                     kwlist, &row, &data))
        return NULL;
    Py_INCREF(data);
    gtk_clist_set_row_data_full(GTK_CLIST(self->obj), row, data,
                                (GtkDestroyNotify)pyg_destroy_notify);
    Py_INCREF(Py_None);
    return Py_None;
}
%%
override gtk_clist_get_row_data kwargs
static PyObject *
_wrap_gtk_clist_get_row_data(PyGObject *self, PyObject *args,
                             PyObject *kwargs)
{
    static char *kwlist[] = { "row", NULL };
    PyObject *ret;
    int row;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:GtkCList.get_row_data",
                                     kwlist, &row))
        return NULL;
    ret = gtk_clist_get_row_data(GTK_CLIST(self->obj), row);
    if (!ret) ret = Py_None;
    Py_INCREF(ret);
    return ret;
}
%%
override gtk_clist_find_row_from_data kwargs
static PyObject *
_wrap_gtk_clist_find_row_from_data(PyGObject *self, PyObject *args,
                                   PyObject *kwargs)
{
    static char *kwlist[] = { "data", NULL };
    PyObject *data;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     "O:GtkCList.find_row_from_data", kwlist,
                                     &data))
        return NULL;
    return PyInt_FromLong(gtk_clist_find_row_from_data(
                                GTK_CLIST(self->obj), data));
}
%%
override gtk_clist_get_selection_info kwargs
static PyObject *
_wrap_gtk_clist_get_selection_info(PyGObject *self, PyObject *args,
                                   PyObject *kwargs)
{
    static char *kwlist[] = { "x", "y", NULL };
    gint x, y, row, column;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     "ii:GtkCList.get_selection_info", kwlist,
                                     &x, &y))
        return NULL;
    if (gtk_clist_get_selection_info(GTK_CLIST(self->obj), x, y,
                                     &row, &column))
        return Py_BuildValue("(ii)", row, column);
    else {
        Py_INCREF(Py_None);
        return Py_None;
    }
}
%%
override-attr GtkCList.selection
static PyObject *
_wrap_gtk_clist__get_selection(PyGObject *self, void *closure)
{
    guint row;
    GList *selection;
    PyObject *py_int, *ret = PyList_New(0);

    if (ret == NULL)
        return NULL;

    for (selection = GTK_CLIST(self->obj)->selection; selection != NULL;
         selection = selection->next) {
        row = GPOINTER_TO_UINT(selection->data);

        py_int = PyInt_FromLong(row);

        if (!py_int) {
            Py_DECREF(ret);
            return NULL;
        }

        PyList_Append(ret, py_int);
        Py_DECREF(py_int);
    }
    return ret;

}