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

« back to all changes in this revision

Viewing changes to plug-ins/pygimp/gimpmodule.c

  • 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:
22
22
#endif
23
23
 
24
24
#include "pygimp.h"
 
25
 
 
26
#include "pygimpcolor-api.h"
 
27
 
25
28
#include <sysmodule.h>
26
29
 
27
 
#if PY_VERSION_HEX >= 0x2030000
28
 
#define ARG_UINT_FORMAT "I"
29
 
#else
30
 
#define ARG_UINT_FORMAT "i"
31
 
#endif
32
 
 
33
 
/* maximum bits per pixel ... */
34
 
#define MAX_BPP 4
 
30
#include <glib-object.h>
 
31
 
 
32
#include <pygobject.h>
 
33
 
 
34
#include "pygimp-util.h"
 
35
 
 
36
#include "pygimp-intl.h"
 
37
 
35
38
 
36
39
PyObject *pygimp_error;
37
40
 
67
70
pygimp_init_proc(void)
68
71
{
69
72
    PyObject *r;
 
73
 
70
74
    r = PyObject_CallFunction(callbacks[0], "()");
 
75
 
71
76
    if (!r) {
72
 
        PyErr_Print();
73
 
        PyErr_Clear();
74
 
        return;
 
77
        PyErr_Print();
 
78
        PyErr_Clear();
 
79
        return;
75
80
    }
 
81
 
76
82
    Py_DECREF(r);
77
83
}
78
84
 
80
86
pygimp_quit_proc(void)
81
87
{
82
88
    PyObject *r;
 
89
 
83
90
    r = PyObject_CallFunction(callbacks[1], "()");
 
91
 
84
92
    if (!r) {
85
 
        PyErr_Print();
86
 
        PyErr_Clear();
87
 
        return;
 
93
        PyErr_Print();
 
94
        PyErr_Clear();
 
95
        return;
88
96
    }
 
97
 
89
98
    Py_DECREF(r);
90
99
}
91
100
 
93
102
pygimp_query_proc(void)
94
103
{
95
104
    PyObject *r;
 
105
 
96
106
    r = PyObject_CallFunction(callbacks[2], "()");
 
107
 
97
108
    if (!r) {
98
 
        PyErr_Print();
99
 
        PyErr_Clear();
100
 
        return;
 
109
        PyErr_Print();
 
110
        PyErr_Clear();
 
111
        return;
101
112
    }
 
113
 
102
114
    Py_DECREF(r);
103
115
}
104
116
 
105
117
static void
106
118
pygimp_run_proc(const char *name, int nparams, const GimpParam *params,
107
 
                int *nreturn_vals, GimpParam **return_vals)
 
119
                int *nreturn_vals, GimpParam **return_vals)
108
120
{
109
121
    PyObject *args, *ret;
110
122
    GimpParamDef *pd, *rv;
113
125
    int np, nrv;
114
126
 
115
127
    gimp_procedural_db_proc_info(name, &b, &h, &a, &c, &d, &t, &np, &nrv,
116
 
                         &pd, &rv);
 
128
                                 &pd, &rv);
117
129
    g_free(b); g_free(h); g_free(a); g_free(c); g_free(d); g_free(pd);
118
130
 
119
131
#if PG_DEBUG > 0
120
 
    fprintf(stderr, "Params for %s:", name);
 
132
    g_printerr("Params for %s:", name);
121
133
    print_GParam(nparams, params);
122
134
#endif
 
135
 
123
136
    args = pygimp_param_to_tuple(nparams, params);
 
137
 
124
138
    if (args == NULL) {
125
 
        PyErr_Clear();
126
 
        *nreturn_vals = 1;
127
 
        *return_vals = g_new(GimpParam, 1);
128
 
        (*return_vals)[0].type = GIMP_PDB_STATUS;
129
 
        (*return_vals)[0].data.d_status = GIMP_PDB_CALLING_ERROR;
130
 
        return;
 
139
        PyErr_Clear();
 
140
 
 
141
        *nreturn_vals = 1;
 
142
        *return_vals = g_new(GimpParam, 1);
 
143
        (*return_vals)[0].type = GIMP_PDB_STATUS;
 
144
        (*return_vals)[0].data.d_status = GIMP_PDB_CALLING_ERROR;
 
145
 
 
146
        return;
131
147
    }
 
148
 
132
149
    ret = PyObject_CallFunction(callbacks[3], "(sO)", name, args);
133
150
    Py_DECREF(args);
 
151
 
134
152
    if (ret == NULL) {
135
 
        PyErr_Print();
136
 
        PyErr_Clear();
137
 
        *nreturn_vals = 1;
138
 
        *return_vals = g_new(GimpParam, 1);
139
 
        (*return_vals)[0].type = GIMP_PDB_STATUS;
140
 
        (*return_vals)[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
141
 
        return;
 
153
        PyErr_Print();
 
154
        PyErr_Clear();
 
155
 
 
156
        *nreturn_vals = 1;
 
157
        *return_vals = g_new(GimpParam, 1);
 
158
        (*return_vals)[0].type = GIMP_PDB_STATUS;
 
159
        (*return_vals)[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
 
160
 
 
161
        return;
142
162
    }
 
163
 
143
164
    *return_vals = pygimp_param_from_tuple(ret, rv, nrv);
144
165
    g_free(rv);
 
166
 
145
167
    if (*return_vals == NULL) {
146
 
        PyErr_Clear();
147
 
        *nreturn_vals = 1;
148
 
        *return_vals = g_new(GimpParam, 1);
149
 
        (*return_vals)[0].type = GIMP_PDB_STATUS;
150
 
        (*return_vals)[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
151
 
        return;
 
168
        PyErr_Clear();
 
169
 
 
170
        *nreturn_vals = 1;
 
171
        *return_vals = g_new(GimpParam, 1);
 
172
        (*return_vals)[0].type = GIMP_PDB_STATUS;
 
173
        (*return_vals)[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
 
174
 
 
175
        return;
152
176
    }
 
177
 
153
178
    Py_DECREF(ret);
 
179
 
154
180
    *nreturn_vals = nrv + 1;
155
181
    (*return_vals)[0].type = GIMP_PDB_STATUS;
156
182
    (*return_vals)[0].data.d_status = GIMP_PDB_SUCCESS;
163
189
    int argc, i;
164
190
    char **argv;
165
191
    PyObject *ip, *qp, *query, *rp;
166
 
        
 
192
 
167
193
    if (!PyArg_ParseTuple(args, "OOOO:main", &ip, &qp, &query, &rp))
168
 
        return NULL;
 
194
        return NULL;
169
195
 
170
196
#define Arg_Check(v) (PyCallable_Check(v) || (v) == Py_None)
171
197
 
172
198
    if (!Arg_Check(ip) || !Arg_Check(qp) || !Arg_Check(query) ||
173
 
        !Arg_Check(rp)) {
174
 
        PyErr_SetString(pygimp_error, "arguments must be callable");
175
 
        return NULL;
 
199
        !Arg_Check(rp)) {
 
200
        PyErr_SetString(pygimp_error, "arguments must be callable");
 
201
        return NULL;
176
202
    }
 
203
 
 
204
#undef Arg_Check
 
205
 
177
206
    if (query == Py_None) {
178
 
        PyErr_SetString(pygimp_error, "a query procedure must be provided");
179
 
        return NULL;
 
207
        PyErr_SetString(pygimp_error, "a query procedure must be provided");
 
208
        return NULL;
180
209
    }
181
210
 
182
211
    if (ip != Py_None) {
183
 
        callbacks[0] = ip;
184
 
        PLUG_IN_INFO.init_proc = pygimp_init_proc;
 
212
        callbacks[0] = ip;
 
213
        PLUG_IN_INFO.init_proc = pygimp_init_proc;
185
214
    }
 
215
 
186
216
    if (qp != Py_None) {
187
 
        callbacks[1] = qp;
188
 
        PLUG_IN_INFO.quit_proc = pygimp_quit_proc;
 
217
        callbacks[1] = qp;
 
218
        PLUG_IN_INFO.quit_proc = pygimp_quit_proc;
189
219
    }
 
220
 
190
221
    if (query != Py_None) {
191
 
        callbacks[2] = query;
192
 
        PLUG_IN_INFO.query_proc = pygimp_query_proc;
 
222
        callbacks[2] = query;
 
223
        PLUG_IN_INFO.query_proc = pygimp_query_proc;
193
224
    }
 
225
 
194
226
    if (rp != Py_None) {
195
 
        callbacks[3] = rp;
196
 
        PLUG_IN_INFO.run_proc = pygimp_run_proc;
 
227
        callbacks[3] = rp;
 
228
        PLUG_IN_INFO.run_proc = pygimp_run_proc;
197
229
    }
198
230
 
199
231
    av = PySys_GetObject("argv");
202
234
    argv = g_new(char *, argc);
203
235
 
204
236
    for (i = 0; i < argc; i++)
205
 
        argv[i] = g_strdup(PyString_AsString(PyList_GetItem(av, i)));
 
237
        argv[i] = g_strdup(PyString_AsString(PyList_GetItem(av, i)));
206
238
 
207
239
    gimp_main(&PLUG_IN_INFO, argc, argv);
208
240
 
209
241
    if (argv != NULL) {
210
 
        for (i = 0; i < argc; i++)
211
 
            if (argv[i] != NULL)
212
 
                g_free(argv[i]);
213
 
        g_free(argv);
 
242
        for (i = 0; i < argc; i++)
 
243
            if (argv[i] != NULL)
 
244
                g_free(argv[i]);
 
245
 
 
246
        g_free(argv);
214
247
    }
215
248
 
216
249
    Py_INCREF(Py_None);
221
254
pygimp_quit(PyObject *self)
222
255
{
223
256
    gimp_quit();
 
257
 
224
258
    Py_INCREF(Py_None);
225
259
    return Py_None;
226
260
}
229
263
pygimp_message(PyObject *self, PyObject *args)
230
264
{
231
265
    char *msg;
 
266
 
232
267
    if (!PyArg_ParseTuple(args, "s:message", &msg))
233
268
        return NULL;
 
269
 
234
270
    gimp_message(msg);
 
271
 
235
272
    Py_INCREF(Py_None);
236
273
    return Py_None;
237
274
}
244
281
    GimpParam *return_vals;
245
282
 
246
283
    if (!PyArg_ParseTuple(args, "ss#:set_data", &id, &data, &bytes))
247
 
        return NULL;
 
284
        return NULL;
248
285
 
249
 
    return_vals = gimp_run_procedure("gimp_procedural_db_set_data",
250
 
                                     &nreturn_vals,
251
 
                                     GIMP_PDB_STRING, id,
252
 
                                     GIMP_PDB_INT32, bytes,
253
 
                                     GIMP_PDB_INT8ARRAY, data,
254
 
                                     GIMP_PDB_END);
 
286
    return_vals = gimp_run_procedure("gimp-procedural-db-set-data",
 
287
                                     &nreturn_vals,
 
288
                                     GIMP_PDB_STRING, id,
 
289
                                     GIMP_PDB_INT32, bytes,
 
290
                                     GIMP_PDB_INT8ARRAY, data,
 
291
                                     GIMP_PDB_END);
255
292
 
256
293
    if (return_vals[0].data.d_status != GIMP_PDB_SUCCESS) {
257
 
        PyErr_SetString(pygimp_error, "error occurred while storing");
258
 
        return NULL;
 
294
        PyErr_SetString(pygimp_error, "error occurred while storing");
 
295
        return NULL;
259
296
    }
 
297
 
260
298
    gimp_destroy_params(return_vals, nreturn_vals);
 
299
 
261
300
    Py_INCREF(Py_None);
262
301
    return Py_None;
263
302
}
271
310
    PyObject *s;
272
311
 
273
312
    if (!PyArg_ParseTuple(args, "s:get_data", &id))
274
 
        return NULL;
 
313
        return NULL;
275
314
 
276
 
    return_vals = gimp_run_procedure("gimp_procedural_db_get_data",
277
 
                                     &nreturn_vals,
278
 
                                     GIMP_PDB_STRING, id,
279
 
                                     GIMP_PDB_END);
 
315
    return_vals = gimp_run_procedure("gimp-procedural-db-get-data",
 
316
                                     &nreturn_vals,
 
317
                                     GIMP_PDB_STRING, id,
 
318
                                     GIMP_PDB_END);
280
319
 
281
320
    if (return_vals[0].data.d_status != GIMP_PDB_SUCCESS) {
282
 
        PyErr_SetString(pygimp_error, "no data for id");
283
 
        return NULL;
 
321
        PyErr_SetString(pygimp_error, "no data for id");
 
322
        return NULL;
284
323
    }
 
324
 
285
325
    s = PyString_FromStringAndSize((char *)return_vals[2].data.d_int8array,
286
 
                                   return_vals[1].data.d_int32);
 
326
                                   return_vals[1].data.d_int32);
287
327
    gimp_destroy_params(return_vals, nreturn_vals);
 
328
 
288
329
    return s;
289
330
}
290
331
 
292
333
pygimp_progress_init(PyObject *self, PyObject *args)
293
334
{
294
335
    char *msg = NULL;
 
336
 
295
337
    if (!PyArg_ParseTuple(args, "|s:progress_init", &msg))
296
 
        return NULL;
 
338
        return NULL;
 
339
 
297
340
    gimp_progress_init(msg);
 
341
 
298
342
    Py_INCREF(Py_None);
299
343
    return Py_None;
300
344
}
303
347
pygimp_progress_update(PyObject *self, PyObject *args)
304
348
{
305
349
    double p;
 
350
 
306
351
    if (!PyArg_ParseTuple(args, "d:progress_update", &p))
307
 
        return NULL;
 
352
        return NULL;
 
353
 
308
354
    gimp_progress_update(p);
 
355
 
309
356
    Py_INCREF(Py_None);
310
357
    return Py_None;
311
358
}
317
364
    PyObject *r;
318
365
 
319
366
    if (pdata->user_data) {
320
 
        r = PyObject_CallFunction(pdata->start, "siO", message, cancelable,
321
 
                                  pdata->user_data);
322
 
        Py_DECREF(pdata->user_data);
 
367
        r = PyObject_CallFunction(pdata->start, "siO", message, cancelable,
 
368
                                  pdata->user_data);
 
369
        Py_DECREF(pdata->user_data);
323
370
    } else
324
 
        r = PyObject_CallFunction(pdata->start, "si", message, cancelable);
 
371
        r = PyObject_CallFunction(pdata->start, "si", message, cancelable);
325
372
 
326
373
    if (!r) {
327
 
        PyErr_Print();
328
 
        PyErr_Clear();
329
 
        return;
 
374
        PyErr_Print();
 
375
        PyErr_Clear();
 
376
        return;
330
377
    }
331
378
 
332
379
    Py_DECREF(r);
339
386
    PyObject *r;
340
387
 
341
388
    if (pdata->user_data) {
342
 
        r = PyObject_CallFunction(pdata->end, "O", pdata->user_data);
343
 
        Py_DECREF(pdata->user_data);
 
389
        r = PyObject_CallFunction(pdata->end, "O", pdata->user_data);
 
390
        Py_DECREF(pdata->user_data);
344
391
    } else
345
 
        r = PyObject_CallFunction(pdata->end, NULL);
 
392
        r = PyObject_CallFunction(pdata->end, NULL);
346
393
 
347
394
    if (!r) {
348
 
        PyErr_Print();
349
 
        PyErr_Clear();
350
 
        return;
 
395
        PyErr_Print();
 
396
        PyErr_Clear();
 
397
        return;
351
398
    }
352
399
 
353
400
    Py_DECREF(r);
360
407
    PyObject *r;
361
408
 
362
409
    if (pdata->user_data) {
363
 
        r = PyObject_CallFunction(pdata->text, "sO", message, pdata->user_data);
364
 
        Py_DECREF(pdata->user_data);
 
410
        r = PyObject_CallFunction(pdata->text, "sO", message, pdata->user_data);
 
411
        Py_DECREF(pdata->user_data);
365
412
    } else
366
 
        r = PyObject_CallFunction(pdata->text, "s", message);
 
413
        r = PyObject_CallFunction(pdata->text, "s", message);
367
414
 
368
415
    if (!r) {
369
 
        PyErr_Print();
370
 
        PyErr_Clear();
371
 
        return;
 
416
        PyErr_Print();
 
417
        PyErr_Clear();
 
418
        return;
372
419
    }
373
420
 
374
421
    Py_DECREF(r);
381
428
    PyObject *r;
382
429
 
383
430
    if (pdata->user_data) {
384
 
        r = PyObject_CallFunction(pdata->value, "dO", percentage,
385
 
                                  pdata->user_data);
386
 
        Py_DECREF(pdata->user_data);
387
 
    } else 
388
 
        r = PyObject_CallFunction(pdata->value, "d", percentage);
 
431
        r = PyObject_CallFunction(pdata->value, "dO", percentage,
 
432
                                  pdata->user_data);
 
433
        Py_DECREF(pdata->user_data);
 
434
    } else
 
435
        r = PyObject_CallFunction(pdata->value, "d", percentage);
389
436
 
390
437
    if (!r) {
391
 
        PyErr_Print();
392
 
        PyErr_Clear();
393
 
        return;
 
438
        PyErr_Print();
 
439
        PyErr_Clear();
 
440
        return;
394
441
    }
395
442
 
396
443
    Py_DECREF(r);
399
446
static PyObject *
400
447
pygimp_progress_install(PyObject *self, PyObject *args, PyObject *kwargs)
401
448
{
 
449
    GimpProgressVtable vtable = { 0, };
402
450
    const gchar *ret;
403
451
    ProgressData *pdata;
404
452
    static char *kwlist[] = { "start", "end", "text", "value", "data", NULL };
406
454
    pdata = g_new0(ProgressData, 1);
407
455
 
408
456
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOO|O:progress_install",
409
 
                                     kwlist,
410
 
                                     &pdata->start, &pdata->end,
411
 
                                     &pdata->text, &pdata->value,
412
 
                                     &pdata->user_data))
413
 
        goto cleanup;
 
457
                                     kwlist,
 
458
                                     &pdata->start, &pdata->end,
 
459
                                     &pdata->text, &pdata->value,
 
460
                                     &pdata->user_data))
 
461
        goto cleanup;
414
462
 
415
 
#define PROCESS_FUNC(n) G_STMT_START {                                  \
416
 
    if (!PyCallable_Check(pdata->n)) {                                  \
417
 
        PyErr_SetString(pygimp_error, #n "must be a callable");         \
418
 
        goto cleanup;                                                   \
419
 
    }                                                                   \
420
 
    Py_INCREF(pdata->n);                                                \
 
463
#define PROCESS_FUNC(n) G_STMT_START {                                  \
 
464
    if (!PyCallable_Check(pdata->n)) {                                  \
 
465
        PyErr_SetString(pygimp_error, #n "argument must be callable");  \
 
466
        goto cleanup;                                                   \
 
467
    }                                                                   \
 
468
    Py_INCREF(pdata->n);                                                \
421
469
} G_STMT_END
422
470
 
423
471
    PROCESS_FUNC(start);
429
477
 
430
478
#undef PROCESS_FUNC
431
479
 
432
 
    ret = gimp_progress_install(pygimp_progress_start,
433
 
                                pygimp_progress_end,
434
 
                                pygimp_progress_text,
435
 
                                pygimp_progress_value,
436
 
                                pdata);
 
480
    vtable.start     = pygimp_progress_start;
 
481
    vtable.end       = pygimp_progress_end;
 
482
    vtable.set_text  = pygimp_progress_text;
 
483
    vtable.set_value = pygimp_progress_value;
 
484
 
 
485
    ret = gimp_progress_install_vtable(&vtable, pdata);
437
486
 
438
487
    if (!ret) {
439
 
        PyErr_SetString(pygimp_error, "error occurred while installing progress functions");
440
 
 
441
 
        Py_DECREF(pdata->start);
442
 
        Py_DECREF(pdata->end);
443
 
        Py_DECREF(pdata->text);
444
 
        Py_DECREF(pdata->value);
445
 
 
446
 
        goto cleanup;
 
488
        PyErr_SetString(pygimp_error,
 
489
                        "error occurred while installing progress functions");
 
490
 
 
491
        Py_DECREF(pdata->start);
 
492
        Py_DECREF(pdata->end);
 
493
        Py_DECREF(pdata->text);
 
494
        Py_DECREF(pdata->value);
 
495
 
 
496
        goto cleanup;
447
497
    }
448
498
 
449
499
    return PyString_FromString(ret);
460
510
    gchar *callback;
461
511
 
462
512
    if (!PyArg_ParseTuple(args, "s:progress_uninstall", &callback))
463
 
        return NULL;
 
513
        return NULL;
464
514
 
465
515
    pdata = gimp_progress_uninstall(callback);
466
516
 
467
517
    if (!pdata) {
468
 
        PyErr_SetString(pygimp_error, "error occurred while uninstalling progress functions");
469
 
        return NULL;
 
518
        PyErr_SetString(pygimp_error,
 
519
                        "error occurred while uninstalling progress functions");
 
520
        return NULL;
470
521
    }
471
522
 
472
523
    Py_DECREF(pdata->start);
488
539
    gint32 *imgs;
489
540
    int nimgs, i;
490
541
    PyObject *ret;
 
542
 
491
543
    imgs = gimp_image_list(&nimgs);
492
544
    ret = PyList_New(nimgs);
 
545
 
493
546
    for (i = 0; i < nimgs; i++)
494
 
        PyList_SetItem(ret, i, (PyObject *)pygimp_image_new(imgs[i]));
 
547
        PyList_SetItem(ret, i, (PyObject *)pygimp_image_new(imgs[i]));
 
548
 
 
549
    g_free(imgs);
 
550
 
495
551
    return ret;
496
552
}
497
553
 
499
555
pygimp_install_procedure(PyObject *self, PyObject *args)
500
556
{
501
557
    char *name, *blurb, *help, *author, *copyright, *date, *menu_path,
502
 
         *image_types, *n, *d;
 
558
         *image_types, *n, *d;
503
559
    GimpParamDef *params, *return_vals;
504
560
    int type, nparams, nreturn_vals, i;
505
561
    PyObject *pars, *rets;
506
562
 
507
563
    if (!PyArg_ParseTuple(args, "sssssszziOO:install_procedure",
508
 
                          &name, &blurb, &help,
509
 
                          &author, &copyright, &date, &menu_path, &image_types,
510
 
                          &type, &pars, &rets))
511
 
        return NULL;
 
564
                          &name, &blurb, &help,
 
565
                          &author, &copyright, &date, &menu_path, &image_types,
 
566
                          &type, &pars, &rets))
 
567
        return NULL;
 
568
 
512
569
    if (!PySequence_Check(pars) || !PySequence_Check(rets)) {
513
 
        PyErr_SetString(PyExc_TypeError,
514
 
                        "last two args must be sequences");
515
 
        return NULL;
 
570
        PyErr_SetString(PyExc_TypeError, "last two args must be sequences");
 
571
        return NULL;
516
572
    }
 
573
 
517
574
    nparams = PySequence_Length(pars);
518
575
    nreturn_vals = PySequence_Length(rets);
519
576
    params = g_new(GimpParamDef, nparams);
 
577
 
520
578
    for (i = 0; i < nparams; i++) {
521
 
        if (!PyArg_ParseTuple(PySequence_GetItem(pars, i), "iss",
522
 
                              &(params[i].type), &n, &d)) {
523
 
            g_free(params);
524
 
            return NULL;
525
 
        }
526
 
        params[i].name = g_strdup(n);
527
 
        params[i].description = g_strdup(d);
 
579
        if (!PyArg_ParseTuple(PySequence_GetItem(pars, i), "iss",
 
580
                              &(params[i].type), &n, &d)) {
 
581
            g_free(params);
 
582
            return NULL;
 
583
        }
 
584
 
 
585
        params[i].name = g_strdup(n);
 
586
        params[i].description = g_strdup(d);
528
587
    }
 
588
 
529
589
    return_vals = g_new(GimpParamDef, nreturn_vals);
 
590
 
530
591
    for (i = 0; i < nreturn_vals; i++) {
531
 
        if (!PyArg_ParseTuple(PySequence_GetItem(rets, i), "iss",
532
 
                              &(return_vals[i].type), &n, &d)) {
533
 
            g_free(params); g_free(return_vals);
534
 
            return NULL;
535
 
        }
536
 
        return_vals[i].name = g_strdup(n);
537
 
        return_vals[i].description = g_strdup(d);
 
592
        if (!PyArg_ParseTuple(PySequence_GetItem(rets, i), "iss",
 
593
                              &(return_vals[i].type), &n, &d)) {
 
594
            g_free(params); g_free(return_vals);
 
595
            return NULL;
 
596
        }
 
597
 
 
598
        return_vals[i].name = g_strdup(n);
 
599
        return_vals[i].description = g_strdup(d);
538
600
    }
 
601
 
539
602
    gimp_install_procedure(name, blurb, help, author, copyright, date,
540
 
                           menu_path, image_types, type, nparams, nreturn_vals,
541
 
                           params, return_vals);
 
603
                           menu_path, image_types, type, nparams, nreturn_vals,
 
604
                           params, return_vals);
 
605
 
542
606
    Py_INCREF(Py_None);
543
607
    return Py_None;
544
608
}
547
611
pygimp_install_temp_proc(PyObject *self, PyObject *args)
548
612
{
549
613
    char *name, *blurb, *help, *author, *copyright, *date, *menu_path,
550
 
        *image_types, *n, *d;
 
614
        *image_types, *n, *d;
551
615
    GimpParamDef *params, *return_vals;
552
616
    int type, nparams, nreturn_vals, i;
553
617
    PyObject *pars, *rets;
554
618
 
555
619
    if (!PyArg_ParseTuple(args, "sssssszziOO:install_temp_proc",
556
 
                          &name, &blurb, &help,
557
 
                          &author, &copyright, &date, &menu_path, &image_types,
558
 
                          &type, &pars, &rets))
559
 
        return NULL;
 
620
                          &name, &blurb, &help,
 
621
                          &author, &copyright, &date, &menu_path, &image_types,
 
622
                          &type, &pars, &rets))
 
623
        return NULL;
 
624
 
560
625
    if (!PySequence_Check(pars) || !PySequence_Check(rets)) {
561
 
        PyErr_SetString(PyExc_TypeError,
562
 
                        "last two args must be sequences");
563
 
        return NULL;
 
626
        PyErr_SetString(PyExc_TypeError, "last two args must be sequences");
 
627
        return NULL;
564
628
    }
 
629
 
565
630
    nparams = PySequence_Length(pars);
566
631
    nreturn_vals = PySequence_Length(rets);
567
632
    params = g_new(GimpParamDef, nparams);
 
633
 
568
634
    for (i = 0; i < nparams; i++) {
569
 
        if (!PyArg_ParseTuple(PySequence_GetItem(pars, i), "iss",
570
 
                              &(params[i].type), &n, &d)) {
571
 
            g_free(params);
572
 
            return NULL;
573
 
        }
574
 
        params[i].name = g_strdup(n);
575
 
        params[i].description = g_strdup(d);
 
635
        if (!PyArg_ParseTuple(PySequence_GetItem(pars, i), "iss",
 
636
                              &(params[i].type), &n, &d)) {
 
637
            g_free(params);
 
638
            return NULL;
 
639
        }
 
640
 
 
641
        params[i].name = g_strdup(n);
 
642
        params[i].description = g_strdup(d);
576
643
    }
 
644
 
577
645
    return_vals = g_new(GimpParamDef, nreturn_vals);
 
646
 
578
647
    for (i = 0; i < nreturn_vals; i++) {
579
 
        if (!PyArg_ParseTuple(PySequence_GetItem(rets, i), "iss",
580
 
                              &(return_vals[i].type), &n, &d)) {
581
 
            g_free(params); g_free(return_vals);
582
 
            return NULL;
583
 
        }
584
 
        return_vals[i].name = g_strdup(n);
585
 
        return_vals[i].description = g_strdup(d);
 
648
        if (!PyArg_ParseTuple(PySequence_GetItem(rets, i), "iss",
 
649
                              &(return_vals[i].type), &n, &d)) {
 
650
            g_free(params); g_free(return_vals);
 
651
            return NULL;
 
652
        }
 
653
 
 
654
        return_vals[i].name = g_strdup(n);
 
655
        return_vals[i].description = g_strdup(d);
586
656
    }
 
657
 
587
658
    gimp_install_temp_proc(name, blurb, help, author, copyright, date,
588
 
                           menu_path, image_types, type, nparams, nreturn_vals, params,
589
 
                           return_vals, pygimp_run_proc);
 
659
                           menu_path, image_types, type,
 
660
                           nparams, nreturn_vals, params, return_vals,
 
661
                           pygimp_run_proc);
 
662
 
590
663
    Py_INCREF(Py_None);
591
664
    return Py_None;
592
665
}
597
670
    char *name;
598
671
 
599
672
    if (!PyArg_ParseTuple(args, "s:uninstall_temp_proc", &name))
600
 
        return NULL;
 
673
        return NULL;
 
674
 
601
675
    gimp_uninstall_temp_proc(name);
 
676
 
602
677
    Py_INCREF(Py_None);
603
678
    return Py_None;
604
679
}
607
682
pygimp_register_magic_load_handler(PyObject *self, PyObject *args)
608
683
{
609
684
    char *name, *extensions, *prefixes, *magics;
 
685
 
610
686
    if (!PyArg_ParseTuple(args, "ssss:register_magic_load_handler",
611
 
                          &name, &extensions, &prefixes, &magics))
612
 
        return NULL;
 
687
                          &name, &extensions, &prefixes, &magics))
 
688
        return NULL;
 
689
 
613
690
    gimp_register_magic_load_handler(name, extensions, prefixes, magics);
 
691
 
614
692
    Py_INCREF(Py_None);
615
693
    return Py_None;
616
694
}
619
697
pygimp_register_load_handler(PyObject *self, PyObject *args)
620
698
{
621
699
    char *name, *extensions, *prefixes;
 
700
 
622
701
    if (!PyArg_ParseTuple(args, "sss:register_load_handler",
623
 
                          &name, &extensions, &prefixes))
624
 
        return NULL;
 
702
                          &name, &extensions, &prefixes))
 
703
        return NULL;
 
704
 
625
705
    gimp_register_load_handler(name, extensions, prefixes);
 
706
 
626
707
    Py_INCREF(Py_None);
627
708
    return Py_None;
628
709
}
631
712
pygimp_register_save_handler(PyObject *self, PyObject *args)
632
713
{
633
714
    char *name, *extensions, *prefixes;
 
715
 
634
716
    if (!PyArg_ParseTuple(args, "sss:register_save_handler",
635
 
                          &name, &extensions, &prefixes))
636
 
        return NULL;
 
717
                          &name, &extensions, &prefixes))
 
718
        return NULL;
 
719
 
637
720
    gimp_register_save_handler(name, extensions, prefixes);
 
721
 
 
722
    Py_INCREF(Py_None);
 
723
    return Py_None;
 
724
}
 
725
 
 
726
static PyObject *
 
727
pygimp_domain_register(PyObject *self, PyObject *args)
 
728
{
 
729
    char *name, *path = NULL;
 
730
 
 
731
    if (!PyArg_ParseTuple(args, "s|s:domain_register", &name, &path))
 
732
        return NULL;
 
733
 
 
734
    gimp_plugin_domain_register(name, path);
 
735
 
 
736
    Py_INCREF(Py_None);
 
737
    return Py_None;
 
738
}
 
739
 
 
740
static PyObject *
 
741
pygimp_menu_register(PyObject *self, PyObject *args)
 
742
{
 
743
    char *name, *path;
 
744
 
 
745
    if (!PyArg_ParseTuple(args, "ss:menu_register", &name, &path))
 
746
        return NULL;
 
747
 
 
748
    gimp_plugin_menu_register(name, path);
 
749
 
638
750
    Py_INCREF(Py_None);
639
751
    return Py_None;
640
752
}
648
760
static PyObject *
649
761
pygimp_install_cmap(PyObject *self)
650
762
{
651
 
    return PyInt_FromLong(gimp_install_cmap());
 
763
    return PyBool_FromLong(gimp_install_cmap());
 
764
}
 
765
 
 
766
static PyObject *
 
767
pygimp_min_colors(PyObject *self)
 
768
{
 
769
    return PyInt_FromLong(gimp_min_colors());
652
770
}
653
771
 
654
772
static PyObject *
658
776
}
659
777
 
660
778
static PyObject *
 
779
pygimp_personal_rc_file(PyObject *self, PyObject *args, PyObject *kwargs)
 
780
{
 
781
    char *basename, *filename;
 
782
    PyObject *ret;
 
783
 
 
784
    static char *kwlist[] = { "basename", NULL };
 
785
 
 
786
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
787
                                     "s:personal_rc_file", kwlist,
 
788
                                     &basename))
 
789
        return NULL;
 
790
 
 
791
    filename = gimp_personal_rc_file(basename);
 
792
    ret = PyString_FromString(filename);
 
793
    g_free(filename);
 
794
 
 
795
    return ret;
 
796
}
 
797
 
 
798
static PyObject *
 
799
pygimp_context_push(PyObject *self)
 
800
{
 
801
    gimp_context_push();
 
802
    return Py_None;
 
803
}
 
804
 
 
805
static PyObject *
 
806
pygimp_context_pop(PyObject *self)
 
807
{
 
808
    gimp_context_pop();
 
809
    return Py_None;
 
810
}
 
811
 
 
812
static PyObject *
661
813
pygimp_get_background(PyObject *self)
662
814
{
663
 
    GimpRGB colour;
664
 
    guchar r, g, b;
 
815
    GimpRGB rgb;
665
816
 
666
 
    gimp_context_get_background(&colour);
667
 
    gimp_rgb_get_uchar(&colour, &r, &g, &b);
668
 
    return Py_BuildValue("(iii)", (int)r, (int)g, (int)b);
 
817
    gimp_context_get_background(&rgb);
 
818
    return pygimp_rgb_new(&rgb);
669
819
}
670
820
 
671
821
static PyObject *
672
822
pygimp_get_foreground(PyObject *self)
673
823
{
674
 
    GimpRGB colour;
675
 
    guchar r, g, b;
 
824
    GimpRGB rgb;
676
825
 
677
 
    gimp_context_get_foreground(&colour);
678
 
    gimp_rgb_get_uchar(&colour, &r, &g, &b);
679
 
    return Py_BuildValue("(iii)", (int)r, (int)g, (int)b);
 
826
    gimp_context_get_foreground(&rgb);
 
827
    return pygimp_rgb_new(&rgb);
680
828
}
681
829
 
682
830
static PyObject *
683
831
pygimp_set_background(PyObject *self, PyObject *args)
684
832
{
685
 
    GimpRGB colour;
 
833
    PyObject *color;
 
834
    GimpRGB tmprgb, *rgb;
686
835
    int r, g, b;
687
 
    if (!PyArg_ParseTuple(args, "(iii):set_background", &r, &g, &b)) {
688
 
        PyErr_Clear();
689
 
        if (!PyArg_ParseTuple(args, "iii:set_background", &r, &g, &b))
690
 
            return NULL;
691
 
    }
692
 
    r = CLAMP(r, 0, 255);
693
 
    g = CLAMP(g, 0, 255);
694
 
    b = CLAMP(b, 0, 255);
695
 
    gimp_rgb_set_uchar(&colour, r, g, b);
696
 
    gimp_context_set_background(&colour);
 
836
    gboolean compat = FALSE;
 
837
 
 
838
    if (!PyArg_ParseTuple(args, "O!:set_background",
 
839
                          PyGimpRGB_Type, &color)) {
 
840
        PyErr_Clear();
 
841
        compat = TRUE;
 
842
        if (!PyArg_ParseTuple(args, "(iii):set_background", &r, &g, &b)) {
 
843
            PyErr_Clear();
 
844
            if (!PyArg_ParseTuple(args, "iii:set_background", &r, &g, &b)) {
 
845
                PyErr_Clear();
 
846
                PyArg_ParseTuple(args, "O!:set_background",
 
847
                                 PyGimpRGB_Type, &color);
 
848
                return NULL;
 
849
            }
 
850
        }
 
851
    }
 
852
 
 
853
    if (compat) {
 
854
        r = CLAMP(r, 0, 255);
 
855
        g = CLAMP(g, 0, 255);
 
856
        b = CLAMP(b, 0, 255);
 
857
 
 
858
        gimp_rgb_set_uchar(&tmprgb, r, g, b);
 
859
        rgb = &tmprgb;
 
860
    } else {
 
861
        rgb = pyg_boxed_get(color, GimpRGB);
 
862
    }
 
863
 
 
864
    gimp_context_set_background(rgb);
 
865
 
697
866
    Py_INCREF(Py_None);
698
867
    return Py_None;
699
868
}
701
870
static PyObject *
702
871
pygimp_set_foreground(PyObject *self, PyObject *args)
703
872
{
704
 
    GimpRGB colour;
 
873
    PyObject *color;
 
874
    GimpRGB tmprgb, *rgb;
705
875
    int r, g, b;
706
 
    if (!PyArg_ParseTuple(args, "(iii):set_foreground", &r, &g, &b)) {
707
 
        PyErr_Clear();
708
 
        if (!PyArg_ParseTuple(args, "iii:set_foreground", &r, &g, &b))
709
 
            return NULL;
710
 
    }
711
 
    r = CLAMP(r, 0, 255);
712
 
    g = CLAMP(g, 0, 255);
713
 
    b = CLAMP(b, 0, 255);
714
 
    gimp_rgb_set_uchar(&colour, r, g, b);
715
 
    gimp_context_set_foreground(&colour);
 
876
    gboolean compat = FALSE;
 
877
 
 
878
    if (!PyArg_ParseTuple(args, "O!:set_foreground",
 
879
                          PyGimpRGB_Type, &color)) {
 
880
        PyErr_Clear();
 
881
        compat = TRUE;
 
882
        if (!PyArg_ParseTuple(args, "(iii):set_foreground", &r, &g, &b)) {
 
883
            PyErr_Clear();
 
884
            if (!PyArg_ParseTuple(args, "iii:set_foreground", &r, &g, &b)) {
 
885
                PyErr_Clear();
 
886
                PyArg_ParseTuple(args, "O!:set_foreground",
 
887
                                 PyGimpRGB_Type, &color);
 
888
                return NULL;
 
889
            }
 
890
        }
 
891
    }
 
892
 
 
893
    if (compat) {
 
894
        r = CLAMP(r, 0, 255);
 
895
        g = CLAMP(g, 0, 255);
 
896
        b = CLAMP(b, 0, 255);
 
897
 
 
898
        gimp_rgb_set_uchar(&tmprgb, r, g, b);
 
899
        rgb = &tmprgb;
 
900
    } else {
 
901
        rgb = pyg_boxed_get(color, GimpRGB);
 
902
    }
 
903
 
 
904
    gimp_context_set_foreground(rgb);
 
905
 
716
906
    Py_INCREF(Py_None);
717
907
    return Py_None;
718
908
}
719
909
 
720
910
static PyObject *
721
 
pygimp_gradients_get_list(PyObject *self)
 
911
pygimp_gradients_get_list(PyObject *self, PyObject *args, PyObject *kwargs)
722
912
{
723
 
    char **list;
 
913
    char **list, *filter = NULL;
724
914
    int num, i;
725
915
    PyObject *ret;
726
916
 
727
 
    list = gimp_gradients_get_list(NULL, &num);
 
917
    static char *kwlist[] = { "filter", NULL };
 
918
 
 
919
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
920
                                     "|s:gradients_get_list", kwlist,
 
921
                                     &filter))
 
922
        return NULL;
 
923
 
 
924
    list = gimp_gradients_get_list(filter, &num);
 
925
 
728
926
    ret = PyList_New(num);
729
 
    for (i = 0; i < num; i++)
730
 
        PyList_SetItem(ret, i, PyString_FromString(list[i]));
 
927
 
 
928
    for (i = 0; i < num; i++) {
 
929
        PyList_SetItem(ret, i, PyString_FromString(list[i]));
 
930
        g_free(list[i]);
 
931
    }
 
932
 
731
933
    g_free(list);
 
934
 
732
935
    return ret;
733
936
}
734
937
 
760
963
    char *actv;
761
964
 
762
965
    if (!PyArg_ParseTuple(args, "s:gradients_set_gradient", &actv))
763
 
        return NULL;
 
966
        return NULL;
764
967
 
765
968
    gimp_context_set_gradient(actv);
766
969
 
787
990
    int i, j;
788
991
    PyObject *ret;
789
992
 
790
 
    if (!PyArg_ParseTuple(args, "si|i:gradient_get_uniform_samples", &name, &num, &reverse))
791
 
        return NULL;
 
993
    if (!PyArg_ParseTuple(args, "si|i:gradient_get_uniform_samples",
 
994
                          &name, &num, &reverse))
 
995
        return NULL;
792
996
 
793
997
    if (!gimp_gradient_get_uniform_samples(name, num, reverse, &nsamp, &samp)) {
794
 
        PyErr_SetString(pygimp_error, "gradient_get_uniform_samples failed");
795
 
        return NULL;
 
998
        PyErr_SetString(pygimp_error, "gradient_get_uniform_samples failed");
 
999
        return NULL;
796
1000
    }
797
1001
 
798
1002
    ret = PyList_New(num);
799
1003
    for (i = 0, j = 0; i < num; i++, j += 4)
800
 
        PyList_SetItem(ret, i, Py_BuildValue("(dddd)", samp[j],
801
 
                                             samp[j+1], samp[j+2], samp[j+3]));
 
1004
        PyList_SetItem(ret, i, Py_BuildValue("(dddd)", samp[j],
 
1005
                                             samp[j+1], samp[j+2], samp[j+3]));
802
1006
 
803
1007
    g_free(samp);
804
1008
 
816
1020
    PyObject *ret, *item;
817
1021
    gboolean success;
818
1022
 
819
 
    if (!PyArg_ParseTuple(args, "sO|i:gradient_get_uniform_samples", &name, &ret, &reverse))
820
 
        return NULL;
 
1023
    if (!PyArg_ParseTuple(args, "sO|i:gradient_get_custom_samples",
 
1024
                          &name, &ret, &reverse))
 
1025
        return NULL;
821
1026
 
822
1027
    if (!PySequence_Check(ret)) {
823
 
        PyErr_SetString(PyExc_TypeError,
824
 
                        "second arg must be a sequence");
825
 
        return NULL;
 
1028
        PyErr_SetString(PyExc_TypeError,
 
1029
                        "second arg must be a sequence");
 
1030
        return NULL;
826
1031
    }
827
1032
 
828
1033
    num = PySequence_Length(ret);
829
1034
    pos = g_new(gdouble, num);
830
1035
 
831
1036
    for (i = 0; i < num; i++) {
832
 
        item = PySequence_GetItem(ret, i);
833
 
 
834
 
        if (!PyFloat_Check(item)) {
835
 
            PyErr_SetString(PyExc_TypeError,
836
 
                            "second arg must be a sequence of floats");
837
 
            g_free(pos);
838
 
            return NULL;
839
 
        }
840
 
 
841
 
        pos[i] = PyFloat_AsDouble(item);
 
1037
        item = PySequence_GetItem(ret, i);
 
1038
 
 
1039
        if (!PyFloat_Check(item)) {
 
1040
            PyErr_SetString(PyExc_TypeError,
 
1041
                            "second arg must be a sequence of floats");
 
1042
            g_free(pos);
 
1043
            return NULL;
 
1044
        }
 
1045
 
 
1046
        pos[i] = PyFloat_AsDouble(item);
842
1047
    }
843
1048
 
844
1049
    success = gimp_gradient_get_custom_samples(name, num, pos, reverse,
845
 
                                               &nsamp, &samp);
 
1050
                                               &nsamp, &samp);
846
1051
    g_free(pos);
847
1052
 
848
1053
    if (!success) {
849
 
        PyErr_SetString(pygimp_error, "gradient_get_custom_samples failed");
850
 
        return NULL;
 
1054
        PyErr_SetString(pygimp_error, "gradient_get_custom_samples failed");
 
1055
        return NULL;
851
1056
    }
852
1057
 
853
1058
    ret = PyList_New(num);
854
1059
    for (i = 0, j = 0; i < num; i++, j += 4)
855
 
        PyList_SetItem(ret, i, Py_BuildValue("(dddd)", samp[j],
856
 
                                             samp[j+1], samp[j+2], samp[j+3]));
 
1060
        PyList_SetItem(ret, i, Py_BuildValue("(dddd)", samp[j],
 
1061
                                             samp[j+1], samp[j+2], samp[j+3]));
857
1062
 
858
1063
    g_free(samp);
859
1064
 
866
1071
    char *name;
867
1072
    PyObject *arg_list, *str, *new_args, *ret;
868
1073
 
869
 
    if (PyErr_Warn(PyExc_DeprecationWarning, "use gimp.gradient_get_uniform_samples") < 0)
 
1074
    if (PyErr_Warn(PyExc_DeprecationWarning,
 
1075
                   "use gimp.gradient_get_uniform_samples") < 0)
870
1076
        return NULL;
871
1077
 
872
1078
    arg_list = PySequence_List(args);
894
1100
    char *name;
895
1101
    PyObject *arg_list, *str, *new_args, *ret;
896
1102
 
897
 
    if (PyErr_Warn(PyExc_DeprecationWarning, "use gimp.gradient_get_custom_samples") < 0)
 
1103
    if (PyErr_Warn(PyExc_DeprecationWarning,
 
1104
                   "use gimp.gradient_get_custom_samples") < 0)
898
1105
        return NULL;
899
1106
 
900
1107
    arg_list = PySequence_List(args);
921
1128
    PyGimpImage *img;
922
1129
 
923
1130
    if (!PyArg_ParseTuple(args, "O:delete", &img))
924
 
        return NULL;
925
 
    if (pygimp_image_check(img)) gimp_image_delete(img->ID);
926
 
    else if (pygimp_drawable_check(img)) gimp_drawable_delete(img->ID);
927
 
    else if (pygimp_display_check(img)) gimp_display_delete(img->ID);
 
1131
        return NULL;
 
1132
 
 
1133
    if (pygimp_image_check(img))
 
1134
        gimp_image_delete(img->ID);
 
1135
    else if (pygimp_drawable_check(img))
 
1136
        gimp_drawable_delete(img->ID);
 
1137
    else if (pygimp_display_check(img))
 
1138
        gimp_display_delete(img->ID);
 
1139
 
928
1140
    Py_INCREF(Py_None);
929
1141
    return Py_None;
930
1142
}
934
1146
pygimp_displays_flush(PyObject *self)
935
1147
{
936
1148
    gimp_displays_flush();
937
 
    Py_INCREF(Py_None);
938
 
    return Py_None;
939
 
}
940
 
 
 
1149
 
 
1150
    Py_INCREF(Py_None);
 
1151
    return Py_None;
 
1152
}
 
1153
 
 
1154
static PyObject *
 
1155
pygimp_displays_reconnect(PyObject *self, PyObject *args)
 
1156
{
 
1157
    PyGimpImage *old_img, *new_img;
 
1158
 
 
1159
    if (!PyArg_ParseTuple(args, "O!O!:displays_reconnect",
 
1160
                          &PyGimpImage_Type, &old_img,
 
1161
                          &PyGimpImage_Type, &new_img))
 
1162
        return NULL;
 
1163
 
 
1164
    if (!gimp_displays_reconnect (old_img->ID, new_img->ID)) {
 
1165
        PyErr_Format(pygimp_error,
 
1166
                     "could not reconnect the displays of image (ID %d) "
 
1167
                     "to image (ID %d)",
 
1168
                     old_img->ID, new_img->ID);
 
1169
        return NULL;
 
1170
    }
 
1171
 
 
1172
    Py_INCREF(Py_None);
 
1173
    return Py_None;
 
1174
}
941
1175
 
942
1176
static PyObject *
943
1177
pygimp_tile_cache_size(PyObject *self, PyObject *args)
944
1178
{
945
1179
    unsigned long k;
 
1180
 
946
1181
    if (!PyArg_ParseTuple(args, "l:tile_cache_size", &k))
947
 
        return NULL;
 
1182
        return NULL;
 
1183
 
948
1184
    gimp_tile_cache_size(k);
 
1185
 
949
1186
    Py_INCREF(Py_None);
950
1187
    return Py_None;
951
1188
}
955
1192
pygimp_tile_cache_ntiles(PyObject *self, PyObject *args)
956
1193
{
957
1194
    unsigned long n;
 
1195
 
958
1196
    if (!PyArg_ParseTuple(args, "l:tile_cache_ntiles", &n))
959
 
        return NULL;
 
1197
        return NULL;
 
1198
 
960
1199
    gimp_tile_cache_ntiles(n);
 
1200
 
961
1201
    Py_INCREF(Py_None);
962
1202
    return Py_None;
963
1203
}
980
1220
pygimp_extension_ack(PyObject *self)
981
1221
{
982
1222
    gimp_extension_ack();
 
1223
 
983
1224
    Py_INCREF(Py_None);
984
1225
    return Py_None;
985
1226
}
988
1229
pygimp_extension_enable(PyObject *self)
989
1230
{
990
1231
    gimp_extension_enable();
 
1232
 
991
1233
    Py_INCREF(Py_None);
992
1234
    return Py_None;
993
1235
}
997
1239
{
998
1240
    guint timeout;
999
1241
 
1000
 
    if (!PyArg_ParseTuple(args, ARG_UINT_FORMAT ":extension_process", &timeout))
1001
 
        return NULL;
 
1242
    if (!PyArg_ParseTuple(args, "I:extension_process", &timeout))
 
1243
        return NULL;
 
1244
 
1002
1245
    gimp_extension_process(timeout);
 
1246
 
1003
1247
    Py_INCREF(Py_None);
1004
1248
    return Py_None;
1005
1249
}
1008
1252
pygimp_parasite_find(PyObject *self, PyObject *args)
1009
1253
{
1010
1254
    char *name;
 
1255
 
1011
1256
    if (!PyArg_ParseTuple(args, "s:parasite_find", &name))
1012
 
        return NULL;
 
1257
        return NULL;
 
1258
 
1013
1259
    return pygimp_parasite_new(gimp_parasite_find(name));
1014
1260
}
1015
1261
 
1017
1263
pygimp_parasite_attach(PyObject *self, PyObject *args)
1018
1264
{
1019
1265
    PyGimpParasite *parasite;
 
1266
 
1020
1267
    if (!PyArg_ParseTuple(args, "O!:parasite_attach",
1021
 
                          &PyGimpParasite_Type, &parasite))
1022
 
        return NULL;
1023
 
    gimp_parasite_attach(parasite->para);
 
1268
                          &PyGimpParasite_Type, &parasite))
 
1269
        return NULL;
 
1270
 
 
1271
    if (!gimp_parasite_attach(parasite->para)) {
 
1272
        PyErr_Format(pygimp_error, "could not attach parasite '%s'",
 
1273
                     gimp_parasite_name(parasite->para));
 
1274
        return NULL;
 
1275
    }
 
1276
 
1024
1277
    Py_INCREF(Py_None);
1025
1278
    return Py_None;
1026
1279
}
1030
1283
{
1031
1284
    char *name, *data;
1032
1285
    int flags, size;
 
1286
 
1033
1287
    if (!PyArg_ParseTuple(args, "sis#:attach_new_parasite", &name, &flags,
1034
 
                          &data, &size))
1035
 
        return NULL;
1036
 
    gimp_attach_new_parasite(name, flags, size, data);
 
1288
                          &data, &size))
 
1289
        return NULL;
 
1290
 
 
1291
    if (!gimp_attach_new_parasite(name, flags, size, data)) {
 
1292
        PyErr_Format(pygimp_error, "could not attach new parasite '%s'", name);
 
1293
        return NULL;
 
1294
    }
 
1295
 
1037
1296
    Py_INCREF(Py_None);
1038
1297
    return Py_None;
1039
1298
}
1042
1301
pygimp_parasite_detach(PyObject *self, PyObject *args)
1043
1302
{
1044
1303
    char *name;
 
1304
 
1045
1305
    if (!PyArg_ParseTuple(args, "s:parasite_detach", &name))
1046
 
        return NULL;
1047
 
    gimp_parasite_detach(name);
 
1306
        return NULL;
 
1307
 
 
1308
    if (!gimp_parasite_detach(name)) {
 
1309
        PyErr_Format(pygimp_error, "could not detach parasite '%s'", name);
 
1310
        return NULL;
 
1311
    }
 
1312
 
1048
1313
    Py_INCREF(Py_None);
1049
1314
    return Py_None;
1050
1315
}
1056
1321
    gchar **parasites;
1057
1322
 
1058
1323
    if (gimp_parasite_list(&num_parasites, &parasites)) {
1059
 
        PyObject *ret;
1060
 
        gint i;
1061
 
 
1062
 
        ret = PyTuple_New(num_parasites);
1063
 
        for (i = 0; i < num_parasites; i++) {
1064
 
            PyTuple_SetItem(ret, i, PyString_FromString(parasites[i]));
1065
 
            g_free(parasites[i]);
1066
 
        }
1067
 
        g_free(parasites);
1068
 
        return ret;
 
1324
        PyObject *ret;
 
1325
        gint i;
 
1326
 
 
1327
        ret = PyTuple_New(num_parasites);
 
1328
 
 
1329
        for (i = 0; i < num_parasites; i++) {
 
1330
            PyTuple_SetItem(ret, i, PyString_FromString(parasites[i]));
 
1331
            g_free(parasites[i]);
 
1332
        }
 
1333
 
 
1334
        g_free(parasites);
 
1335
        return ret;
1069
1336
    }
 
1337
 
1070
1338
    PyErr_SetString(pygimp_error, "could not list parasites");
1071
1339
    return NULL;
1072
1340
}
1073
1341
 
1074
1342
static PyObject *
 
1343
pygimp_show_tool_tips(PyObject *self)
 
1344
{
 
1345
    return PyBool_FromLong(gimp_show_tool_tips());
 
1346
}
 
1347
 
 
1348
static PyObject *
 
1349
pygimp_show_help_button(PyObject *self)
 
1350
{
 
1351
    return PyBool_FromLong(gimp_show_help_button());
 
1352
}
 
1353
 
 
1354
static PyObject *
 
1355
pygimp_check_size(PyObject *self)
 
1356
{
 
1357
    return PyInt_FromLong(gimp_check_size());
 
1358
}
 
1359
 
 
1360
static PyObject *
 
1361
pygimp_check_type(PyObject *self)
 
1362
{
 
1363
    return PyInt_FromLong(gimp_check_type());
 
1364
}
 
1365
 
 
1366
static PyObject *
1075
1367
pygimp_default_display(PyObject *self)
1076
1368
{
1077
1369
    return pygimp_display_new(gimp_default_display());
1078
1370
}
1079
1371
 
1080
1372
static PyObject *
 
1373
pygimp_wm_class(PyObject *self)
 
1374
{
 
1375
    return PyString_FromString(gimp_wm_class());
 
1376
}
 
1377
 
 
1378
static PyObject *
 
1379
pygimp_display_name(PyObject *self)
 
1380
{
 
1381
    return PyString_FromString(gimp_display_name());
 
1382
}
 
1383
 
 
1384
static PyObject *
 
1385
pygimp_monitor_number(PyObject *self)
 
1386
{
 
1387
    return PyInt_FromLong(gimp_monitor_number());
 
1388
}
 
1389
 
 
1390
static PyObject *
 
1391
pygimp_get_progname(PyObject *self)
 
1392
{
 
1393
    return PyString_FromString(gimp_get_progname());
 
1394
}
 
1395
 
 
1396
static PyObject *
 
1397
pygimp_fonts_refresh(PyObject *self)
 
1398
{
 
1399
    if (!gimp_fonts_refresh()) {
 
1400
        PyErr_SetString(pygimp_error, "could not refresh fonts");
 
1401
        return NULL;
 
1402
    }
 
1403
 
 
1404
    Py_INCREF(Py_None);
 
1405
    return Py_None;
 
1406
}
 
1407
 
 
1408
static PyObject *
 
1409
pygimp_checks_get_shades(PyObject *self, PyObject *args, PyObject *kwargs)
 
1410
{
 
1411
    int type;
 
1412
    guchar light, dark;
 
1413
    static char *kwlist[] = { "type", NULL };
 
1414
 
 
1415
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
1416
                                     "i:checks_get_shades", kwlist,
 
1417
                                     &type))
 
1418
        return NULL;
 
1419
 
 
1420
    if (type < GIMP_CHECK_TYPE_LIGHT_CHECKS ||
 
1421
        type > GIMP_CHECK_TYPE_BLACK_ONLY) {
 
1422
        PyErr_SetString(PyExc_ValueError, "Invalid check type");
 
1423
        return NULL;
 
1424
    }
 
1425
 
 
1426
    gimp_checks_get_shades(type, &light, &dark);
 
1427
 
 
1428
    return Py_BuildValue("(ii)", light, dark);
 
1429
}
 
1430
 
 
1431
static PyObject *
 
1432
pygimp_fonts_get_list(PyObject *self, PyObject *args, PyObject *kwargs)
 
1433
{
 
1434
    char **list, *filter = NULL;
 
1435
    int num, i;
 
1436
    PyObject *ret;
 
1437
 
 
1438
    static char *kwlist[] = { "filter", NULL };
 
1439
 
 
1440
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
1441
                                     "|s:fonts_get_list", kwlist,
 
1442
                                     &filter))
 
1443
        return NULL;
 
1444
 
 
1445
    list = gimp_fonts_get_list(filter, &num);
 
1446
 
 
1447
    if (num == 0) {
 
1448
        PyErr_SetString(pygimp_error, "could not get font list");
 
1449
        return NULL;
 
1450
    }
 
1451
 
 
1452
    ret = PyList_New(num);
 
1453
 
 
1454
    for (i = 0; i < num; i++) {
 
1455
        PyList_SetItem(ret, i, PyString_FromString(list[i]));
 
1456
        g_free(list[i]);
 
1457
    }
 
1458
 
 
1459
    g_free(list);
 
1460
 
 
1461
    return ret;
 
1462
}
 
1463
 
 
1464
static PyObject *
 
1465
vectors_to_objects(int num_vectors, int *vectors)
 
1466
{
 
1467
    PyObject *ret;
 
1468
    int i;
 
1469
 
 
1470
    ret = PyList_New(num_vectors);
 
1471
    if (ret == NULL)
 
1472
        goto done;
 
1473
 
 
1474
    for (i = 0; i < num_vectors; i++)
 
1475
        PyList_SetItem(ret, i, pygimp_vectors_new(vectors[i]));
 
1476
 
 
1477
done:
 
1478
    g_free(vectors);
 
1479
    return ret;
 
1480
}
 
1481
 
 
1482
static PyObject *
 
1483
pygimp_vectors_import_from_file(PyObject *self, PyObject *args, PyObject *kwargs)
 
1484
{
 
1485
    PyGimpImage *img;
 
1486
    PyObject *py_file;
 
1487
    gboolean merge = FALSE, scale = FALSE;
 
1488
    int *vectors, num_vectors;
 
1489
    gboolean success;
 
1490
 
 
1491
    static char *kwlist[] = { "image", "svg_file", "merge", "scale", NULL };
 
1492
 
 
1493
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
1494
                                     "O!O|ii:vectors_import_from_file", kwlist,
 
1495
                                     &PyGimpImage_Type, &img, &py_file,
 
1496
                                     &merge, &scale))
 
1497
        return NULL;
 
1498
 
 
1499
    if (PyString_Check(py_file)) {
 
1500
        success = gimp_vectors_import_from_file(img->ID,
 
1501
                                                PyString_AsString(py_file),
 
1502
                                                merge, scale,
 
1503
                                                &num_vectors, &vectors);
 
1504
    } else {
 
1505
        PyObject *chunk_size, *buffer, *read_method;
 
1506
 
 
1507
        chunk_size = PyInt_FromLong(16 * 1024);
 
1508
        if (chunk_size == NULL)
 
1509
            return NULL;
 
1510
 
 
1511
        buffer = PyString_FromString("");
 
1512
        if (buffer == NULL) {
 
1513
            Py_DECREF(chunk_size);
 
1514
            return NULL;
 
1515
        }
 
1516
 
 
1517
        read_method = PyString_FromString("read");
 
1518
        if (read_method == NULL || !PyCallable_Check(read_method)) {
 
1519
            Py_XDECREF(read_method);
 
1520
            PyErr_SetString(PyExc_TypeError,
 
1521
                            "svg_file must be an object that has a \"read\" "
 
1522
                            "method, or a filename (str)");   
 
1523
            return NULL;
 
1524
        }
 
1525
 
 
1526
        while (1) {
 
1527
            PyObject *chunk;
 
1528
            chunk = PyObject_CallMethodObjArgs(py_file, read_method,
 
1529
                                               chunk_size, NULL);
 
1530
 
 
1531
            if (!chunk || !PyString_Check(chunk)) {
 
1532
                Py_XDECREF(chunk);
 
1533
                Py_DECREF(chunk_size);
 
1534
                Py_DECREF(buffer);
 
1535
                Py_DECREF(read_method);
 
1536
                return NULL;
 
1537
            }
 
1538
 
 
1539
            if (PyString_GET_SIZE(chunk) != 0) {
 
1540
                PyString_ConcatAndDel(&buffer, chunk);
 
1541
                if (buffer == NULL) {
 
1542
                    Py_DECREF(chunk_size);
 
1543
                    Py_DECREF(read_method);
 
1544
                    return NULL;
 
1545
                }
 
1546
            } else {
 
1547
                Py_DECREF(chunk);
 
1548
                break;
 
1549
            }
 
1550
        }
 
1551
 
 
1552
        success = gimp_vectors_import_from_string(img->ID,
 
1553
                                                  PyString_AsString(buffer),
 
1554
                                                  PyString_Size(buffer),
 
1555
                                                  merge, scale,
 
1556
                                                  &num_vectors, &vectors);
 
1557
 
 
1558
        Py_DECREF(chunk_size);
 
1559
        Py_DECREF(buffer);
 
1560
        Py_DECREF(read_method);
 
1561
    }
 
1562
 
 
1563
    if (!success) {
 
1564
        PyErr_SetString(pygimp_error, "Vectors import failed");
 
1565
        return NULL;
 
1566
    }
 
1567
 
 
1568
    return vectors_to_objects(num_vectors, vectors);
 
1569
}
 
1570
 
 
1571
static PyObject *
 
1572
pygimp_vectors_import_from_string(PyObject *self, PyObject *args, PyObject *kwargs)
 
1573
{
 
1574
    PyGimpImage *img;
 
1575
    const char *svg_string;
 
1576
    int length;
 
1577
    gboolean merge = FALSE, scale = FALSE;
 
1578
    int *vectors, num_vectors;
 
1579
    gboolean success;
 
1580
 
 
1581
    static char *kwlist[] = { "image", "svg_string", "merge", "scale", NULL };
 
1582
 
 
1583
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
1584
                                     "O!s#|ii:vectors_import_from_string", kwlist,
 
1585
                                     &PyGimpImage_Type, &img,
 
1586
                                     &svg_string, &length,
 
1587
                                     &merge, &scale))
 
1588
        return NULL;
 
1589
 
 
1590
    success = gimp_vectors_import_from_string(img->ID, svg_string, length,
 
1591
                                              merge, scale,
 
1592
                                              &num_vectors, &vectors);
 
1593
 
 
1594
    if (!success) {
 
1595
        PyErr_SetString(pygimp_error, "Vectors import failed");
 
1596
        return NULL;
 
1597
    }
 
1598
 
 
1599
    return vectors_to_objects(num_vectors, vectors);
 
1600
}
 
1601
 
 
1602
static PyObject *
1081
1603
id2image(PyObject *self, PyObject *args)
1082
1604
{
1083
1605
    int id;
 
1606
 
1084
1607
    if (!PyArg_ParseTuple(args, "i:_id2image", &id))
1085
 
        return NULL;
 
1608
        return NULL;
 
1609
 
1086
1610
    if (id >= 0)
1087
 
        return pygimp_image_new(id);
 
1611
        return pygimp_image_new(id);
 
1612
 
1088
1613
    Py_INCREF(Py_None);
1089
1614
    return Py_None;
1090
1615
}
1093
1618
id2drawable(PyObject *self, PyObject *args)
1094
1619
{
1095
1620
    int id;
 
1621
 
1096
1622
    if (!PyArg_ParseTuple(args, "i:_id2drawable", &id))
1097
 
        return NULL;
 
1623
        return NULL;
 
1624
 
1098
1625
    if (id >= 0)
1099
 
        return pygimp_drawable_new(NULL, id);
 
1626
        return pygimp_drawable_new(NULL, id);
 
1627
 
1100
1628
    Py_INCREF(Py_None);
1101
1629
    return Py_None;
1102
1630
}
1105
1633
id2display(PyObject *self, PyObject *args)
1106
1634
{
1107
1635
    int id;
 
1636
 
1108
1637
    if (!PyArg_ParseTuple(args, "i:_id2display", &id))
1109
 
        return NULL;
1110
 
    if (id >= 0)
1111
 
        return pygimp_display_new(id);
 
1638
        return NULL;
 
1639
 
 
1640
    if (id >= 0)
 
1641
        return pygimp_display_new(id);
 
1642
 
 
1643
    Py_INCREF(Py_None);
 
1644
    return Py_None;
 
1645
}
 
1646
 
 
1647
static PyObject *
 
1648
id2vectors(PyObject *self, PyObject *args)
 
1649
{
 
1650
    int id;
 
1651
 
 
1652
    if (!PyArg_ParseTuple(args, "i:_id2vectors", &id))
 
1653
        return NULL;
 
1654
 
 
1655
    if (id >= 0)
 
1656
        return pygimp_vectors_new(id);
 
1657
 
1112
1658
    Py_INCREF(Py_None);
1113
1659
    return Py_None;
1114
1660
}
1116
1662
/* List of methods defined in the module */
1117
1663
 
1118
1664
static struct PyMethodDef gimp_methods[] = {
1119
 
    {"main",    (PyCFunction)pygimp_main,       METH_VARARGS},
1120
 
    {"quit",    (PyCFunction)pygimp_quit,       METH_NOARGS},
1121
 
    {"message", (PyCFunction)pygimp_message,    METH_VARARGS},
1122
 
    {"set_data",        (PyCFunction)pygimp_set_data,   METH_VARARGS},
1123
 
    {"get_data",        (PyCFunction)pygimp_get_data,   METH_VARARGS},
1124
 
    {"progress_init",   (PyCFunction)pygimp_progress_init,      METH_VARARGS},
1125
 
    {"progress_update", (PyCFunction)pygimp_progress_update,    METH_VARARGS},
1126
 
    {"progress_install",        (PyCFunction)pygimp_progress_install,   METH_VARARGS | METH_KEYWORDS},
1127
 
    {"progress_uninstall",      (PyCFunction)pygimp_progress_uninstall, METH_VARARGS},
1128
 
    {"image_list",      (PyCFunction)pygimp_image_list, METH_NOARGS},
1129
 
    {"install_procedure",       (PyCFunction)pygimp_install_procedure,  METH_VARARGS},
1130
 
    {"install_temp_proc",       (PyCFunction)pygimp_install_temp_proc,  METH_VARARGS},
1131
 
    {"uninstall_temp_proc",     (PyCFunction)pygimp_uninstall_temp_proc,        METH_VARARGS},
1132
 
    {"register_magic_load_handler",     (PyCFunction)pygimp_register_magic_load_handler,        METH_VARARGS},
1133
 
    {"register_load_handler",   (PyCFunction)pygimp_register_load_handler,      METH_VARARGS},
1134
 
    {"register_save_handler",   (PyCFunction)pygimp_register_save_handler,      METH_VARARGS},
1135
 
    {"gamma",   (PyCFunction)pygimp_gamma,      METH_NOARGS},
1136
 
    {"install_cmap",    (PyCFunction)pygimp_install_cmap,       METH_NOARGS},
1137
 
    {"gtkrc",   (PyCFunction)pygimp_gtkrc,      METH_NOARGS},
1138
 
    {"get_background",  (PyCFunction)pygimp_get_background,     METH_NOARGS},
1139
 
    {"get_foreground",  (PyCFunction)pygimp_get_foreground,     METH_NOARGS},
1140
 
    {"set_background",  (PyCFunction)pygimp_set_background,     METH_VARARGS},
1141
 
    {"set_foreground",  (PyCFunction)pygimp_set_foreground,     METH_VARARGS},
1142
 
    {"gradients_get_list",      (PyCFunction)pygimp_gradients_get_list, METH_NOARGS},
1143
 
    {"context_get_gradient",    (PyCFunction)pygimp_context_get_gradient,       METH_NOARGS},
1144
 
    {"context_set_gradient",    (PyCFunction)pygimp_context_set_gradient,       METH_VARARGS},
1145
 
    {"gradients_get_gradient",  (PyCFunction)pygimp_gradients_get_gradient,     METH_NOARGS},
1146
 
    {"gradients_set_gradient",  (PyCFunction)pygimp_gradients_set_gradient,     METH_VARARGS},
1147
 
    {"gradient_get_uniform_samples",    (PyCFunction)pygimp_gradient_get_uniform_samples,       METH_VARARGS},
1148
 
    {"gradient_get_custom_samples",     (PyCFunction)pygimp_gradient_get_custom_samples,        METH_VARARGS},
1149
 
    {"gradients_sample_uniform",        (PyCFunction)pygimp_gradients_sample_uniform,   METH_VARARGS},
1150
 
    {"gradients_sample_custom", (PyCFunction)pygimp_gradients_sample_custom,    METH_VARARGS},
 
1665
    {"main",    (PyCFunction)pygimp_main,       METH_VARARGS},
 
1666
    {"quit",    (PyCFunction)pygimp_quit,       METH_NOARGS},
 
1667
    {"message", (PyCFunction)pygimp_message,    METH_VARARGS},
 
1668
    {"set_data",        (PyCFunction)pygimp_set_data,   METH_VARARGS},
 
1669
    {"get_data",        (PyCFunction)pygimp_get_data,   METH_VARARGS},
 
1670
    {"progress_init",   (PyCFunction)pygimp_progress_init,      METH_VARARGS},
 
1671
    {"progress_update", (PyCFunction)pygimp_progress_update,    METH_VARARGS},
 
1672
    {"progress_install",        (PyCFunction)pygimp_progress_install,   METH_VARARGS | METH_KEYWORDS},
 
1673
    {"progress_uninstall",      (PyCFunction)pygimp_progress_uninstall, METH_VARARGS},
 
1674
    {"image_list",      (PyCFunction)pygimp_image_list, METH_NOARGS},
 
1675
    {"install_procedure",       (PyCFunction)pygimp_install_procedure,  METH_VARARGS},
 
1676
    {"install_temp_proc",       (PyCFunction)pygimp_install_temp_proc,  METH_VARARGS},
 
1677
    {"uninstall_temp_proc",     (PyCFunction)pygimp_uninstall_temp_proc,        METH_VARARGS},
 
1678
    {"register_magic_load_handler",     (PyCFunction)pygimp_register_magic_load_handler,        METH_VARARGS},
 
1679
    {"register_load_handler",   (PyCFunction)pygimp_register_load_handler,      METH_VARARGS},
 
1680
    {"register_save_handler",   (PyCFunction)pygimp_register_save_handler,      METH_VARARGS},
 
1681
    {"domain_register",         (PyCFunction)pygimp_domain_register,    METH_VARARGS},
 
1682
    {"menu_register",           (PyCFunction)pygimp_menu_register,      METH_VARARGS},
 
1683
    {"gamma",   (PyCFunction)pygimp_gamma,      METH_NOARGS},
 
1684
    {"install_cmap",    (PyCFunction)pygimp_install_cmap,       METH_NOARGS},
 
1685
    {"min_colors",      (PyCFunction)pygimp_min_colors, METH_NOARGS},
 
1686
    {"gtkrc",   (PyCFunction)pygimp_gtkrc,      METH_NOARGS},
 
1687
    {"personal_rc_file",        (PyCFunction)pygimp_personal_rc_file, METH_VARARGS | METH_KEYWORDS},
 
1688
    {"context_push", (PyCFunction)pygimp_context_push, METH_NOARGS},
 
1689
    {"context_pop", (PyCFunction)pygimp_context_pop, METH_NOARGS},
 
1690
    {"get_foreground",  (PyCFunction)pygimp_get_foreground,     METH_NOARGS},
 
1691
    {"get_background",  (PyCFunction)pygimp_get_background,     METH_NOARGS},
 
1692
    {"get_foreground",  (PyCFunction)pygimp_get_foreground,     METH_NOARGS},
 
1693
    {"set_background",  (PyCFunction)pygimp_set_background,     METH_VARARGS},
 
1694
    {"set_foreground",  (PyCFunction)pygimp_set_foreground,     METH_VARARGS},
 
1695
    {"gradients_get_list",      (PyCFunction)pygimp_gradients_get_list, METH_VARARGS | METH_KEYWORDS},
 
1696
    {"context_get_gradient",    (PyCFunction)pygimp_context_get_gradient,       METH_NOARGS},
 
1697
    {"context_set_gradient",    (PyCFunction)pygimp_context_set_gradient,       METH_VARARGS},
 
1698
    {"gradients_get_gradient",  (PyCFunction)pygimp_gradients_get_gradient,     METH_NOARGS},
 
1699
    {"gradients_set_gradient",  (PyCFunction)pygimp_gradients_set_gradient,     METH_VARARGS},
 
1700
    {"gradient_get_uniform_samples",    (PyCFunction)pygimp_gradient_get_uniform_samples,       METH_VARARGS},
 
1701
    {"gradient_get_custom_samples",     (PyCFunction)pygimp_gradient_get_custom_samples,        METH_VARARGS},
 
1702
    {"gradients_sample_uniform",        (PyCFunction)pygimp_gradients_sample_uniform,   METH_VARARGS},
 
1703
    {"gradients_sample_custom", (PyCFunction)pygimp_gradients_sample_custom,    METH_VARARGS},
1151
1704
    {"delete", (PyCFunction)pygimp_delete, METH_VARARGS},
1152
1705
    {"displays_flush", (PyCFunction)pygimp_displays_flush, METH_NOARGS},
 
1706
    {"displays_reconnect", (PyCFunction)pygimp_displays_reconnect, METH_VARARGS},
1153
1707
    {"tile_cache_size", (PyCFunction)pygimp_tile_cache_size, METH_VARARGS},
1154
1708
    {"tile_cache_ntiles", (PyCFunction)pygimp_tile_cache_ntiles, METH_VARARGS},
1155
1709
    {"tile_width", (PyCFunction)pygimp_tile_width, METH_NOARGS},
1162
1716
    {"attach_new_parasite",(PyCFunction)pygimp_attach_new_parasite,METH_VARARGS},
1163
1717
    {"parasite_detach",    (PyCFunction)pygimp_parasite_detach,    METH_VARARGS},
1164
1718
    {"parasite_list",    (PyCFunction)pygimp_parasite_list,    METH_NOARGS},
 
1719
    {"show_tool_tips",  (PyCFunction)pygimp_show_tool_tips,  METH_NOARGS},
 
1720
    {"show_help_button",  (PyCFunction)pygimp_show_help_button,  METH_NOARGS},
 
1721
    {"check_size",  (PyCFunction)pygimp_check_size,  METH_NOARGS},
 
1722
    {"check_type",  (PyCFunction)pygimp_check_type,  METH_NOARGS},
1165
1723
    {"default_display",  (PyCFunction)pygimp_default_display,  METH_NOARGS},
 
1724
    {"wm_class", (PyCFunction)pygimp_wm_class,  METH_NOARGS},
 
1725
    {"display_name", (PyCFunction)pygimp_display_name,  METH_NOARGS},
 
1726
    {"monitor_number", (PyCFunction)pygimp_monitor_number,      METH_NOARGS},
 
1727
    {"get_progname", (PyCFunction)pygimp_get_progname,  METH_NOARGS},
 
1728
    {"fonts_refresh", (PyCFunction)pygimp_fonts_refresh,        METH_NOARGS},
 
1729
    {"fonts_get_list", (PyCFunction)pygimp_fonts_get_list,      METH_VARARGS | METH_KEYWORDS},
 
1730
    {"checks_get_shades", (PyCFunction)pygimp_checks_get_shades, METH_VARARGS | METH_KEYWORDS},
 
1731
    {"vectors_import_from_file", (PyCFunction)pygimp_vectors_import_from_file, METH_VARARGS | METH_KEYWORDS},
 
1732
    {"vectors_import_from_string", (PyCFunction)pygimp_vectors_import_from_string, METH_VARARGS | METH_KEYWORDS},
1166
1733
    {"_id2image", (PyCFunction)id2image, METH_VARARGS},
1167
1734
    {"_id2drawable", (PyCFunction)id2drawable, METH_VARARGS},
1168
1735
    {"_id2display", (PyCFunction)id2display, METH_VARARGS},
1169
 
    {NULL,       (PyCFunction)NULL, 0, NULL}            /* sentinel */
 
1736
    {"_id2vectors", (PyCFunction)id2vectors, METH_VARARGS},
 
1737
    {NULL,       (PyCFunction)NULL, 0, NULL}            /* sentinel */
 
1738
};
 
1739
 
 
1740
 
 
1741
static struct _PyGimp_Functions pygimp_api_functions = {
 
1742
    &PyGimpImage_Type,
 
1743
    pygimp_image_new,
 
1744
    &PyGimpDisplay_Type,
 
1745
    pygimp_display_new,
 
1746
    &PyGimpDrawable_Type,
 
1747
    pygimp_drawable_new,
 
1748
    &PyGimpLayer_Type,
 
1749
    pygimp_layer_new,
 
1750
    &PyGimpChannel_Type,
 
1751
    pygimp_channel_new,
 
1752
    &PyGimpVectors_Type,
 
1753
    pygimp_vectors_new,
1170
1754
};
1171
1755
 
1172
1756
 
1173
1757
/* Initialization function for the module (*must* be called initgimp) */
1174
1758
 
1175
 
static char gimp_module_documentation[] = 
 
1759
static char gimp_module_documentation[] =
1176
1760
"This module provides interfaces to allow you to write gimp plugins"
1177
1761
;
1178
1762
 
1179
 
void
1180
 
initgimp()
 
1763
DL_EXPORT(void)
 
1764
initgimp(void)
1181
1765
{
1182
1766
    PyObject *m, *d;
1183
1767
    PyObject *i;
1186
1770
    PyGimpPDB_Type.tp_alloc = PyType_GenericAlloc;
1187
1771
    PyGimpPDB_Type.tp_new = PyType_GenericNew;
1188
1772
    if (PyType_Ready(&PyGimpPDB_Type) < 0)
1189
 
        return;
 
1773
        return;
1190
1774
 
1191
1775
    PyGimpPDBFunction_Type.ob_type = &PyType_Type;
1192
1776
    PyGimpPDBFunction_Type.tp_alloc = PyType_GenericAlloc;
1193
1777
    PyGimpPDBFunction_Type.tp_new = PyType_GenericNew;
1194
1778
    if (PyType_Ready(&PyGimpPDBFunction_Type) < 0)
1195
 
        return;
 
1779
        return;
1196
1780
 
1197
1781
    PyGimpImage_Type.ob_type = &PyType_Type;
1198
1782
    PyGimpImage_Type.tp_alloc = PyType_GenericAlloc;
1199
1783
    PyGimpImage_Type.tp_new = PyType_GenericNew;
1200
1784
    if (PyType_Ready(&PyGimpImage_Type) < 0)
1201
 
        return;
 
1785
        return;
1202
1786
 
1203
1787
    PyGimpDisplay_Type.ob_type = &PyType_Type;
1204
1788
    PyGimpDisplay_Type.ob_type = &PyType_Type;
1205
1789
    PyGimpDisplay_Type.tp_alloc = PyType_GenericAlloc;
1206
1790
    PyGimpDisplay_Type.tp_new = PyType_GenericNew;
1207
1791
    if (PyType_Ready(&PyGimpDisplay_Type) < 0)
1208
 
        return;
 
1792
        return;
1209
1793
 
1210
1794
    PyGimpLayer_Type.ob_type = &PyType_Type;
1211
1795
    PyGimpLayer_Type.tp_alloc = PyType_GenericAlloc;
1212
1796
    PyGimpLayer_Type.tp_new = PyType_GenericNew;
1213
1797
    if (PyType_Ready(&PyGimpLayer_Type) < 0)
1214
 
        return;
 
1798
        return;
1215
1799
 
1216
1800
    PyGimpChannel_Type.ob_type = &PyType_Type;
1217
1801
    PyGimpChannel_Type.tp_alloc = PyType_GenericAlloc;
1218
1802
    PyGimpChannel_Type.tp_new = PyType_GenericNew;
1219
1803
    if (PyType_Ready(&PyGimpChannel_Type) < 0)
1220
 
        return;
 
1804
        return;
1221
1805
 
1222
1806
    PyGimpTile_Type.ob_type = &PyType_Type;
1223
1807
    PyGimpTile_Type.tp_alloc = PyType_GenericAlloc;
1224
1808
    PyGimpTile_Type.tp_new = PyType_GenericNew;
1225
1809
    if (PyType_Ready(&PyGimpTile_Type) < 0)
1226
 
        return;
 
1810
        return;
1227
1811
 
1228
1812
    PyGimpPixelRgn_Type.ob_type = &PyType_Type;
1229
1813
    PyGimpPixelRgn_Type.tp_alloc = PyType_GenericAlloc;
1230
1814
    PyGimpPixelRgn_Type.tp_new = PyType_GenericNew;
1231
1815
    if (PyType_Ready(&PyGimpPixelRgn_Type) < 0)
1232
 
        return;
 
1816
        return;
1233
1817
 
1234
1818
    PyGimpParasite_Type.ob_type = &PyType_Type;
1235
1819
    PyGimpParasite_Type.tp_alloc = PyType_GenericAlloc;
1236
1820
    PyGimpParasite_Type.tp_new = PyType_GenericNew;
1237
1821
    if (PyType_Ready(&PyGimpParasite_Type) < 0)
1238
 
        return;
 
1822
        return;
 
1823
 
 
1824
    PyGimpVectorsStroke_Type.ob_type = &PyType_Type;
 
1825
    PyGimpVectorsStroke_Type.tp_alloc = PyType_GenericAlloc;
 
1826
    PyGimpVectorsStroke_Type.tp_new = PyType_GenericNew;
 
1827
    if (PyType_Ready(&PyGimpVectorsStroke_Type) < 0)
 
1828
        return;
 
1829
 
 
1830
    PyGimpVectorsBezierStroke_Type.ob_type = &PyType_Type;
 
1831
    PyGimpVectorsBezierStroke_Type.tp_alloc = PyType_GenericAlloc;
 
1832
    PyGimpVectorsBezierStroke_Type.tp_new = PyType_GenericNew;
 
1833
    if (PyType_Ready(&PyGimpVectorsBezierStroke_Type) < 0)
 
1834
        return;
 
1835
 
 
1836
    PyGimpVectors_Type.ob_type = &PyType_Type;
 
1837
    PyGimpVectors_Type.tp_alloc = PyType_GenericAlloc;
 
1838
    PyGimpVectors_Type.tp_new = PyType_GenericNew;
 
1839
    if (PyType_Ready(&PyGimpVectors_Type) < 0)
 
1840
        return;
 
1841
 
 
1842
    pygimp_init_pygobject();
 
1843
    init_pygimpcolor();
 
1844
 
 
1845
    /* initialize i18n support */
 
1846
    bindtextdomain (GETTEXT_PACKAGE "-python", gimp_locale_directory ());
 
1847
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
 
1848
    bind_textdomain_codeset (GETTEXT_PACKAGE "-python", "UTF-8");
 
1849
#endif
 
1850
 
 
1851
    /* set the default python encoding to utf-8 */
 
1852
    PyUnicode_SetDefaultEncoding("utf-8");
1239
1853
 
1240
1854
    /* Create the module and add the functions */
1241
1855
    m = Py_InitModule4("gimp", gimp_methods,
1242
 
                       gimp_module_documentation,
1243
 
                       (PyObject*)NULL,PYTHON_API_VERSION);
 
1856
                       gimp_module_documentation,
 
1857
                       NULL, PYTHON_API_VERSION);
1244
1858
 
1245
1859
    /* Add some symbolic constants to the module */
1246
1860
    d = PyModule_GetDict(m);
1258
1872
    PyDict_SetItemString(d, "Tile", (PyObject *)&PyGimpTile_Type);
1259
1873
    PyDict_SetItemString(d, "PixelRgn", (PyObject *)&PyGimpPixelRgn_Type);
1260
1874
    PyDict_SetItemString(d, "Parasite", (PyObject *)&PyGimpParasite_Type);
 
1875
    PyDict_SetItemString(d, "VectorsBezierStroke", (PyObject *)&PyGimpVectorsBezierStroke_Type);
 
1876
    PyDict_SetItemString(d, "Vectors", (PyObject *)&PyGimpVectors_Type);
1261
1877
 
1262
 
    /* these are private, for use in gimpprocbrowser */
1263
 
    PyDict_SetItemString(d, "_PDBFunction",
1264
 
                         (PyObject *)&PyGimpPDBFunction_Type);
1265
 
    PyDict_SetItemString(d, "_pdb_function_new",
1266
 
                         PyCObject_FromVoidPtr(pygimp_pdb_function_new, NULL));
 
1878
    /* for other modules */
 
1879
    pygimp_api_functions.pygimp_error = pygimp_error;
 
1880
    PyDict_SetItemString(d, "_PyGimp_API",
 
1881
                         i=PyCObject_FromVoidPtr(&pygimp_api_functions, NULL));
 
1882
    Py_DECREF(i);
1267
1883
 
1268
1884
    PyDict_SetItemString(d, "version",
1269
 
                         i=Py_BuildValue("(iii)",
1270
 
                                         gimp_major_version,
1271
 
                                         gimp_minor_version,
1272
 
                                         gimp_micro_version));
 
1885
                         i=Py_BuildValue("(iii)",
 
1886
                                         gimp_major_version,
 
1887
                                         gimp_minor_version,
 
1888
                                         gimp_micro_version));
1273
1889
    Py_DECREF(i);
1274
 
        
 
1890
 
 
1891
    /* Some environment constants */
 
1892
    PyDict_SetItemString(d, "directory",
 
1893
                         PyString_FromString(gimp_directory()));
 
1894
    PyDict_SetItemString(d, "data_directory",
 
1895
                         PyString_FromString(gimp_data_directory()));
 
1896
    PyDict_SetItemString(d, "locale_directory",
 
1897
                         PyString_FromString(gimp_locale_directory()));
 
1898
    PyDict_SetItemString(d, "sysconf_directory",
 
1899
                         PyString_FromString(gimp_sysconf_directory()));
 
1900
    PyDict_SetItemString(d, "plug_in_directory",
 
1901
                         PyString_FromString(gimp_plug_in_directory()));
 
1902
 
1275
1903
    /* Check for errors */
1276
1904
    if (PyErr_Occurred())
1277
 
        Py_FatalError("can't initialize module gimp");
 
1905
        Py_FatalError("can't initialize module gimp");
1278
1906
}