xed/plugin-loaders/python/bindings/xeditcommands.override

123 lines
3.1 KiB
Plaintext
Raw Normal View History

2011-11-07 13:46:58 -06:00
%%
headers
#define NO_IMPORT_PYGOBJECT
#define NO_IMPORT_PYGTK
#include <pygobject.h>
#include <pygtk/pygtk.h>
2016-01-25 08:13:49 -06:00
#include "xedit-commands.h"
#include "xedit-window.h"
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
void pyxeditcommands_register_classes (PyObject *d);
void pyxeditcommands_add_constants (PyObject *module, const gchar *strip_prefix);
2011-11-07 13:46:58 -06:00
%%
2016-01-25 08:13:49 -06:00
modulename xedit.commands
2011-11-07 13:46:58 -06:00
%%
2016-01-25 08:13:49 -06:00
import xedit.Window as PyXeditWindow_Type
import xedit.Document as PyXeditDocument_Type
2011-11-07 13:46:58 -06:00
%%
ignore-glob
_*
%%
2016-01-25 08:13:49 -06:00
override xedit_commands_load_uri kwargs
2011-11-07 13:46:58 -06:00
static PyObject *
2016-01-25 08:13:49 -06:00
_wrap_xedit_commands_load_uri (PyObject *self, PyObject *args, PyObject *kwargs)
2011-11-07 13:46:58 -06:00
{
static char *kwlist[] = { "window", "uri", "encoding", "line_pos", NULL };
PyGObject *window;
char *uri;
int line_pos = 0;
PyObject *py_encoding = NULL;
2016-01-25 08:13:49 -06:00
XeditEncoding *encoding = NULL;
2011-11-07 13:46:58 -06:00
if (!PyArg_ParseTupleAndKeywords (args, kwargs, "O!s|Oi:load_uri",
2016-01-25 08:13:49 -06:00
kwlist, &PyXeditWindow_Type,
2011-11-07 13:46:58 -06:00
&window, &uri, &py_encoding,
&line_pos))
return NULL;
if (py_encoding != NULL && py_encoding != Py_None)
{
2016-01-25 08:13:49 -06:00
if (pyg_boxed_check (py_encoding, XEDIT_TYPE_ENCODING))
encoding = pyg_boxed_get (py_encoding, XeditEncoding);
2011-11-07 13:46:58 -06:00
else
{
PyErr_SetString (PyExc_TypeError,
2016-01-25 08:13:49 -06:00
"encoding should be a XeditEncoding");
2011-11-07 13:46:58 -06:00
return NULL;
}
}
2016-01-25 08:13:49 -06:00
xedit_commands_load_uri (XEDIT_WINDOW (window->obj), uri, encoding,
2011-11-07 13:46:58 -06:00
line_pos);
Py_INCREF (Py_None);
return Py_None;
}
%%
2016-01-25 08:13:49 -06:00
override xedit_commands_load_uris kwargs
2011-11-07 13:46:58 -06:00
static PyObject *
2016-01-25 08:13:49 -06:00
_wrap_xedit_commands_load_uris (PyObject *self, PyObject *args, PyObject *kwargs)
2011-11-07 13:46:58 -06:00
{
static char *kwlist[] = { "window", "uris", "encoding", "line_pos", NULL };
PyGObject *window;
GSList *uris = NULL;
int line_pos = 0;
PyObject *py_encoding = NULL;
PyObject *list;
PyObject *item;
2016-01-25 08:13:49 -06:00
XeditEncoding *encoding = NULL;
2011-11-07 13:46:58 -06:00
int len;
int i;
if (!PyArg_ParseTupleAndKeywords (args, kwargs, "O!O|Oi:load_uri",
2016-01-25 08:13:49 -06:00
kwlist, &PyXeditWindow_Type,
2011-11-07 13:46:58 -06:00
&window, &list, &py_encoding,
&line_pos))
return NULL;
if (py_encoding != NULL && py_encoding != Py_None)
{
2016-01-25 08:13:49 -06:00
if (pyg_boxed_check (py_encoding, XEDIT_TYPE_ENCODING))
encoding = pyg_boxed_get (py_encoding, XeditEncoding);
2011-11-07 13:46:58 -06:00
else {
PyErr_SetString (PyExc_TypeError,
2016-01-25 08:13:49 -06:00
"encoding should be a XeditEncoding");
2011-11-07 13:46:58 -06:00
return NULL;
}
}
if (!PySequence_Check (list))
{
PyErr_SetString (PyExc_TypeError,
"second 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 (!PyString_Check (item))
{
PyErr_SetString (PyExc_TypeError,
"sequence item not a string");
g_slist_free (uris);
return NULL;
}
uris = g_slist_prepend (uris, PyString_AsString (item));
}
uris = g_slist_reverse (uris);
2016-01-25 08:13:49 -06:00
xedit_commands_load_uris (XEDIT_WINDOW (window->obj), uris,
2011-11-07 13:46:58 -06:00
encoding, line_pos);
g_slist_free (uris);
Py_INCREF (Py_None);
return Py_None;
}