summaryrefslogtreecommitdiff
path: root/plugin-loaders/python/bindings/gedit.override
blob: 52c492a410bef541568fea1aacd7a16b6d9f24e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
%%
headers
#include <pygobject.h>
#include <pygtk/pygtk.h>

#include <gedit/gedit-language-manager.h>
#include <gedit/gedit-plugin.h>
#include <gedit/gedit-app.h>
#include <gedit/gedit-encodings.h>
#include <gedit/gedit-enum-types.h>
#include <gedit/gedit-statusbar.h>
#include <gedit/gedit-debug.h>
#include <gedit/gedit-help.h>

#include "gedit-plugin-python.h"

void pygedit_register_classes (PyObject *d); 
void pygedit_add_constants (PyObject *module, const gchar *strip_prefix);

static PyObject *
_helper_wrap_gobject_glist (const GList *list)
{
    PyObject *py_list;
    const GList *tmp;

    if ((py_list = PyList_New(0)) == NULL) {
        return NULL;
    }
    for (tmp = list; tmp != NULL; tmp = tmp->next) {
        PyObject *py_obj = pygobject_new(G_OBJECT(tmp->data));

        if (py_obj == NULL) {
            Py_DECREF(py_list);
            return NULL;
        }
        PyList_Append(py_list, py_obj);
        Py_DECREF(py_obj);
    }
    return py_list;
}

static PyObject *
_helper_wrap_gobject_gslist (const GSList *list)
{
    PyObject *py_list;
    const GSList *tmp;

    if ((py_list = PyList_New(0)) == NULL) {
        return NULL;
    }
    for (tmp = list; tmp != NULL; tmp = tmp->next) {
        PyObject *py_obj = pygobject_new(G_OBJECT(tmp->data));

        if (py_obj == NULL) {
            Py_DECREF(py_list);
            return NULL;
        }
        PyList_Append(py_list, py_obj);
        Py_DECREF(py_obj);
    }
    return py_list;
}
%%
include
  geditplugin.override
  geditmessage.override
%%
modulename gedit 
%%
import gtk.Widget as PyGtkWidget_Type
import gobject.GObject as PyGObject_Type
import gtk.gdk.Screen as PyGdkScreen_Type
import gtk.VBox as PyGtkVBox_Type
import gtk.Window as PyGtkWindow_Type
import gtk.Image as PyGtkImage_Type
import gtk.Statusbar as PyGtkStatusbar_Type
import gtksourceview2.Buffer as PyGtkSourceBuffer_Type
import gtksourceview2.View as PyGtkSourceView_Type
import gtksourceview2.Language as PyGtkSourceLanguage_Type
import gtksourceview2.LanguageManager as PyGtkSourceLanguageManager_Type
%%
ignore-glob
  *_get_type
  gedit_document_error_quark
  gedit_panel_add_item_with_stock_icon
%%
override gedit_app_create_window kwargs
static PyObject *
_wrap_gedit_app_create_window(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "screen", NULL};
    PyGObject *screen = NULL;
    GeditWindow *ret;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
			"|O!", kwlist,
			&PyGdkScreen_Type, &screen))
        return NULL;

    ret = gedit_app_create_window(GEDIT_APP(self->obj),
				  screen ? GDK_SCREEN(screen->obj) : NULL);

    /* pygobject_new handles NULL checking */
    return pygobject_new((GObject *)ret);
}
%%
override gedit_app_get_windows
static PyObject *
_wrap_gedit_app_get_windows(PyGObject *self)
{
    const GList *list;
    PyObject *py_list;

    list = gedit_app_get_windows (GEDIT_APP (self->obj));

    py_list = _helper_wrap_gobject_glist (list);

    return py_list;
}
%%
override gedit_app_get_views
static PyObject *
_wrap_gedit_app_get_views(PyGObject *self)
{
    GList *list;
    PyObject *py_list;

    list = gedit_app_get_views (GEDIT_APP (self->obj));

    py_list = _helper_wrap_gobject_glist (list);

    g_list_free (list);

    return py_list;
}
%%
override gedit_app_get_documents
static PyObject *
_wrap_gedit_app_get_documents(PyGObject *self)
{
    GList *list;
    PyObject *py_list;

    list = gedit_app_get_documents (GEDIT_APP (self->obj));

    py_list = _helper_wrap_gobject_glist (list);

    g_list_free (list);

    return py_list;
}
%%
override gedit_window_get_documents
static PyObject *
_wrap_gedit_window_get_documents(PyGObject *self)
{
    GList *list;
    PyObject *py_list;

    list = gedit_window_get_documents (GEDIT_WINDOW (self->obj));

    py_list = _helper_wrap_gobject_glist (list);

    g_list_free(list);

    return py_list;
}
%%
override gedit_window_get_unsaved_documents
static PyObject *
_wrap_gedit_window_get_unsaved_documents(PyGObject *self)
{
    GList *list;
    PyObject *py_list;

    list = gedit_window_get_unsaved_documents (GEDIT_WINDOW (self->obj));

    py_list = _helper_wrap_gobject_glist (list);

    g_list_free(list);

    return py_list;
}
%%
override gedit_window_get_views
static PyObject *
_wrap_gedit_window_get_views(PyGObject *self)
{
    GList *list;
    PyObject *py_list;

    list = gedit_window_get_views (GEDIT_WINDOW (self->obj));

    py_list = _helper_wrap_gobject_glist (list);

    g_list_free(list);

    return py_list;
}
%%
override gedit_window_close_tabs kwargs
static PyObject *
_wrap_gedit_window_close_tabs (PyGObject *self,
			       PyObject  *args,
			       PyObject  *kwargs)
{
	static char *kwlist[] = { "tabs", NULL };
	PyObject *list, *item;
	GList *glist = NULL;
	int len, i;

	if (!PyArg_ParseTupleAndKeywords (args, kwargs,
					  "O:GeditWindow.close_tabs", kwlist,
					  &list))
		return NULL;

	if (!PySequence_Check (list))
	{
		PyErr_SetString (PyExc_TypeError,
				 "first argument must be a sequence");
		return NULL;
	}

	len = PySequence_Length (list);

	for (i = 0; i < len; i++)
	{
		item = PySequence_GetItem (list, i);
		Py_DECREF(item);

		if (!pygobject_check (item, &PyGeditTab_Type))
		{
			PyErr_SetString (PyExc_TypeError,
					 "sequence item not a Gtkwidget object");
			g_list_free (glist);
			return NULL;
		}

		glist = g_list_append (glist, pygobject_get (item));
	}

	gedit_window_close_tabs (GEDIT_WINDOW (self->obj), glist);

	g_list_free (glist);
	Py_INCREF (Py_None);
	return Py_None;
}
%%
override gedit_document_get_search_text
static PyObject *
_wrap_gedit_document_get_search_text(PyGObject *self)
{
    PyObject *tuple, *string;
    guint flags;
    gchar *ret;

    ret = gedit_document_get_search_text (GEDIT_DOCUMENT (self->obj), &flags);

    tuple = PyTuple_New(2);
    if (ret) {
        string = PyString_FromString(ret);
        PyTuple_SetItem(tuple, 0, string);
    } else {
        Py_INCREF(Py_None);
        PyTuple_SetItem(tuple, 0, Py_None);
    }
    PyTuple_SetItem(tuple, 1, PyInt_FromLong(flags));

    g_free(ret);

    return tuple;
}
%%
override gedit_panel_add_item kwargs
static PyObject *
_wrap_gedit_panel_add_item(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist1[] = { "item", "name", "image", NULL };
    static char *kwlist2[] = { "item", "name", "stock_id", NULL };
    PyGObject *item, *image;
    char *name = NULL;
    char *stock_id = NULL;

    if (PyArg_ParseTupleAndKeywords(args, kwargs, "O!sO!:GeditPanel.add_item", kwlist1, &PyGtkWidget_Type, &item, &name, &PyGtkImage_Type, &image)) {
        gedit_panel_add_item(GEDIT_PANEL(self->obj), GTK_WIDGET(item->obj), name, GTK_WIDGET(image->obj));
        Py_INCREF(Py_None);
        return Py_None;
    }

    PyErr_Clear();

    if (PyArg_ParseTupleAndKeywords(args, kwargs, "O!ss:GeditPanel.add_item", kwlist2, &PyGtkWidget_Type, &item, &name, &stock_id)) {
        gedit_panel_add_item_with_stock_icon(GEDIT_PANEL(self->obj), GTK_WIDGET(item->obj), name, stock_id);
        Py_INCREF(Py_None);
        return Py_None;
    }

    PyErr_Clear();
    PyErr_SetString(PyExc_TypeError, "the last arg should be either a gtk.Image or a stock_id string");
    return NULL;
}
%%
override gedit_app_get_default_deprecated
/* deprecated wrappers */
static PyObject *
_wrap_gedit_app_get_default_deprecated(PyObject *self)
{
    if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.app_get_default instead") < 0)
	return NULL;
    return _wrap_gedit_app_get_default(self);
}
%%
override gedit_encoding_get_from_charset_deprecated kwargs
static PyObject *
_wrap_gedit_encoding_get_from_charset_deprecated(PyObject *self, PyObject *args, PyObject *kwargs)
{
    if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.encoding_get_from_charset instead") < 0)
	return NULL;
    return _wrap_gedit_encoding_get_from_charset(self, args, kwargs);
}
%%
override gedit_encoding_get_from_index_deprecated kwargs
static PyObject *
_wrap_gedit_encoding_get_from_index_deprecated(PyObject *self, PyObject *args, PyObject *kwargs)
{
    if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.encoding_get_from_index instead") < 0)
	return NULL;
    return _wrap_gedit_encoding_get_from_index(self, args, kwargs);
}
%%
override gedit_encoding_get_utf8_deprecated
static PyObject *
_wrap_gedit_encoding_get_utf8_deprecated(PyObject *self)
{
    if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.encoding_get_utf8 instead") < 0)
	return NULL;
    return _wrap_gedit_encoding_get_utf8(self);
}
%%
override gedit_encoding_get_current_deprecated
static PyObject *
_wrap_gedit_encoding_get_current_deprecated(PyObject *self)
{
    if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.encoding_get_current instead") < 0)
	return NULL;
    return _wrap_gedit_encoding_get_current(self);
}
%%
override gedit_tab_get_from_document_deprecated kwargs
static PyObject *
_wrap_gedit_tab_get_from_document_deprecated(PyObject *self, PyObject *args, PyObject *kwargs)
{
    if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.tab_get_from_document instead") < 0)
	return NULL;
    return _wrap_gedit_tab_get_from_document(self, args, kwargs);
}
%%
override gedit_language_manager_list_languages_sorted kwargs
static PyObject *
_wrap_gedit_language_manager_list_languages_sorted(PyObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "lm", "include_hidden", NULL };
    PyGObject *lm;
    int include_hidden;
    PyObject *py_list;
    GSList *list;

    if (!PyArg_ParseTupleAndKeywords (args, kwargs,
                                      "O!i:language_manager_list_languages_sorted",
                                      kwlist, &PyGtkSourceLanguageManager_Type, &lm,
                                      &include_hidden))
        return NULL;

    list = gedit_language_manager_list_languages_sorted (GTK_SOURCE_LANGUAGE_MANAGER (lm->obj),
                                                         include_hidden);

    py_list = _helper_wrap_gobject_gslist (list);

    g_slist_free (list);

    return py_list;
}
%%
override gedit_debug kwargs
static PyObject *
_wrap_gedit_debug(PyObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "message", NULL };
    PyObject *traceback_module, *mdict, *func, *traceback, *tuple;
    PyObject *filename, *lineno, *funcname;
    char *message = NULL;

    if (g_getenv ("GEDIT_DEBUG_PLUGINS") == NULL)
    {
        Py_INCREF (Py_None);
        return Py_None;
    }

    if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|s", kwlist, &message))
        return NULL;

    traceback_module = PyImport_ImportModule ("traceback");
    if (traceback_module == NULL)
    {
        g_warning ("traceback module cannot be imported");
        Py_INCREF (Py_None);
        return Py_None;
    }

    mdict = PyModule_GetDict (traceback_module);
    func = PyDict_GetItemString (mdict, "extract_stack");
    traceback = PyObject_CallFunction (func, "zi", NULL, 1);
    tuple = PyList_GetItem (traceback, 0);

    if (tuple == NULL || !PyTuple_Check (tuple))
    {
        g_warning ("traceback tuple is null!");
    }
    else
    {
        filename = PyTuple_GetItem (tuple, 0);
        lineno = PyTuple_GetItem (tuple, 1);
        funcname = PyTuple_GetItem (tuple, 2);

        if (message == NULL)
            gedit_debug (GEDIT_DEBUG_PLUGINS,
                         PyString_AsString (filename),
                         PyInt_AsLong (lineno),
                         PyString_AsString (funcname));
        else
            gedit_debug_message (GEDIT_DEBUG_PLUGINS,
                                 PyString_AsString (filename),
                                 PyInt_AsLong (lineno),
                                 PyString_AsString (funcname),
                                 "%s",
                                 message);
    }
    Py_DECREF (traceback);
    Py_DECREF (traceback_module);

    Py_INCREF (Py_None);
    return Py_None;
}
%%
override gedit_statusbar_flash_message kwargs
static PyObject *
_wrap_gedit_statusbar_flash_message(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "context_id", "message", NULL };
    int context_id;
    char *message;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,"is:GeditStatusbar.flash_message", kwlist, &context_id, &message))
        return NULL;
   
    gedit_statusbar_flash_message(GEDIT_STATUSBAR(self->obj), context_id, "%s", message);

    Py_INCREF(Py_None);
    return Py_None;
}
%%