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
|
#include <Python.h>
#include <gtk/gtk.h>
#include <gtkspell/gtkspell.h>
#include "pygobject.h"
typedef struct {
PyObject_HEAD
GtkSpell *spell;
} gtkspell_SpellObject;
extern PyTypeObject gtkspell_SpellType;
static PyTypeObject *_PyGtkTextView_Type;
#define PyGtkTextView_Type (*_PyGtkTextView_Type)
static PyObject *
_wrap_gtkspell_new_attach (PyTypeObject *type, PyObject *args, PyObject *kwds)
{
gtkspell_SpellObject *self;
PyObject *pytextview;
GtkTextView *textview;
GtkSpell *spell;
char *language = NULL;
GError *error = NULL;
if (!PyArg_ParseTuple(args, "O!|z:gtkspell.Spell.__new__",
&PyGtkTextView_Type, &pytextview, &language))
return NULL;
textview = GTK_TEXT_VIEW(((PyGObject *)pytextview)->obj);
spell = gtkspell_new_attach(textview, language, &error);
if (pyg_error_check(&error))
return NULL;
if (!spell) {
PyErr_SetString(PyExc_RuntimeError, "unable to create and attach a Spell object");
return NULL;
}
self = (gtkspell_SpellObject *)type->tp_alloc(type, 0);
self->spell = spell;
return (PyObject *)self;
}
static PyObject *
_wrap_gtkspell_set_language (gtkspell_SpellObject *self, PyObject *args, PyObject *kwds)
{
gchar *lang = NULL;
gboolean result;
char *argnames[] = {"language", NULL};
if (!PyArg_ParseTupleAndKeywords (args, kwds, "z", argnames, &lang))
return NULL;
result = gtkspell_set_language (self->spell, lang, NULL);
if (!result) {
/*there are no specific errors in GtkSpell yet*/
PyErr_SetString(PyExc_RuntimeError, "Error setting language");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
_wrap_gtkspell_recheck_all (gtkspell_SpellObject *self)
{
gtkspell_recheck_all ((GtkSpell *)self->spell);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
_wrap_gtkspell_get_from_text_view (PyObject *junk, PyObject *args, PyObject *kwds)
{
PyObject *pytextview;
GtkTextView *textview;
gtkspell_SpellObject *self;
char *argnames[] = {"textview", NULL};
if (!PyArg_ParseTupleAndKeywords (args, kwds, "O", argnames, &pytextview))
return NULL;
textview = GTK_TEXT_VIEW(((PyGObject *)pytextview)->obj);
self = (gtkspell_SpellObject *)PyType_GenericAlloc((PyTypeObject *)>kspell_SpellType, 1);
if (self != NULL) {
self->spell = gtkspell_get_from_text_view(textview);
if (self->spell == NULL) {
Py_DECREF(self);
return NULL;
}
}
return (PyObject *)self;
}
static PyObject *
_wrap_gtkspell_detach (gtkspell_SpellObject *self)
{
gtkspell_detach(self->spell);
self->spell = NULL;
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef gtkspell_methods[] = {
{"set_language", (PyCFunction)_wrap_gtkspell_set_language,
METH_KEYWORDS, "Set the language"},
{"recheck_all", (PyCFunction)_wrap_gtkspell_recheck_all,
METH_NOARGS, "Recheck the spelling in the entire buffer"},
{"detach", (PyCFunction)_wrap_gtkspell_detach,
METH_NOARGS, "Detaches a Spell object from a TextView"},
{ NULL, NULL, 0 }
};
PyTypeObject gtkspell_SpellType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"gtkspell.Spell", /*tp_name*/
sizeof(gtkspell_SpellObject), /*tp_basicsize*/
0, /*tp_itemsize*/
0, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"GtkSpell object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
gtkspell_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
_wrap_gtkspell_new_attach, /* tp_new */
};
static PyMethodDef gtkspell_functions[] = {
{"get_from_text_view", (PyCFunction)_wrap_gtkspell_get_from_text_view,
METH_KEYWORDS, "Retrieves the Spell object attach"},
{ NULL, NULL, 0, NULL }
};
DL_EXPORT(void)
initgtkspell(void)
{
PyObject *m, *module;
init_pygobject();
if ((module = PyImport_ImportModule("gtk")) != NULL) {
PyObject *moddict = PyModule_GetDict(module);
_PyGtkTextView_Type = (PyTypeObject *)PyDict_GetItemString(moddict, "TextView");
if (_PyGtkTextView_Type == NULL) {
PyErr_SetString(PyExc_ImportError,
"cannot import name TextView from gtk");
return;
}
} else {
PyErr_SetString(PyExc_ImportError,
"could not import gtk");
return;
}
m = Py_InitModule3 ("gtkspell", gtkspell_functions, "GtkSpell bindings");
if (PyType_Ready(>kspell_SpellType) < 0)
return;
Py_INCREF(>kspell_SpellType);
PyModule_AddObject(m, "Spell", (PyObject *)>kspell_SpellType);
if (PyErr_Occurred ()) {
PyErr_Print();
Py_FatalError ("can't initialise module gtkspell");
}
}
|