summaryrefslogtreecommitdiff
path: root/gtk/gtkiconview.override
blob: 2057a24412ee98fbb326669dc09d9f3312b15df0 (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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/* -*- Mode: C; c-basic-offset: 4 -*-
 * pygtk- Python bindings for the GTK toolkit.
 * Copyright (C) 2005  John Finlay, Johan Dahlin
 *
 *   gtkiconview.override: overrides for the gtk.IconView object.
 *
 * 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_icon_view_new_with_model
%%
new-constructor GTK_TYPE_ICON_VIEW
%%
override gtk_icon_view_new kwargs
static int
_wrap_gtk_icon_view_new(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "model", NULL };
    PyGObject *pymodel = NULL;
 
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O:GtkIconView.__init__",
				     kwlist, &pymodel))
        return -1;
    if (pymodel == NULL || (PyObject *)pymodel == Py_None)
        pygobject_construct(self, NULL);
    else if (pygobject_check(pymodel, &PyGtkTreeModel_Type))
        pygobject_construct(self, "model", GTK_TREE_MODEL(pymodel->obj), NULL);
    else {
	PyErr_SetString(PyExc_TypeError,
			"model must be a gtk.TreeModel or None");
	return -1;
    }
 
    if (!self->obj) {
        PyErr_SetString(PyExc_RuntimeError,
			"could not create GtkIconView object");
        return -1;
    }
    return 0;
}
%%
override gtk_icon_view_get_selected_items noargs
static PyObject *
_wrap_gtk_icon_view_get_selected_items(PyGObject *self)
{
    GList *paths;
    PyObject *py_paths;
    int plen, i;

    paths = gtk_icon_view_get_selected_items(GTK_ICON_VIEW(self->obj));

    plen = g_list_length(paths);
    if ((py_paths = PyList_New(plen)) == NULL)
        return NULL;
    for (i = 0; i < plen; i++) {
        GtkTreePath *path = (GtkTreePath *)g_list_nth_data(paths, i);
        PyObject *pypath = pygtk_tree_path_to_pyobject(path);
        PyList_SET_ITEM(py_paths, i, pypath);
    }
    g_list_foreach(paths, (GFunc)gtk_tree_path_free, NULL);
    g_list_free(paths);
    return py_paths;
}
%%
override gtk_icon_view_selected_foreach kwargs
static void
pygtk_icon_view_selected_foreach_cb(GtkIconView *iconview,
                                    GtkTreePath *path,
                                    gpointer user_data)
{
    PyGILState_STATE state;
    PyObject *callback, *args, *ret;
 
    state = pyg_gil_state_ensure();
    callback = PyTuple_GetItem((PyObject *)user_data, 0);
    args = Py_BuildValue("(NNO)",
                         pygobject_new((GObject *)iconview),
                         pygtk_tree_path_to_pyobject(path),
                         PyTuple_GetItem((PyObject *)user_data, 1));
    ret = PyObject_CallObject(callback, args);
    if (!ret)
        PyErr_Print();
    Py_XDECREF(ret);
    Py_DECREF(args);
    pyg_gil_state_release(state);
}
static PyObject *
_wrap_gtk_icon_view_selected_foreach(PyGObject *self, PyObject *args,
                                     PyObject *kwargs)
{
    static char *kwlist[] = { "func", "data",  NULL };
    PyObject *func, *data, *py_data = Py_None;
 
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     "O|O:GtkIconView.foreach",
                                     kwlist, &func, &py_data)) {
        return NULL;
    }
    if (!PyCallable_Check(func)) {
        PyErr_SetString(PyExc_TypeError, "func must be callable");
        return NULL;
    }
 
    data = Py_BuildValue("(OO)", func, py_data);
     
    gtk_icon_view_selected_foreach(GTK_ICON_VIEW(self->obj),
                                   pygtk_icon_view_selected_foreach_cb,
                                   (gpointer)data);
    Py_DECREF(data);
    Py_INCREF(Py_None);
    return Py_None;
}
%%
override gtk_icon_view_get_item_at_pos kwargs
static PyObject *
_wrap_gtk_icon_view_get_item_at_pos(PyGObject *self, PyObject *args, 
				    PyObject *kwargs)
{
    static char *kwlist[] = { "x", "y", NULL };
    GtkTreePath *path;
    GtkCellRenderer *renderer;
    gint x,y;
    gboolean r;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     "ii:GtkIconView.get_item_at_pos",
                                     kwlist,
                                     &x, &y))
        return NULL;


    r = gtk_icon_view_get_item_at_pos(GTK_ICON_VIEW(self->obj), x, y, &path, &renderer);
    if (r && path) {
        PyObject *py_path = pygtk_tree_path_to_pyobject(path);
        gtk_tree_path_free(path);
        return Py_BuildValue("(NN)", py_path, pygobject_new((GObject*)renderer));
    }

    Py_INCREF(Py_None);
    return Py_None;
}
%%
override gtk_icon_view_get_visible_range noargs
static PyObject *
_wrap_gtk_icon_view_get_visible_range(PyGObject *self)
{
    GtkTreePath *start_path, *end_path;
    gboolean r;
    
    r = gtk_icon_view_get_visible_range(GTK_ICON_VIEW(self->obj),
					&start_path, &end_path);
    if (r) {
        PyObject *py_start_path = pygtk_tree_path_to_pyobject(start_path);
        PyObject *py_end_path = pygtk_tree_path_to_pyobject(end_path);
        gtk_tree_path_free(start_path);
        gtk_tree_path_free(end_path); 
       return Py_BuildValue("(NN)", py_start_path, py_end_path);
    }

    Py_INCREF(Py_None);
    return Py_None;
}
%%
override gtk_icon_view_get_cursor noargs
static PyObject *
_wrap_gtk_icon_view_get_cursor(PyGObject *self)
{
    GtkTreePath *path;
    GtkCellRenderer *renderer;
    gboolean r;

    r = gtk_icon_view_get_cursor(GTK_ICON_VIEW(self->obj), &path, &renderer);
    if (r && path) {
        PyObject *py_path = pygtk_tree_path_to_pyobject(path);
        gtk_tree_path_free(path);
        return Py_BuildValue("(NN)", py_path, pygobject_new((GObject*)renderer));
    }

    Py_INCREF(Py_None);
    return Py_None;
}
%%
override gtk_icon_view_get_drag_dest_item noargs
static PyObject *
_wrap_gtk_icon_view_get_drag_dest_item(PyGObject *self)
{
    GtkTreePath *path;
    GtkIconViewDropPosition pos;

    gtk_icon_view_get_drag_dest_item(GTK_ICON_VIEW(self->obj), &path, &pos);
    if (path) {
        PyObject *py_path = pygtk_tree_path_to_pyobject(path);
        gtk_tree_path_free(path);
        return Py_BuildValue("(NN)", py_path,
			     pyg_enum_from_gtype(GTK_TYPE_ICON_VIEW_DROP_POSITION, (gint)pos));
    }

    Py_INCREF(Py_None);
    return Py_None;
}
%%
override gtk_icon_view_get_dest_item_at_pos kwargs
static PyObject *
_wrap_gtk_icon_view_get_dest_item_at_pos(PyGObject *self, PyObject *args, 
					 PyObject *kwargs)
{
    static char *kwlist[] = { "x", "y", NULL };
    GtkTreePath *path;
    GtkIconViewDropPosition pos;
    gint drag_x, drag_y;
    gboolean r;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     "ii:GtkIconView.get_dest_item_at_pos",
                                     kwlist, &drag_x, &drag_y))
        return NULL;


    r = gtk_icon_view_get_dest_item_at_pos(GTK_ICON_VIEW(self->obj),
					   drag_x, drag_y, &path, &pos);
    if (r && path) {
        PyObject *py_path = pygtk_tree_path_to_pyobject(path);
        gtk_tree_path_free(path);
        return Py_BuildValue("(NN)", py_path,
			     pyg_enum_from_gtype(GTK_TYPE_ICON_VIEW_DROP_POSITION, (gint) pos));
    }

    Py_INCREF(Py_None);
    return Py_None;
}
%%
override gtk_icon_view_enable_model_drag_source kwargs
static PyObject *
_wrap_gtk_icon_view_enable_model_drag_source(PyGObject *self, PyObject *args,
                                             PyObject *kwargs)
{
    static char *kwlist[] = { "start_button_mask", "targets", "actions", NULL };
    PyObject *py_sbmask, *py_targets, *py_actions;
    GdkModifierType sbmask;
    GtkTargetEntry *targets;
    GdkDragAction actions;
    gint n_targets, i;
 
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     "OOO:GtkIconView.enable_model_drag_source",
                                     kwlist,
                                     &py_sbmask, &py_targets, &py_actions))
        return NULL;
    if (pyg_flags_get_value(GDK_TYPE_MODIFIER_TYPE,
                             py_sbmask, (gint *)&sbmask))
        return NULL;
    if (pyg_flags_get_value(GDK_TYPE_DRAG_ACTION,
                             py_actions, (gint *)&actions))
        return NULL;
    if (!PySequence_Check(py_targets)) {
        PyErr_SetString(PyExc_TypeError, "targets must be a sequence");
        return NULL;
    }
    n_targets = PySequence_Length(py_targets);
    targets = g_new(GtkTargetEntry, n_targets);
    for (i = 0; i < n_targets; i++) {
        PyObject *item = PySequence_GetItem(py_targets, i);
        Py_DECREF(item);
        if (!PyArg_ParseTuple(item, "zii", &targets[i].target,
                              &targets[i].flags, &targets[i].info)) {
            PyErr_Clear();
            PyErr_SetString(PyExc_TypeError,
                            "list items should be of form (string,int,int)");
            g_free(targets);
            return NULL;
        }
    }
    gtk_icon_view_enable_model_drag_source(GTK_ICON_VIEW(self->obj),
                                           sbmask, targets, n_targets, actions);
    g_free(targets);
    Py_INCREF(Py_None);
    return Py_None;
}
%%
override gtk_icon_view_enable_model_drag_dest kwargs
static PyObject *
_wrap_gtk_icon_view_enable_model_drag_dest(PyGObject *self, PyObject *args,
                                           PyObject *kwargs)
{
    static char *kwlist[] = { "targets", "actions", NULL };
    PyObject *py_targets, *py_actions;
    GtkTargetEntry *targets;
    GdkDragAction actions;
    gint n_targets, i;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     "OO:GtkIconView.enable_model_drag_dest",
                                     kwlist,
                                     &py_targets, &py_actions))
        return NULL;
    if (pyg_flags_get_value(GDK_TYPE_DRAG_ACTION,
                             py_actions, (gint *)&actions))
        return NULL;
    if (!PySequence_Check(py_targets)) {
        PyErr_SetString(PyExc_TypeError, "targets must be a sequence");
        return NULL;
    }
    n_targets = PySequence_Length(py_targets);
    targets = g_new(GtkTargetEntry, n_targets);
    for (i = 0; i < n_targets; i++) {
        PyObject *item = PySequence_GetItem(py_targets, i);
        Py_DECREF(item);
        if (!PyArg_ParseTuple(item, "zii", &targets[i].target,
                              &targets[i].flags, &targets[i].info)) {
            PyErr_Clear();
            PyErr_SetString(PyExc_TypeError,
                            "list items should be of form (string,int,int)");
            g_free(targets);
            return NULL;
        }
    }
    gtk_icon_view_enable_model_drag_dest(GTK_ICON_VIEW(self->obj),
                                         targets, n_targets, actions);
    g_free(targets);
    Py_INCREF(Py_None);
    return Py_None;
}
%%
override gtk_icon_view_get_tooltip_context kwargs
static PyObject *
_wrap_gtk_icon_view_get_tooltip_context(PyGObject *self,
                                        PyObject *args,
                                        PyObject *kwargs)
{
    static char *kwlist[] = { "x", "y", "keyboard_tip", NULL };
    
    gboolean        ret;
    PyObject        *py_ret = Py_None, *py_keyboard_tip = Py_True;
    gint            x, y;
    GtkTreeModel    *tree_model;
    GtkTreePath     *path;
    GtkTreeIter     iter;
    
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                        "iiO:GtkIconView.get_tooltip_context",
                        kwlist, &x, &y, &py_keyboard_tip))
        return NULL;
    
    ret = gtk_icon_view_get_tooltip_context(GTK_ICON_VIEW(self->obj), &x, &y,
                                            PyObject_IsTrue(py_keyboard_tip),
                                            &tree_model,
                                            &path, &iter);
    if (ret) {
        py_ret = Py_BuildValue("(NNN)",
                               pygobject_new((GObject *)tree_model),
                               pygtk_tree_path_to_pyobject(path),
                               pyg_boxed_new(GTK_TYPE_TREE_ITER, &iter,
                                             TRUE, TRUE));

        gtk_tree_path_free(path);
        return py_ret;
    }
    Py_INCREF(py_ret);    
    return py_ret;
}
%%
override gtk_icon_view_convert_widget_to_bin_window_coords kwargs
static PyObject*
_wrap_gtk_icon_view_convert_widget_to_bin_window_coords(PyGObject *self,
                                                        PyObject *args,
                                                        PyObject *kwargs)
{
    static char *kwlist[] = { "widget_x", "widget_y", NULL };
    gint widget_x, widget_y, window_x = 0, window_y = 0;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                        "ii:GtkIconView.convert_widget_to_bin_window_coords",
                        kwlist, &widget_x, &widget_y))
        return NULL;
    
    gtk_icon_view_convert_widget_to_bin_window_coords(GTK_ICON_VIEW(self->obj),
                                          widget_x, widget_y,
                                          &window_x, &window_y);
    
    return Py_BuildValue("(ii)", window_x, window_y);
}