~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/pygimp/gimpui.override

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
headers
 
3
#include <Python.h>
 
4
 
 
5
#define NO_IMPORT_PYGOBJECT
 
6
#include <pygobject.h>
 
7
 
 
8
#include <libgimp/gimp.h>
 
9
#include <libgimp/gimpui.h>
 
10
 
 
11
#define NO_IMPORT_PYGIMP
 
12
#include "pygimp-api.h"
 
13
 
 
14
#define NO_IMPORT_PYGIMPCOLOR
 
15
#include "pygimpcolor-api.h"
 
16
 
 
17
typedef struct {
 
18
    PyObject *constraint;
 
19
    PyObject *user_data;
 
20
} PyGimpConstraintData;
 
21
%%
 
22
modulename gimpui
 
23
%%
 
24
import gobject.GObject as PyGObject_Type
 
25
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
 
26
import gtk.Object as PyGtkObject_Type
 
27
import gtk.Widget as PyGtkWidget_Type
 
28
import gtk.Dialog as PyGtkDialog_Type
 
29
import gtk.Window as PyGtkWindow_Type
 
30
import gtk.Label as PyGtkLabel_Type
 
31
import gtk.Button as PyGtkButton_Type
 
32
import gtk.ToggleButton as PyGtkToggleButton_Type
 
33
import gtk.RadioButton as PyGtkRadioButton_Type
 
34
import gtk.SpinButton as PyGtkSpinButton_Type
 
35
import gtk.Entry as PyGtkEntry_Type
 
36
import gtk.DrawingArea as PyGtkDrawingArea_Type
 
37
import gtk.Table as PyGtkTable_Type
 
38
import gtk.Frame as PyGtkFrame_Type
 
39
import gtk.HBox as PyGtkHBox_Type
 
40
import gtk.VBox as PyGtkVBox_Type
 
41
import gtk.HPaned as PyGtkHPaned_Type
 
42
import gtk.VPaned as PyGtkVPaned_Type
 
43
import gtk.Scale as PyGtkScale_Type
 
44
import gtk.ProgressBar as PyGtkProgressBar_Type
 
45
import gtk.OptionMenu as PyGtkOptionMenu_Type
 
46
import gtk.ComboBox as PyGtkComboBox_Type
 
47
import gtk.ListStore as PyGtkListStore_Type
 
48
import gtk.TreeModel as PyGtkTreeModel_Type
 
49
import gtk.CellRenderer as PyGtkCellRenderer_Type
 
50
import gtk.CellRendererToggle as PyGtkCellRendererToggle_Type
 
51
%%
 
52
ignore
 
53
  gimp_dialog_add_buttons
 
54
%%
 
55
ignore-glob
 
56
  *_get_type
 
57
  *_valist
 
58
  gimp_resolution_*
 
59
%%
 
60
override gimp_drawable_combo_box_new kwargs
 
61
static gboolean
 
62
pygimp_drawable_constraint_marshal(gint32 image_id, gint32 drawable_id,
 
63
                                   gpointer user_data)
 
64
{
 
65
    PyObject *img, *drw, *ret;
 
66
    gboolean res;
 
67
    PyGimpConstraintData *data = user_data;
 
68
 
 
69
    img = pygimp_image_new(image_id);
 
70
    if (!img) {
 
71
        PyErr_Print();
 
72
        return FALSE;
 
73
    }
 
74
 
 
75
    drw = pygimp_drawable_new(NULL, drawable_id);
 
76
    if (!drw) {
 
77
        PyErr_Print();
 
78
        Py_DECREF(img);
 
79
        return FALSE;
 
80
    }
 
81
 
 
82
    if (data->user_data && data->user_data != Py_None)
 
83
        ret = PyObject_CallFunctionObjArgs(data->constraint, img, drw,
 
84
                                           data->user_data, NULL);
 
85
    else
 
86
        ret = PyObject_CallFunctionObjArgs(data->constraint, img, drw, NULL);
 
87
 
 
88
    if (!ret) {
 
89
        PyErr_Print();
 
90
        res = FALSE;
 
91
    } else {
 
92
        res = PyObject_IsTrue(ret);
 
93
        Py_DECREF(ret);
 
94
    }
 
95
 
 
96
    Py_DECREF(drw);
 
97
    Py_DECREF(img);
 
98
 
 
99
    return res;
 
100
}
 
101
 
 
102
static int
 
103
_wrap_gimp_drawable_combo_box_new(PyGObject *self, PyObject *args,
 
104
                                  PyObject *kwargs)
 
105
{
 
106
    PyObject *constraint = NULL, *user_data = NULL;
 
107
    GimpDrawableConstraintFunc func = NULL;
 
108
    PyGimpConstraintData *data = NULL;
 
109
 
 
110
    static char *kwlist[] = { "constraint", "data", NULL };
 
111
 
 
112
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
113
                                     "|OO:gimpui.DrawableComboBox.__init__",
 
114
                                     kwlist,
 
115
                                     &constraint, &user_data))
 
116
        return -1;
 
117
 
 
118
    if (constraint && constraint != Py_None) {
 
119
        if (!PyCallable_Check(constraint)) {
 
120
            PyErr_SetString(PyExc_TypeError, "first arg must be callable");
 
121
            return -1;
 
122
        }
 
123
 
 
124
        data = g_new(PyGimpConstraintData, 1);
 
125
 
 
126
        data->constraint = constraint;
 
127
        Py_XINCREF(constraint);
 
128
 
 
129
        data->user_data = user_data;
 
130
        Py_XINCREF(user_data);
 
131
 
 
132
        func = pygimp_drawable_constraint_marshal;
 
133
    }
 
134
 
 
135
    self->obj = (GObject *)gimp_drawable_combo_box_new(func, data);
 
136
 
 
137
    Py_XDECREF(constraint);
 
138
    Py_XDECREF(user_data);
 
139
    g_free(data);
 
140
 
 
141
    if (pyg_type_from_object((PyObject *)self) != GIMP_TYPE_DRAWABLE_COMBO_BOX) {
 
142
        PyErr_SetString(PyExc_RuntimeError, "__gobject_init__ must be used "
 
143
                        "when subclassing gimpui.DrawableComboBox");
 
144
        return -1;
 
145
    }
 
146
 
 
147
    pygobject_register_wrapper((PyObject *)self);
 
148
    return 0;
 
149
}
 
150
%%
 
151
define GimpDrawableComboBox.set_active_drawable kwargs
 
152
static PyObject *
 
153
_wrap_gimp_drawable_combo_box_set_active_drawable(PyGObject *self, PyObject *args, PyObject *kwargs)
 
154
{
 
155
    PyGimpDrawable *drw;
 
156
 
 
157
    static char *kwlist[] = { "drawable", NULL };
 
158
 
 
159
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, 
 
160
                                     "O!:GimpDrawableComboBox.set_active_drawable",
 
161
                                     kwlist,
 
162
                                     PyGimpDrawable_Type, &drw))
 
163
        return NULL;
 
164
 
 
165
    if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), drw->ID)) {
 
166
        PyErr_Format(pygimp_error,
 
167
                     "Drawable (ID %d) does not exist in GimpDrawableComboBox",
 
168
                     drw->ID);
 
169
        return NULL;
 
170
    }
 
171
 
 
172
    Py_INCREF(Py_None);
 
173
    return Py_None;
 
174
}
 
175
%%
 
176
define GimpDrawableComboBox.get_active_drawable noargs
 
177
static PyObject *
 
178
_wrap_gimp_drawable_combo_box_get_active_drawable(PyGObject *self)
 
179
{
 
180
    int value;
 
181
 
 
182
    if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
 
183
        return pygimp_drawable_new(NULL, value);
 
184
 
 
185
    Py_INCREF(Py_None);
 
186
    return Py_None;
 
187
}
 
188
%%
 
189
override gimp_channel_combo_box_new kwargs
 
190
static gboolean
 
191
pygimp_channel_constraint_marshal(gint32 image_id, gint32 channel_id,
 
192
                                  gpointer user_data)
 
193
{
 
194
    PyObject *img, *chn, *ret;
 
195
    gboolean res;
 
196
    PyGimpConstraintData *data = user_data;
 
197
 
 
198
    img = pygimp_image_new(image_id);
 
199
    if (!img) {
 
200
        PyErr_Print();
 
201
        return FALSE;
 
202
    }
 
203
 
 
204
    chn = pygimp_channel_new(channel_id);
 
205
    if (!chn) {
 
206
        PyErr_Print();
 
207
        Py_DECREF(img);
 
208
        return FALSE;
 
209
    }
 
210
 
 
211
    if (data->user_data && data->user_data != Py_None)
 
212
        ret = PyObject_CallFunctionObjArgs(data->constraint, img, chn,
 
213
                                           data->user_data, NULL);
 
214
    else
 
215
        ret = PyObject_CallFunctionObjArgs(data->constraint, img, chn, NULL);
 
216
 
 
217
    if (!ret) {
 
218
        PyErr_Print();
 
219
        res = FALSE;
 
220
    } else {
 
221
        res = PyObject_IsTrue(ret);
 
222
        Py_DECREF(ret);
 
223
    }
 
224
 
 
225
    Py_DECREF(chn);
 
226
    Py_DECREF(img);
 
227
 
 
228
    return res;
 
229
}
 
230
 
 
231
static int
 
232
_wrap_gimp_channel_combo_box_new(PyGObject *self, PyObject *args,
 
233
                                 PyObject *kwargs)
 
234
{
 
235
    PyObject *constraint = NULL, *user_data = NULL;
 
236
    GimpDrawableConstraintFunc func = NULL;
 
237
    PyGimpConstraintData *data = NULL;
 
238
 
 
239
    static char *kwlist[] = { "constraint", "data", NULL };
 
240
 
 
241
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
242
                                     "|OO:gimpui.ChannelComboBox.__init__",
 
243
                                     kwlist,
 
244
                                     &constraint, &user_data))
 
245
        return -1;
 
246
 
 
247
    if (constraint && constraint != Py_None) {
 
248
        if (!PyCallable_Check(constraint)) {
 
249
            PyErr_SetString(PyExc_TypeError, "first arg must be callable");
 
250
            return -1;
 
251
        }
 
252
 
 
253
        data = g_new(PyGimpConstraintData, 1);
 
254
 
 
255
        data->constraint = constraint;
 
256
        Py_INCREF(constraint);
 
257
 
 
258
        data->user_data = user_data;
 
259
        Py_XINCREF(user_data);
 
260
 
 
261
        func = pygimp_channel_constraint_marshal;
 
262
    }
 
263
 
 
264
    self->obj = (GObject *)gimp_channel_combo_box_new(func, data);
 
265
 
 
266
    Py_XDECREF(constraint);
 
267
    Py_XDECREF(user_data);
 
268
    g_free(data);
 
269
 
 
270
    if (pyg_type_from_object((PyObject *)self) != GIMP_TYPE_CHANNEL_COMBO_BOX) {
 
271
        PyErr_SetString(PyExc_RuntimeError, "__gobject_init__ must be used "
 
272
                        "when subclassing gimpui.ChannelComboBox");
 
273
        return -1;
 
274
    }
 
275
 
 
276
    pygobject_register_wrapper((PyObject *)self);
 
277
    return 0;
 
278
}
 
279
%%
 
280
define GimpChannelComboBox.set_active_channel kwargs
 
281
static PyObject *
 
282
_wrap_gimp_channel_combo_box_set_active_channel(PyGObject *self, PyObject *args, PyObject *kwargs)
 
283
{
 
284
    PyGimpChannel *chn;
 
285
 
 
286
    static char *kwlist[] = { "channel", NULL };
 
287
 
 
288
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, 
 
289
                                     "O!:GimpChannelComboBox.set_active_channel",
 
290
                                     kwlist,
 
291
                                     PyGimpChannel_Type, &chn))
 
292
        return NULL;
 
293
 
 
294
    if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), chn->ID)) {
 
295
        PyErr_Format(pygimp_error,
 
296
                     "Channel (ID %d) does not exist in GimpChannelComboBox",
 
297
                     chn->ID);
 
298
        return NULL;
 
299
    }
 
300
 
 
301
    Py_INCREF(Py_None);
 
302
    return Py_None;
 
303
}
 
304
%%
 
305
define GimpChannelComboBox.get_active_channel noargs
 
306
static PyObject *
 
307
_wrap_gimp_channel_combo_box_get_active_channel(PyGObject *self)
 
308
{
 
309
    int value;
 
310
 
 
311
    if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
 
312
        return pygimp_channel_new(value);
 
313
 
 
314
    Py_INCREF(Py_None);
 
315
    return Py_None;
 
316
}
 
317
%%
 
318
override gimp_layer_combo_box_new kwargs
 
319
static gboolean
 
320
pygimp_layer_constraint_marshal(gint32 image_id, gint32 layer_id,
 
321
                                gpointer user_data)
 
322
{
 
323
    PyObject *img, *lay, *ret;
 
324
    gboolean res;
 
325
    PyGimpConstraintData *data = user_data;
 
326
 
 
327
    img = pygimp_image_new(image_id);
 
328
    if (!img) {
 
329
        PyErr_Print();
 
330
        return FALSE;
 
331
    }
 
332
 
 
333
    lay = pygimp_layer_new(layer_id);
 
334
    if (!lay) {
 
335
        PyErr_Print();
 
336
        Py_DECREF(img);
 
337
        return FALSE;
 
338
    }
 
339
 
 
340
    if (data->user_data && data->user_data != Py_None)
 
341
        ret = PyObject_CallFunctionObjArgs(data->constraint, img, lay,
 
342
                                           data->user_data, NULL);
 
343
    else
 
344
        ret = PyObject_CallFunctionObjArgs(data->constraint, img, lay, NULL);
 
345
 
 
346
    if (!ret) {
 
347
        PyErr_Print();
 
348
        res = FALSE;
 
349
    } else {
 
350
        res = PyObject_IsTrue(ret);
 
351
        Py_DECREF(ret);
 
352
    }
 
353
 
 
354
    Py_DECREF(lay);
 
355
    Py_DECREF(img);
 
356
 
 
357
    return res;
 
358
}
 
359
 
 
360
static int
 
361
_wrap_gimp_layer_combo_box_new(PyGObject *self, PyObject *args,
 
362
                               PyObject *kwargs)
 
363
{
 
364
    PyObject *constraint = NULL, *user_data = NULL;
 
365
    GimpDrawableConstraintFunc func = NULL;
 
366
    PyGimpConstraintData *data = NULL;
 
367
 
 
368
    static char *kwlist[] = { "constraint", "data", NULL };
 
369
 
 
370
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
371
                                     "|OO:gimpui.LayerComboBox.__init__",
 
372
                                     kwlist,
 
373
                                     &constraint, &user_data))
 
374
        return -1;
 
375
 
 
376
    if (constraint && constraint != Py_None) {
 
377
        if (!PyCallable_Check(constraint)) {
 
378
            PyErr_SetString(PyExc_TypeError, "first arg must be callable");
 
379
            return -1;
 
380
        }
 
381
 
 
382
        data = g_new(PyGimpConstraintData, 1);
 
383
 
 
384
        data->constraint = constraint;
 
385
        Py_INCREF(constraint);
 
386
 
 
387
        data->user_data = user_data;
 
388
        Py_XINCREF(user_data);
 
389
 
 
390
        func = pygimp_layer_constraint_marshal;
 
391
    }
 
392
 
 
393
    self->obj = (GObject *)gimp_layer_combo_box_new(func, data);
 
394
 
 
395
    Py_XDECREF(constraint);
 
396
    Py_XDECREF(user_data);
 
397
    g_free(data);
 
398
 
 
399
    if (pyg_type_from_object((PyObject *)self) != GIMP_TYPE_LAYER_COMBO_BOX) {
 
400
        PyErr_SetString(PyExc_RuntimeError, "__gobject_init__ must be used "
 
401
                        "when subclassing gimpui.LayerComboBox");
 
402
        return -1;
 
403
    }
 
404
 
 
405
    pygobject_register_wrapper((PyObject *)self);
 
406
    return 0;
 
407
}
 
408
%%
 
409
define GimpLayerComboBox.set_active_layer kwargs
 
410
static PyObject *
 
411
_wrap_gimp_layer_combo_box_set_active_layer(PyGObject *self, PyObject *args, PyObject *kwargs)
 
412
{
 
413
    PyGimpLayer *lay;
 
414
 
 
415
    static char *kwlist[] = { "layer", NULL };
 
416
 
 
417
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, 
 
418
                                     "O!:GimpLayerComboBox.set_active_layer",
 
419
                                     kwlist,
 
420
                                     PyGimpLayer_Type, &lay))
 
421
        return NULL;
 
422
 
 
423
    if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), lay->ID)) {
 
424
        PyErr_Format(pygimp_error,
 
425
                     "Layer (ID %d) does not exist in GimpLayerComboBox",
 
426
                     lay->ID);
 
427
        return NULL;
 
428
    }
 
429
 
 
430
    Py_INCREF(Py_None);
 
431
    return Py_None;
 
432
}
 
433
%%
 
434
define GimpLayerComboBox.get_active_layer noargs
 
435
static PyObject *
 
436
_wrap_gimp_layer_combo_box_get_active_layer(PyGObject *self)
 
437
{
 
438
    int value;
 
439
 
 
440
    if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
 
441
        return pygimp_layer_new(value);
 
442
 
 
443
    Py_INCREF(Py_None);
 
444
    return Py_None;
 
445
}
 
446
%%
 
447
override gimp_vectors_combo_box_new kwargs
 
448
static gboolean
 
449
pygimp_vectors_constraint_marshal(gint32 image_id, gint32 vectors_id,
 
450
                                  gpointer user_data)
 
451
{
 
452
    PyObject *img, *vect, *ret;
 
453
    gboolean res;
 
454
    PyGimpConstraintData *data = user_data;
 
455
 
 
456
    img = pygimp_image_new(image_id);
 
457
    if (!img) {
 
458
        PyErr_Print();
 
459
        return FALSE;
 
460
    }
 
461
 
 
462
    vect = pygimp_vectors_new(vectors_id);
 
463
    if (!vect) {
 
464
        PyErr_Print();
 
465
        Py_DECREF(img);
 
466
        return FALSE;
 
467
    }
 
468
 
 
469
    if (data->user_data && data->user_data != Py_None)
 
470
        ret = PyObject_CallFunctionObjArgs(data->constraint, img, vect,
 
471
                                           data->user_data, NULL);
 
472
    else
 
473
        ret = PyObject_CallFunctionObjArgs(data->constraint, img, vect, NULL);
 
474
 
 
475
    if (!ret) {
 
476
        PyErr_Print();
 
477
        res = FALSE;
 
478
    } else {
 
479
        res = PyObject_IsTrue(ret);
 
480
        Py_DECREF(ret);
 
481
    }
 
482
 
 
483
    Py_DECREF(vect);
 
484
    Py_DECREF(img);
 
485
 
 
486
    return res;
 
487
}
 
488
 
 
489
static int
 
490
_wrap_gimp_vectors_combo_box_new(PyGObject *self, PyObject *args,
 
491
                                 PyObject *kwargs)
 
492
{
 
493
    PyObject *constraint = NULL, *user_data = NULL;
 
494
    GimpVectorsConstraintFunc func = NULL;
 
495
    PyGimpConstraintData *data = NULL;
 
496
 
 
497
    static char *kwlist[] = { "constraint", "data", NULL };
 
498
 
 
499
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
500
                                     "|OO:gimpui.VectorsComboBox.__init__",
 
501
                                     kwlist,
 
502
                                     &constraint, &user_data))
 
503
        return -1;
 
504
 
 
505
    if (constraint && constraint != Py_None) {
 
506
        if (!PyCallable_Check(constraint)) {
 
507
            PyErr_SetString(PyExc_TypeError, "first arg must be callable");
 
508
            return -1;
 
509
        }
 
510
 
 
511
        data = g_new(PyGimpConstraintData, 1);
 
512
 
 
513
        data->constraint = constraint;
 
514
        Py_INCREF(constraint);
 
515
 
 
516
        data->user_data = user_data;
 
517
        Py_XINCREF(user_data);
 
518
 
 
519
        func = pygimp_vectors_constraint_marshal;
 
520
    }
 
521
 
 
522
    self->obj = (GObject *)gimp_vectors_combo_box_new(func, data);
 
523
 
 
524
    Py_XDECREF(constraint);
 
525
    Py_XDECREF(user_data);
 
526
    g_free(data);
 
527
 
 
528
    if (pyg_type_from_object((PyObject *)self) != GIMP_TYPE_VECTORS_COMBO_BOX) {
 
529
        PyErr_SetString(PyExc_RuntimeError, "__gobject_init__ must be used "
 
530
                        "when subclassing gimpui.VectorsComboBox");
 
531
        return -1;
 
532
    }
 
533
 
 
534
    pygobject_register_wrapper((PyObject *)self);
 
535
    return 0;
 
536
}
 
537
%%
 
538
define GimpVectorsComboBox.set_active_vectors kwargs
 
539
static PyObject *
 
540
_wrap_gimp_vectors_combo_box_set_active_vectors(PyGObject *self, PyObject *args, PyObject *kwargs)
 
541
{
 
542
    PyGimpVectors *vect;
 
543
 
 
544
    static char *kwlist[] = { "vectors", NULL };
 
545
 
 
546
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, 
 
547
                                     "O!:GimpVectorsComboBox.set_active_vectors",
 
548
                                     kwlist,
 
549
                                     PyGimpVectors_Type, &vect))
 
550
        return NULL;
 
551
 
 
552
    if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), vect->ID)) {
 
553
        PyErr_Format(pygimp_error,
 
554
                     "Vectors (ID %d) does not exist in GimpVectorsComboBox",
 
555
                     vect->ID);
 
556
        return NULL;
 
557
    }
 
558
 
 
559
    Py_INCREF(Py_None);
 
560
    return Py_None;
 
561
}
 
562
%%
 
563
define GimpVectorsComboBox.get_active_vectors noargs
 
564
static PyObject *
 
565
_wrap_gimp_vectors_combo_box_get_active_vectors(PyGObject *self)
 
566
{
 
567
    int value;
 
568
 
 
569
    if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
 
570
        return pygimp_vectors_new(value);
 
571
 
 
572
    Py_INCREF(Py_None);
 
573
    return Py_None;
 
574
}
 
575
%%
 
576
override gimp_image_combo_box_new kwargs
 
577
static gboolean
 
578
pygimp_image_constraint_marshal(gint32 image_id, gpointer user_data)
 
579
{
 
580
    PyObject *img, *ret;
 
581
    gboolean res;
 
582
    PyGimpConstraintData *data = user_data;
 
583
 
 
584
    img = pygimp_image_new(image_id);
 
585
    if (!img) {
 
586
        PyErr_Print();
 
587
        return FALSE;
 
588
    }
 
589
 
 
590
    if (data->user_data && data->user_data != Py_None)
 
591
        ret = PyObject_CallFunctionObjArgs(data->constraint, img,
 
592
                                           data->user_data, NULL);
 
593
    else
 
594
        ret = PyObject_CallFunctionObjArgs(data->constraint, img, NULL);
 
595
 
 
596
    if (!ret) {
 
597
        PyErr_Print();
 
598
        res = FALSE;
 
599
    } else {
 
600
        res = PyObject_IsTrue(ret);
 
601
        Py_DECREF(ret);
 
602
    }
 
603
 
 
604
    Py_DECREF(img);
 
605
 
 
606
    return res;
 
607
}
 
608
 
 
609
static int
 
610
_wrap_gimp_image_combo_box_new(PyGObject *self, PyObject *args,
 
611
                               PyObject *kwargs)
 
612
{
 
613
    PyObject *constraint = NULL, *user_data = NULL;
 
614
    GimpImageConstraintFunc func = NULL;
 
615
    PyGimpConstraintData *data = NULL;
 
616
 
 
617
    static char *kwlist[] = { "constraint", "data", NULL };
 
618
 
 
619
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
620
                                     "|OO:gimpui.ImageComboBox.__init__",
 
621
                                     kwlist,
 
622
                                     &constraint, &user_data))
 
623
        return -1;
 
624
 
 
625
    if (constraint && constraint != Py_None) {
 
626
        if (!PyCallable_Check(constraint)) {
 
627
            PyErr_SetString(PyExc_TypeError, "first arg must be callable");
 
628
            return -1;
 
629
        }
 
630
 
 
631
        data = g_new(PyGimpConstraintData, 1);
 
632
 
 
633
        data->constraint = constraint;
 
634
        Py_INCREF(constraint);
 
635
 
 
636
        data->user_data = user_data;
 
637
        Py_XINCREF(user_data);
 
638
 
 
639
        func = pygimp_image_constraint_marshal;
 
640
    }
 
641
 
 
642
    self->obj = (GObject *)gimp_image_combo_box_new(func, data);
 
643
 
 
644
    Py_XDECREF(constraint);
 
645
    Py_XDECREF(user_data);
 
646
    g_free(data);
 
647
 
 
648
    if (pyg_type_from_object((PyObject *)self) != GIMP_TYPE_IMAGE_COMBO_BOX) {
 
649
        PyErr_SetString(PyExc_RuntimeError, "__gobject_init__ must be used "
 
650
                        "when subclassing gimpui.ImageComboBox");
 
651
        return -1;
 
652
    }
 
653
 
 
654
    pygobject_register_wrapper((PyObject *)self);
 
655
    return 0;
 
656
}
 
657
%%
 
658
define GimpImageComboBox.set_active_image kwargs
 
659
static PyObject *
 
660
_wrap_gimp_image_combo_box_set_active_image(PyGObject *self, PyObject *args, PyObject *kwargs)
 
661
{
 
662
    PyGimpImage *img;
 
663
 
 
664
    static char *kwlist[] = { "image", NULL };
 
665
 
 
666
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, 
 
667
                                     "O!:GimpImageComboBox.set_active_image",
 
668
                                     kwlist,
 
669
                                     PyGimpImage_Type, &img))
 
670
        return NULL;
 
671
 
 
672
    if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), img->ID)) {
 
673
        PyErr_Format(pygimp_error,
 
674
                     "Image (ID %d) does not exist in GimpImageComboBox",
 
675
                     img->ID);
 
676
        return NULL;
 
677
    }
 
678
 
 
679
    Py_INCREF(Py_None);
 
680
    return Py_None;
 
681
}
 
682
%%
 
683
define GimpImageComboBox.get_active_image noargs
 
684
static PyObject *
 
685
_wrap_gimp_image_combo_box_get_active_image(PyGObject *self)
 
686
{
 
687
    int value;
 
688
 
 
689
    if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
 
690
        return pygimp_image_new(value);
 
691
 
 
692
    Py_INCREF(Py_None);
 
693
    return Py_None;
 
694
}
 
695
%%
 
696
override gimp_dialog_new kwargs
 
697
static void
 
698
pygimp_help_func_marshal(const gchar *help_id, gpointer help_data)
 
699
{
 
700
    GObject *dialog = help_data;
 
701
    PyObject *py_dialog, *help_func, *ret;
 
702
 
 
703
    py_dialog = g_object_get_data(dialog, "pygimp-dialog-pyobject");
 
704
    help_func = g_object_get_data(dialog, "pygimp-dialog-help_func");
 
705
 
 
706
    ret = PyObject_CallFunction(help_func, "sO", help_id, py_dialog);
 
707
 
 
708
    if (ret)
 
709
        Py_DECREF(ret);
 
710
    else
 
711
        PyErr_Print();
 
712
}
 
713
 
 
714
static void
 
715
pygimp_help_func_destroy(gpointer data)
 
716
{
 
717
    PyObject *help_func = data;
 
718
 
 
719
    Py_DECREF(help_func);
 
720
}
 
721
 
 
722
static void
 
723
pygimp_dialog_close(GtkWidget *widget)
 
724
{
 
725
    /* Synthesize delete_event to close dialog. */
 
726
 
 
727
    if (widget->window) {
 
728
        GdkEvent *event = gdk_event_new(GDK_DELETE);
 
729
 
 
730
        event->any.window     = g_object_ref(widget->window);
 
731
        event->any.send_event = TRUE;
 
732
 
 
733
        gtk_main_do_event(event);
 
734
        gdk_event_free(event);
 
735
    }
 
736
}
 
737
 
 
738
static int
 
739
_wrap_gimp_dialog_new(PyGObject *self, PyObject *args, PyObject *kwargs)
 
740
{
 
741
    gchar *title, *role;
 
742
    PyGObject *py_window = NULL;
 
743
    PyObject *py_flags = NULL, *py_buttons = Py_None;
 
744
    PyObject *help_func = NULL;
 
745
    gchar *help_id = NULL;
 
746
    GtkDialogFlags flags = 0;
 
747
    int len, i;
 
748
    GtkWidget *parent;
 
749
    GimpHelpFunc func;
 
750
 
 
751
    static char *kwlist[] = { "title", "role", "parent", "flags",
 
752
                              "help_func", "help_id", "buttons", NULL };
 
753
 
 
754
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
755
                                     "zz|OOOzO:gimpui.GimpDialog.__init__",
 
756
                                     kwlist,
 
757
                                     &title, &role, &py_window, &py_flags,
 
758
                                     &help_func, &help_id, &py_buttons))
 
759
        return -1;
 
760
 
 
761
    if (py_window == NULL || (PyObject*)py_window == Py_None)
 
762
        parent = NULL;
 
763
    else if (pygobject_check(py_window, &PyGtkWindow_Type))
 
764
        parent = GTK_WIDGET(py_window->obj);
 
765
    else {
 
766
        PyErr_SetString(PyExc_TypeError, "parent must be a GtkWindow or None");
 
767
        return -1;
 
768
    }
 
769
 
 
770
    if (pyg_flags_get_value(GTK_TYPE_DIALOG_FLAGS, py_flags, (gint *)&flags))
 
771
        return -1;
 
772
 
 
773
    if (help_func) {
 
774
        if (help_func != Py_None) {
 
775
            if (!PyCallable_Check(help_func)) {
 
776
                PyErr_SetString(PyExc_TypeError, "help_func must be callable");
 
777
                return -1;
 
778
            }
 
779
 
 
780
            func = pygimp_help_func_marshal;
 
781
 
 
782
            g_object_set_data(self->obj, "pygimp-dialog-help-data", self);
 
783
 
 
784
            Py_INCREF(help_func);
 
785
            g_object_set_data_full(self->obj, "pygimp-dialog-help-func",
 
786
                                   help_func, pygimp_help_func_destroy);
 
787
        } else {
 
788
            func = gimp_standard_help_func;
 
789
        }
 
790
    } else {
 
791
        func = gimp_standard_help_func;
 
792
    }
 
793
 
 
794
    if (py_buttons == Py_None)
 
795
        len = 0;
 
796
    else if (PyTuple_Check(py_buttons))
 
797
        len = PyTuple_Size(py_buttons);
 
798
    else {
 
799
        PyErr_SetString(PyExc_TypeError, "buttons must be a tuple containing text/response pairs or None");
 
800
        return -1;
 
801
    }
 
802
 
 
803
    if (len % 2) {
 
804
        PyErr_SetString(PyExc_RuntimeError,
 
805
                        "buttons tuple must contain text/response id pairs");
 
806
        return -1;
 
807
    }
 
808
 
 
809
    pygobject_construct(self,
 
810
                        "title",     title,
 
811
                        "role",      role,
 
812
                        "modal",     (flags & GTK_DIALOG_MODAL),
 
813
                        "help-func", func,
 
814
                        "help-id",   help_id,
 
815
                        NULL);
 
816
 
 
817
    if (!self->obj) {
 
818
        PyErr_SetString(PyExc_RuntimeError,
 
819
                        "could not create GimpDialog object");
 
820
        return -1;
 
821
    }
 
822
 
 
823
    if (parent) {
 
824
        if (GTK_IS_WINDOW(parent))
 
825
            gtk_window_set_transient_for(GTK_WINDOW(self->obj),
 
826
                                         GTK_WINDOW(parent));
 
827
        else
 
828
            gtk_window_set_screen(GTK_WINDOW(self->obj),
 
829
                                  gtk_widget_get_screen(parent));
 
830
 
 
831
        if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
 
832
            g_signal_connect_object(parent, "destroy",
 
833
                                    G_CALLBACK(pygimp_dialog_close),
 
834
                                    self->obj, G_CONNECT_SWAPPED);
 
835
    }
 
836
 
 
837
    for (i = 0; i < len; i += 2) {
 
838
        PyObject *text = PyTuple_GetItem(py_buttons, i);
 
839
        PyObject *id = PyTuple_GetItem(py_buttons, i + 1);
 
840
        if (!PyString_Check(text) && !PyUnicode_Check(text)) {
 
841
            gtk_object_destroy(GTK_OBJECT(self->obj));
 
842
            self->obj = NULL;
 
843
            PyErr_SetString(PyExc_RuntimeError,
 
844
                            "first member of each text/response id pair "
 
845
                            "must be a string");
 
846
            return -1;
 
847
        }
 
848
        if (!PyInt_Check(id)) {
 
849
            gtk_object_destroy(GTK_OBJECT(self->obj));
 
850
            self->obj = NULL;
 
851
            PyErr_SetString(PyExc_RuntimeError,
 
852
                            "second member of each text/response id pair "
 
853
                            "must be a number");
 
854
            return -1;
 
855
        }
 
856
 
 
857
        gimp_dialog_add_button(GIMP_DIALOG(self->obj), PyString_AsString(text),
 
858
                               PyInt_AsLong(id));
 
859
    }
 
860
 
 
861
    return 0;
 
862
}
 
863
%%
 
864
new-constructor GIMP_TYPE_DIALOG
 
865
%%
 
866
override gimp_color_button_get_color noargs
 
867
static PyObject *
 
868
_wrap_gimp_color_button_get_color(PyGObject *self)
 
869
{
 
870
    GimpRGB rgb;
 
871
 
 
872
    gimp_color_button_get_color(GIMP_COLOR_BUTTON(self->obj), &rgb);
 
873
 
 
874
    return pygimp_rgb_new(&rgb);
 
875
}
 
876
%%
 
877
override gimp_brush_select_button_get_brush noargs
 
878
static PyObject *
 
879
_wrap_gimp_brush_select_button_get_brush(PyGObject *self)
 
880
{
 
881
    const gchar *brush_name;
 
882
    gdouble opacity;
 
883
    gint spacing;
 
884
    GimpLayerModeEffects paint_mode;
 
885
 
 
886
    brush_name =
 
887
        gimp_brush_select_button_get_brush(GIMP_BRUSH_SELECT_BUTTON(self->obj),
 
888
                                           &opacity, &spacing, &paint_mode);
 
889
 
 
890
    return Py_BuildValue("(sdiN)", brush_name, opacity, spacing,
 
891
                         pyg_enum_from_gtype(GIMP_TYPE_LAYER_MODE_EFFECTS,
 
892
                                             paint_mode));
 
893
}
 
894
%%
 
895
override gimp_window_set_transient
 
896
static PyObject *
 
897
_wrap_gimp_window_set_transient(PyGObject *self)
 
898
{
 
899
    gimp_window_set_transient(GTK_WINDOW(self->obj));
 
900
    Py_INCREF(Py_None);
 
901
    return Py_None;
 
902
}
 
903
%%
 
904
override gimp_color_button_new kwargs
 
905
static int
 
906
_wrap_gimp_color_button_new(PyGObject *self, PyObject *args, PyObject *kwargs)
 
907
{
 
908
    gchar *title = NULL;
 
909
    gint width = -1, height = -1;
 
910
    PyObject *py_color = NULL, *py_type = NULL;
 
911
    GimpRGB *color, default_color = { 0.0, 0.0, 0.0, 100.0 };
 
912
    GimpColorAreaType type;
 
913
    
 
914
    static char *kwlist[] = { "title", "width", "height", "color", "type",
 
915
                              NULL };
 
916
 
 
917
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
918
                                     "|ziiOO:gimpui.ColorButton.__init__",
 
919
                                     kwlist,
 
920
                                     &title, &width, &height,
 
921
                                     &py_color, &py_type))
 
922
        return -1;
 
923
 
 
924
    if (py_color == NULL || (PyObject*)py_color == Py_None)
 
925
        color = &default_color;
 
926
    else if (pyg_boxed_check(py_color, GIMP_TYPE_RGB))
 
927
        color = pyg_boxed_get(py_color, GimpRGB);
 
928
    else {
 
929
        PyErr_SetString(PyExc_TypeError, "color should be a GimpRGB or None");
 
930
        return -1;
 
931
    }
 
932
 
 
933
    if (py_type == NULL || (PyObject*)py_type == Py_None)
 
934
       type = GIMP_COLOR_AREA_FLAT;
 
935
    else if (pyg_enum_get_value(GIMP_TYPE_COLOR_AREA_TYPE, py_type, (gint*)&type))
 
936
       return -1;
 
937
 
 
938
    if (pygobject_construct(self,
 
939
                            "title", title,
 
940
                            "type", type,
 
941
                            "color", color,
 
942
                            NULL))
 
943
        return -1;
 
944
 
 
945
    gtk_widget_set_size_request(GIMP_COLOR_BUTTON(self->obj)->color_area,
 
946
                                width, height);
 
947
    return 0;
 
948
}
 
949
%%
 
950
new-constructor GIMP_TYPE_COLOR_BUTTON
 
951
%%
 
952
override gimp_color_scale_new kwargs
 
953
static int
 
954
_wrap_gimp_color_scale_new(PyGObject *self, PyObject *args, PyObject *kwargs)
 
955
{
 
956
    PyObject *py_orientation, *py_channel;
 
957
    GtkOrientation orientation;
 
958
    GimpColorSelectorChannel channel;
 
959
    GimpColorScale *scale;
 
960
    GtkRange *range;
 
961
 
 
962
    static char *kwlist[] = { "orientation", "channel", NULL };
 
963
 
 
964
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
965
                                     "OO:gimpui.ColorScale.__init__",
 
966
                                     kwlist,
 
967
                                     &py_orientation, &py_channel))
 
968
        return -1;
 
969
 
 
970
    if (pyg_enum_get_value(GTK_TYPE_ORIENTATION, py_orientation,
 
971
                           (gint*)&orientation))
 
972
        return -1;
 
973
 
 
974
    if (pyg_enum_get_value(GIMP_TYPE_COLOR_SELECTOR_CHANNEL, py_channel, 
 
975
                           (gint*)&channel))
 
976
        return -1;
 
977
 
 
978
    if (pygobject_construct(self, NULL))
 
979
        return -1;
 
980
 
 
981
    scale = GIMP_COLOR_SCALE(self->obj);
 
982
    scale->channel = channel;
 
983
 
 
984
    range = GTK_RANGE(scale);
 
985
    range->orientation = orientation;
 
986
    range->flippable   = (orientation == GTK_ORIENTATION_HORIZONTAL);
 
987
    
 
988
    return 0;
 
989
}
 
990
%%
 
991
new-constructor GIMP_TYPE_COLOR_SCALE
 
992
%%
 
993
override gimp_enum_label_new kwargs
 
994
static int
 
995
_wrap_gimp_enum_label_new(PyGObject *self, PyObject *args, PyObject *kwargs)
 
996
{
 
997
    PyObject *py_enum_type = NULL;
 
998
    gint value;
 
999
    GType enum_type;
 
1000
    GimpEnumLabel *label;
 
1001
 
 
1002
    static char *kwlist[] = { "enum_type", "value", NULL };
 
1003
 
 
1004
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
1005
                                     "Oi:gimpui.GimpEnumLabel.__init__",
 
1006
                                     kwlist,
 
1007
                                     &py_enum_type, &value))
 
1008
        return -1;
 
1009
 
 
1010
    if ((enum_type = pyg_type_from_object(py_enum_type)) == 0)
 
1011
        return -1;
 
1012
 
 
1013
    if (pygobject_construct(self, NULL))
 
1014
        return -1;
 
1015
 
 
1016
    label = GIMP_ENUM_LABEL(self->obj);
 
1017
 
 
1018
    label->enum_class = g_type_class_ref(enum_type);
 
1019
 
 
1020
    gimp_enum_label_set_value (label, value);
 
1021
 
 
1022
    return 0; 
 
1023
}
 
1024
%%
 
1025
new-constructor GIMP_TYPE_ENUM_LABEL
 
1026
%%
 
1027
override gimp_int_combo_box_new kwargs
 
1028
static int
 
1029
_wrap_gimp_int_combo_box_new(PyGObject *self, PyObject *args, PyObject *kwargs)
 
1030
{
 
1031
    PyObject *py_items = NULL;
 
1032
    int len, i;
 
1033
 
 
1034
    static char *kwlist[] = { "items", NULL };
 
1035
 
 
1036
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
1037
                                     "|O:gimpui.IntComboBox.__init__",
 
1038
                                     kwlist,
 
1039
                                     &py_items))
 
1040
        return -1; 
 
1041
 
 
1042
    if (py_items == NULL || py_items == Py_None)
 
1043
        len = 0;
 
1044
    else if (PyTuple_Check(py_items))
 
1045
        len = PyTuple_Size(py_items);
 
1046
    else {
 
1047
        PyErr_SetString(PyExc_TypeError,
 
1048
                        "items must be a tuple containing label/value pairs "
 
1049
                        "or None");
 
1050
        return -1;
 
1051
    }
 
1052
 
 
1053
    if (len % 2) {
 
1054
        PyErr_SetString(PyExc_RuntimeError,
 
1055
                        "items tuple must contain label/value pairs");
 
1056
        return -1;
 
1057
    }
 
1058
 
 
1059
    if (pygobject_construct(self, NULL))
 
1060
        return -1;
 
1061
 
 
1062
    for (i = 0; i < len; i += 2) {
 
1063
        PyObject *label = PyTuple_GetItem(py_items, i);
 
1064
        PyObject *value = PyTuple_GetItem(py_items, i + 1);
 
1065
 
 
1066
        if (!PyString_Check(label)) {
 
1067
            gtk_object_destroy(GTK_OBJECT(self->obj));
 
1068
            self->obj = NULL;
 
1069
            PyErr_SetString(PyExc_RuntimeError,
 
1070
                            "first member of each label/value pair "
 
1071
                            "must be a string");
 
1072
            return -1;
 
1073
        }
 
1074
 
 
1075
        if (!PyInt_Check(value)) {
 
1076
            gtk_object_destroy(GTK_OBJECT(self->obj));
 
1077
            self->obj = NULL;
 
1078
            PyErr_SetString(PyExc_RuntimeError,
 
1079
                            "second member of each label/value pair "
 
1080
                            "must be a number");
 
1081
            return -1;
 
1082
        }
 
1083
 
 
1084
        gimp_int_combo_box_append(GIMP_INT_COMBO_BOX(self->obj),
 
1085
                                  PyString_AsString(label),
 
1086
                                  PyInt_AsLong(value),
 
1087
                                  -1);
 
1088
    }
 
1089
 
 
1090
    return 0;
 
1091
}
 
1092
%%
 
1093
new-constructor GIMP_TYPE_INT_COMBO_BOX
 
1094
%%
 
1095
override gimp_int_combo_box_get_active noargs
 
1096
static PyObject *
 
1097
_wrap_gimp_int_combo_box_get_active(PyGObject *self)
 
1098
{
 
1099
    int value;
 
1100
 
 
1101
    if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(self->obj), &value))
 
1102
        return PyLong_FromLong(value);
 
1103
 
 
1104
    Py_INCREF(Py_None);
 
1105
    return Py_None;
 
1106
}
 
1107
%%
 
1108
override gimp_int_combo_box_set_active kwargs
 
1109
static PyObject *
 
1110
_wrap_gimp_int_combo_box_set_active(PyGObject *self, PyObject *args, PyObject *kwargs)
 
1111
{
 
1112
    int value;
 
1113
 
 
1114
    static char *kwlist[] = { "value", NULL };
 
1115
 
 
1116
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, 
 
1117
                                     "i:GimpIntComboBox.set_active", kwlist,
 
1118
                                     &value))
 
1119
        return NULL;
 
1120
 
 
1121
    if (!gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(self->obj), value)) {
 
1122
        PyErr_Format(pygimp_error,
 
1123
                     "Value %d does not exist in GimpIntComboBox",
 
1124
                     value);
 
1125
        return NULL;
 
1126
    }
 
1127
 
 
1128
    Py_INCREF(Py_None);
 
1129
    return Py_None;
 
1130
}
 
1131
%%
 
1132
override gimp_browser_add_search_types kwargs
 
1133
static PyObject *
 
1134
_wrap_gimp_browser_add_search_types(PyGObject *self, PyObject *args, PyObject *kwargs)
 
1135
{
 
1136
    PyObject *py_types = NULL;
 
1137
    int len, i;
 
1138
 
 
1139
    static char *kwlist[] = { "search_types", NULL };
 
1140
 
 
1141
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
1142
                                     "O:GimpBrowser.add_search_types",
 
1143
                                     kwlist,
 
1144
                                     &py_types))
 
1145
        return NULL;
 
1146
 
 
1147
    if (PyTuple_Check(py_types))
 
1148
        len = PyTuple_Size(py_types);
 
1149
    else {
 
1150
        PyErr_SetString(PyExc_TypeError,
 
1151
                        "search_types must be a tuple containing label/id "
 
1152
                        "pairs");
 
1153
        return NULL;
 
1154
    }
 
1155
 
 
1156
    if (len % 2) {
 
1157
        PyErr_SetString(PyExc_RuntimeError,
 
1158
                        "search_types tuple must contain label/id pairs");
 
1159
        return NULL;
 
1160
    }
 
1161
 
 
1162
    for (i = 0; i < len; i += 2) {
 
1163
        PyObject *label = PyTuple_GetItem(py_types, i);
 
1164
        PyObject *id = PyTuple_GetItem(py_types, i + 1);
 
1165
 
 
1166
        if (!PyString_Check(label)) {
 
1167
            PyErr_SetString(PyExc_RuntimeError,
 
1168
                            "first member of each label/id pair "
 
1169
                            "must be a string");
 
1170
            return NULL;
 
1171
        }
 
1172
 
 
1173
        if (!PyInt_Check(id)) {
 
1174
            PyErr_SetString(PyExc_RuntimeError,
 
1175
                            "second member of each label/id pair "
 
1176
                            "must be a number");
 
1177
            return NULL;
 
1178
        }
 
1179
 
 
1180
        gimp_browser_add_search_types(GIMP_BROWSER(self->obj),
 
1181
                                      PyString_AsString(label),
 
1182
                                      PyInt_AsLong(id),
 
1183
                                      NULL);
 
1184
    }
 
1185
 
 
1186
    Py_INCREF(Py_None);
 
1187
    return Py_None;
 
1188
}
 
1189
%%
 
1190
override gimp_proc_browser_dialog_new kwargs
 
1191
static int
 
1192
_wrap_gimp_proc_browser_dialog_new(PyGObject *self, PyObject *args, PyObject *kwargs)
 
1193
{
 
1194
    gchar *title, *role;
 
1195
    PyObject *py_buttons = Py_None;
 
1196
    PyObject *help_func = NULL;
 
1197
    gchar *help_id = NULL;
 
1198
    int len, i;
 
1199
    GimpHelpFunc func;
 
1200
 
 
1201
    static char *kwlist[] = { "title", "role", "help_func", "help_id",
 
1202
                              "buttons", NULL };
 
1203
 
 
1204
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
1205
                                     "zz|OzO:gimpui.GimpProcBrowserDialog.__init__",
 
1206
                                     kwlist,
 
1207
                                     &title, &role, &help_func, &help_id,
 
1208
                                     &py_buttons))
 
1209
        return -1;
 
1210
 
 
1211
    if (help_func) {
 
1212
        if (help_func != Py_None) {
 
1213
            if (!PyCallable_Check(help_func)) {
 
1214
                PyErr_SetString(PyExc_TypeError, "help_func must be callable");
 
1215
                return -1;
 
1216
            }
 
1217
 
 
1218
            func = pygimp_help_func_marshal;
 
1219
 
 
1220
            g_object_set_data(self->obj, "pygimp-dialog-help-data", self);
 
1221
 
 
1222
            Py_INCREF(help_func);
 
1223
            g_object_set_data_full(self->obj, "pygimp-dialog-help-func",
 
1224
                                   help_func, pygimp_help_func_destroy);
 
1225
        } else {
 
1226
            func = gimp_standard_help_func;
 
1227
        }
 
1228
    } else {
 
1229
        func = gimp_standard_help_func;
 
1230
    }
 
1231
 
 
1232
    if (py_buttons == Py_None)
 
1233
        len = 0;
 
1234
    else if (PyTuple_Check(py_buttons))
 
1235
        len = PyTuple_Size(py_buttons);
 
1236
    else {
 
1237
        PyErr_SetString(PyExc_TypeError, "buttons must be a tuple containing text/response pairs or None");
 
1238
        return -1;
 
1239
    }
 
1240
 
 
1241
    if (len % 2) {
 
1242
        PyErr_SetString(PyExc_RuntimeError,
 
1243
                        "buttons tuple must contain text/response id pairs");
 
1244
        return -1;
 
1245
    }
 
1246
 
 
1247
    pygobject_construct(self,
 
1248
                        "title",     title,
 
1249
                        "role",      role,
 
1250
                        "help-func", func,
 
1251
                        "help-id",   help_id,
 
1252
                        NULL);
 
1253
 
 
1254
    if (!self->obj) {
 
1255
        PyErr_SetString(PyExc_RuntimeError,
 
1256
                        "could not create GimpProcBrowserDialog object");
 
1257
        return -1;
 
1258
    }
 
1259
 
 
1260
    for (i = 0; i < len; i += 2) {
 
1261
        PyObject *text = PyTuple_GetItem(py_buttons, i);
 
1262
        PyObject *id = PyTuple_GetItem(py_buttons, i + 1);
 
1263
        if (!PyString_Check(text) && !PyUnicode_Check(text)) {
 
1264
            gtk_object_destroy(GTK_OBJECT(self->obj));
 
1265
            self->obj = NULL;
 
1266
            PyErr_SetString(PyExc_RuntimeError,
 
1267
                            "first member of each text/response id pair "
 
1268
                            "must be a string");
 
1269
            return -1;
 
1270
        }
 
1271
        if (!PyInt_Check(id)) {
 
1272
            gtk_object_destroy(GTK_OBJECT(self->obj));
 
1273
            self->obj = NULL;
 
1274
            PyErr_SetString(PyExc_RuntimeError,
 
1275
                            "second member of each text/response id pair "
 
1276
                            "must be a number");
 
1277
            return -1;
 
1278
        }
 
1279
 
 
1280
        gimp_dialog_add_button(GIMP_DIALOG(self->obj), PyString_AsString(text),
 
1281
                               PyInt_AsLong(id));
 
1282
    }
 
1283
 
 
1284
    g_signal_emit_by_name(GIMP_PROC_BROWSER_DIALOG(self->obj)->browser,
 
1285
                          "search", "", 0, self->obj);
 
1286
    return 0;
 
1287
}
 
1288
%%
 
1289
new-constructor GIMP_TYPE_PROC_BROWSER_DIALOG