diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-07-17 16:36:21 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-07-17 16:36:21 (GMT) |
commit | 24d3836fcf8d443eb654b981f65478cd9923b8f1 (patch) | |
tree | 7672a28b864127e8958c3c6cce751dcf646d2fbe /plugins/pychrysa/glibext/bufferline.c | |
parent | a61f089babe336b012da31a494b0f7470b6e1a9a (diff) |
Updated the Python bindings.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@552 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/glibext/bufferline.c')
-rw-r--r-- | plugins/pychrysa/glibext/bufferline.c | 300 |
1 files changed, 275 insertions, 25 deletions
diff --git a/plugins/pychrysa/glibext/bufferline.c b/plugins/pychrysa/glibext/bufferline.c index d5b8b13..ce85cfb 100644 --- a/plugins/pychrysa/glibext/bufferline.c +++ b/plugins/pychrysa/glibext/bufferline.c @@ -29,16 +29,35 @@ #include <pygobject.h> +#include <i18n.h> + + #include <glibext/gbufferline.h> -#include "../quirks.h" +#include "../helpers.h" +#include "../arch/vmpa.h" /* Reconstruit et fournit le texte présent sur une ligne tampon. */ static PyObject *py_buffer_line_get_text(PyObject *, PyObject *); +/* Ajoute une propriété particulière à une ligne donnée. */ +static PyObject *py_buffer_line_add_flag(PyObject *, PyObject *); + +/* Retire une propriété particulière à une ligne donnée. */ +static PyObject *py_buffer_line_remove_flag(PyObject *, PyObject *); + +/* Fournit l'emplacement où se situe un symbole. */ +static PyObject *py_buffer_line_get_range(PyObject *, void *); + +/* Renseigne sur les propriétés particulières liées à une ligne. */ +static PyObject *py_buffer_line_get_flags(PyObject *, void *); + +/* Définit les constantes pour les lignes de tampon. */ +static bool py_buffer_line_define_constants(PyTypeObject *); + /****************************************************************************** @@ -57,13 +76,26 @@ static PyObject *py_buffer_line_get_text(PyObject *, PyObject *); static PyObject *py_buffer_line_get_text(PyObject *self, PyObject *args) { PyObject *result; /* Trouvailles à retourner */ + BufferLineColumn first; /* Première colonne à parcourir*/ + BufferLineColumn end; /* Dernière colonne à parcourir*/ + int markup; /* Besoin de décorations ? */ + int ret; /* Bilan de lecture des args. */ GBufferLine *line; /* Version native */ char *text; /* Texte reconstruit à libérer */ + ret = PyArg_ParseTuple(args, "IIp", &first, &end, &markup); + if (!ret) return NULL; + + if (first >= BLC_COUNT || end >= BLC_COUNT) + { + PyErr_SetString(PyExc_ValueError, _("Invalid range in arguments")); + return NULL; + } + line = G_BUFFER_LINE(pygobject_get(self)); - text = "";//g_buffer_line_get_text(line); + text = g_buffer_line_get_text(line, first, end, markup); - result = PyString_FromString(text); + result = PyUnicode_FromString(text); free(text); @@ -74,60 +106,278 @@ static PyObject *py_buffer_line_get_text(PyObject *self, PyObject *args) /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : self = classe représentant une ligne de tampon. * +* args = arguments fournis à l'appel. * * * -* Description : Prend en charge l'objet 'pychrysalide.glibext.BufferLine'. * +* Description : Ajoute une propriété particulière à une ligne donnée. * * * -* Retour : Bilan de l'opération. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -bool register_python_buffer_line(PyObject *module) +static PyObject *py_buffer_line_add_flag(PyObject *self, PyObject *args) { - PyObject *pygobj_mod; /* Module Python-GObject */ - int ret; /* Bilan d'un appel */ + BufferLineFlags flag; /* Drapeau à considérer */ + int ret; /* Bilan de lecture des args. */ + GBufferLine *line; /* Version native */ + + ret = PyArg_ParseTuple(args, "I", &flag); + if (!ret) return NULL; + + if ((flag & ~BLF_ALL) != 0) + { + PyErr_SetString(PyExc_ValueError, _("Invalid flag")); + return NULL; + } + + line = G_BUFFER_LINE(pygobject_get(self)); + g_buffer_line_add_flag(line, flag); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une ligne de tampon. * +* args = arguments fournis à l'appel. * +* * +* Description : Retire une propriété particulière à une ligne donnée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_buffer_line_remove_flag(PyObject *self, PyObject *args) +{ + BufferLineFlags flag; /* Drapeau à considérer */ + int ret; /* Bilan de lecture des args. */ + GBufferLine *line; /* Version native */ + + ret = PyArg_ParseTuple(args, "I", &flag); + if (!ret) return NULL; + + if ((flag & ~BLF_ALL) != 0) + { + PyErr_SetString(PyExc_ValueError, _("Invalid flag")); + return NULL; + } + + line = G_BUFFER_LINE(pygobject_get(self)); + g_buffer_line_remove_flag(line, flag); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique la zone mémoire où se situe la ligne. * +* * +* Retour : Emplacement mémoire virtuel ou physique. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_buffer_line_get_range(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GBufferLine *line; /* Elément à consulter */ + const mrange_t *range; /* Couverture courante */ + + line = G_BUFFER_LINE(pygobject_get(self)); + range = g_buffer_line_get_range(line); + + result = build_from_internal_mrange(range); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Renseigne sur les propriétés particulières liées à une ligne.* +* * +* Retour : Propriétés intégrées. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_buffer_line_get_flags(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GBufferLine *line; /* Elément à consulter */ + BufferLineFlags flags; /* Drapeaux à exporter */ + + line = G_BUFFER_LINE(pygobject_get(self)); + flags = g_buffer_line_get_flags(line); + + result = PyLong_FromLong(flags); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les lignes de tampon. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_buffer_line_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, BLC_PHYSICAL); + result &= PyDict_AddIntMacro(obj_type, BLC_VIRTUAL); + result &= PyDict_AddIntMacro(obj_type, BLC_BINARY); + result &= PyDict_AddIntMacro(obj_type, BLC_ASSEMBLY_HEAD); + result &= PyDict_AddIntMacro(obj_type, BLC_ASSEMBLY); + result &= PyDict_AddIntMacro(obj_type, BLC_COMMENTS); + result &= PyDict_AddIntMacro(obj_type, BLC_COUNT); + result &= PyDict_AddIntMacro(obj_type, BLC_LAST_USED); + result &= PyDict_AddIntMacro(obj_type, BLC_INVALID); + result &= PyDict_AddIntMacro(obj_type, BLC_MAIN); + result &= PyDict_AddIntMacro(obj_type, BLC_FIRST); + result &= PyDict_AddIntMacro(obj_type, BLC_DISPLAY); + + result &= PyDict_AddIntMacro(obj_type, BLF_NONE); + result &= PyDict_AddIntMacro(obj_type, BLF_HAS_CODE); + result &= PyDict_AddIntMacro(obj_type, BLF_ENTRYPOINT); + result &= PyDict_AddIntMacro(obj_type, BLF_BOOKMARK); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ +PyTypeObject *get_python_buffer_line_type(void) +{ static PyMethodDef py_buffer_line_methods[] = { { - "get_text", (PyCFunction)py_buffer_line_get_text, - METH_NOARGS, - "Rebuild and provide the text of a buffer line." + "get_text", py_buffer_line_get_text, + METH_VARARGS, + "get_text($self, first_col, last_col, markup, /)\n--\n\nProvide the text of a buffer line." + }, + { + "add_flag", py_buffer_line_add_flag, + METH_VARARGS, + "add_flag($self, flag, /)\n--\n\nAdd a flag to the buffer line." + }, + { + "remove_flag", py_buffer_line_remove_flag, + METH_VARARGS, + "remove_flag($self, flag, /)\n--\n\nRemove a flag from the buffer line." + }, + { NULL } + }; + + static PyGetSetDef py_buffer_line_getseters[] = { + { + "range", py_buffer_line_get_range, NULL, + "Range covered by the line.", NULL + }, + { + "flags", py_buffer_line_get_flags, NULL, + "Current flags of the buffer line.", NULL }, { NULL } }; static PyTypeObject py_buffer_line_type = { - PyObject_HEAD_INIT(NULL) + PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "pychrysalide.glibext.BufferLine", .tp_basicsize = sizeof(PyGObject), - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_flags = Py_TPFLAGS_DEFAULT, .tp_doc = "PyChrysalide buffer line", - .tp_methods = py_buffer_line_methods + .tp_methods = py_buffer_line_methods, + .tp_getset = py_buffer_line_getseters, }; - pygobj_mod = PyImport_ImportModule("gobject"); - if (pygobj_mod == NULL) return false; + return &py_buffer_line_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.glibext.BufferLine'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - py_buffer_line_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject"); - Py_DECREF(pygobj_mod); +bool register_python_buffer_line(PyObject *module) +{ + PyTypeObject *py_buffer_line_type; /* Type Python 'BufferLine' */ + int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ + + py_buffer_line_type = get_python_buffer_line_type(); + + py_buffer_line_type->tp_base = &PyGObject_Type; + py_buffer_line_type->tp_basicsize = py_buffer_line_type->tp_base->tp_basicsize; + + if (PyType_Ready(py_buffer_line_type) != 0) + return false; - if (PyType_Ready(&py_buffer_line_type) < 0) + if (!py_buffer_line_define_constants(py_buffer_line_type)) return false; - Py_INCREF(&py_buffer_line_type); - ret = PyModule_AddObject(module, "BufferLine", (PyObject *)&py_buffer_line_type); + Py_INCREF(py_buffer_line_type); + ret = PyModule_AddObject(module, "BufferLine", (PyObject *)py_buffer_line_type); + if (ret != 0) return false; - pygobject_register_class(module, "GBufferLine", G_TYPE_BUFFER_LINE, &py_buffer_line_type, - Py_BuildValue("(O)", py_buffer_line_type.tp_base)); + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "BufferLine", G_TYPE_BUFFER_LINE, py_buffer_line_type, + Py_BuildValue("(O)", py_buffer_line_type->tp_base)); - return (ret == 0); + return true; } |