diff options
Diffstat (limited to 'plugins/pychrysa/gui/editem.c')
-rw-r--r-- | plugins/pychrysa/gui/editem.c | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/plugins/pychrysa/gui/editem.c b/plugins/pychrysa/gui/editem.c index 7a40a04..6db03ce 100644 --- a/plugins/pychrysa/gui/editem.c +++ b/plugins/pychrysa/gui/editem.c @@ -90,7 +90,7 @@ static void _update_editor_item_for_binary_python_wrapper(GEditorItem *item, GLo * des éléments d'éditeur, via py_editor_item_register(), donc son compteur * de références doit le maintenir en vie. * - * On peut donc le récupérer directement depuis l'instane GLib, sans passer + * On peut donc le récupérer directement depuis l'instance GLib, sans passer * par la procédure de pygobject, qui obligerait à connaître le type précis * de l'instance GLib manipulée. */ @@ -355,21 +355,18 @@ static PyObject *py_editor_item_register(PyObject *self, PyObject *args) /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : - * * * -* Description : Prend en charge l'objet 'pychrysalide.gui.EditorItem'. * +* Description : Fournit un accès à une définition de type à diffuser. * * * -* Retour : Bilan de l'opération. * +* Retour : Définition d'objet pour Python. * * * * Remarques : - * * * ******************************************************************************/ -bool register_python_editor_item(PyObject *module) +PyTypeObject *get_python_editor_item_type(void) { - PyObject *parent_mod; /* Module Python-GObject */ - int ret; /* Bilan d'un appel */ - static PyMethodDef py_editor_item_methods[] = { { "update_for_binary", (PyCFunction)py_editor_item_update_for_binary, @@ -387,19 +384,19 @@ bool register_python_editor_item(PyObject *module) "Called by Chrysalide on each view content change, if the item is registered." }, { - "get_current_binary", (PyCFunction)py_editor_item_get_current_binary, + "get_current_binary()", (PyCFunction)py_editor_item_get_current_binary, METH_NOARGS, - "Provide the current binary." + "get_current_binary($self, /)\n--\n\nProvide the current binary." }, { "get_current_view", (PyCFunction)py_editor_item_get_current_view, METH_NOARGS, - "Provide the current binary view." + "get_current_view($self, /)\n--\n\nProvide the current binary view." }, { "register", (PyCFunction)py_editor_item_register, METH_NOARGS, - "Register the item as editor item." + "register($self, /)\n--\n\nRegister the item as editor item." }, { NULL } }; @@ -410,32 +407,58 @@ bool register_python_editor_item(PyObject *module) static PyTypeObject py_editor_item_type = { - PyObject_HEAD_INIT(NULL) + PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "pychrysalide.gui.EditorItem", - .tp_basicsize = sizeof(PyGObject), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .tp_doc = "PyChrysalide editor item", .tp_methods = py_editor_item_methods, - .tp_getset = py_editor_item_getseters + .tp_getset = py_editor_item_getseters, }; - parent_mod = PyImport_ImportModule("gobject"); - if (parent_mod == NULL) return false; + return &py_editor_item_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.gui.EditorItem'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_editor_item(PyObject *module) +{ + PyTypeObject *py_editor_item_type; /* Type Python 'LoadedBinary' */ + int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ + + py_editor_item_type = get_python_editor_item_type(); - py_editor_item_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "GObject"); - Py_DECREF(parent_mod); + py_editor_item_type->tp_base = &PyGObject_Type; + py_editor_item_type->tp_basicsize = py_editor_item_type->tp_base->tp_basicsize; - if (PyType_Ready(&py_editor_item_type) < 0) + if (PyType_Ready(py_editor_item_type) != 0) return false; - Py_INCREF(&py_editor_item_type); - ret = PyModule_AddObject(module, "EditorItem", (PyObject *)&py_editor_item_type); + Py_INCREF(py_editor_item_type); + ret = PyModule_AddObject(module, "EditorItem", (PyObject *)py_editor_item_type); + if (ret != 0) return false; + + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "EditorItem", G_TYPE_EDITOR_ITEM, py_editor_item_type, + Py_BuildValue("(O)", py_editor_item_type->tp_base)); - return (ret == 0); + return true; } |