diff options
Diffstat (limited to 'plugins/pychrysalide/gui/editem.c')
-rw-r--r-- | plugins/pychrysalide/gui/editem.c | 296 |
1 files changed, 129 insertions, 167 deletions
diff --git a/plugins/pychrysalide/gui/editem.c b/plugins/pychrysalide/gui/editem.c index c60d678..986d1cb 100644 --- a/plugins/pychrysalide/gui/editem.c +++ b/plugins/pychrysalide/gui/editem.c @@ -33,41 +33,40 @@ #include "../access.h" #include "../helpers.h" +#include "../pychrysa.h" #include "../analysis/binary.h" #include "../gtkext/displaypanel.h" -/* Réagit à un changement du binaire courant. */ -static void _change_editor_item_content_python_wrapper(GEditorItem *, GLoadedContent *, GLoadedContent *); +/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */ -/* Réagit à un changement de vue. */ -static void _change_editor_item_view_python_wrapper(GEditorItem *, GLoadedPanel *, GLoadedPanel *); -/* Réagit à un changement de contenu. */ -static void _update_editor_item_view_python_wrapper(GEditorItem *, GLoadedPanel *); +/* Réagit à un changement de contenu chargé en cours d'analyse. */ +static void py_editor_item_change_content_wrapper(GEditorItem *, GLoadedContent *, GLoadedContent *); /* Réagit à un changement de contenu chargé en cours d'analyse. */ -static PyObject *py_editor_item_change_content(PyObject *, PyObject *); +static void py_editor_item_change_content_wrapper(GEditorItem *, GLoadedContent *, GLoadedContent *); /* Réagit à un changement de vue du contenu en cours d'analyse. */ -static PyObject *py_editor_item_change_view(PyObject *, PyObject *); +static void py_editor_item_change_view_wrapper(GEditorItem *, GLoadedPanel *, GLoadedPanel *); /* Réagit à une modification de la vue du contenu analysé. */ -static PyObject *py_editor_item_update_view(PyObject *, PyObject *); +static void py_editor_item_update_view_wrapper(GEditorItem *, GLoadedPanel *); + -/* Procède à l'enregistrement d'un élément reactif de l'éditeur. */ -static PyObject *py_editor_item_register(PyObject *, PyObject *); +/* ---------------------------------------------------------------------------------- */ +/* GLUE POUR CREATION DEPUIS PYTHON */ +/* ---------------------------------------------------------------------------------- */ /****************************************************************************** * * -* Paramètres : item = élément à actualiser. * -* old = ancien contenu chargé analysé. * -* new = nouveau contenu chargé à analyser. * +* Paramètres : class = classe à initialiser. * +* unused = données non utilisées ici. * * * -* Description : Réagit à un changement du binaire courant. * +* Description : Initialise la classe des éléménts pour l'interface graphique.* * * * Retour : - * * * @@ -75,43 +74,22 @@ static PyObject *py_editor_item_register(PyObject *, PyObject *); * * ******************************************************************************/ -static void _change_editor_item_content_python_wrapper(GEditorItem *item, GLoadedContent *old, GLoadedContent *new) +void py_editor_item_init_gclass(GEditorItemClass *class, gpointer unused) { - PyObject *target; /* Version Python de l'élément */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Retour obtenu */ - - /** - * Normalement, l'objet Python est enregistré dans la liste de Chrysalide - * 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'instance GLib, sans passer - * par la procédure de pygobject, qui obligerait à connaître le type précis - * de l'instance GLib manipulée. - */ - target = pygobject_new(G_OBJECT(item)); - - args = PyTuple_New(2); - PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(old))); - PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(new))); - - value = run_python_method(target, "change_content", args); - - Py_XDECREF(value); - Py_DECREF(args); - Py_DECREF(target); + class->change_content = py_editor_item_change_content_wrapper; + class->change_view = py_editor_item_change_view_wrapper; + class->update_view = py_editor_item_update_view_wrapper; } /****************************************************************************** * * -* Paramètres : item = élément à actualiser. * -* old = ancienne vue du contenu chargé analysé. * -* new = nouvelle vue du contenu chargé analysé. * +* Paramètres : item = instance à consulter. * +* old = ancien contenu chargé analysé. * +* new = nouveau contenu chargé à analyser. * * * -* Description : Réagit à un changement de vue. * +* Description : Réagit à un changement de contenu chargé en cours d'analyse. * * * * Retour : - * * * @@ -119,42 +97,64 @@ static void _change_editor_item_content_python_wrapper(GEditorItem *item, GLoade * * ******************************************************************************/ -static void _change_editor_item_view_python_wrapper(GEditorItem *item, GLoadedPanel *old, GLoadedPanel *new) +static void py_editor_item_change_content_wrapper(GEditorItem *item, GLoadedContent *old, GLoadedContent *new) { - PyObject *target; /* Version Python de l'élément */ + PyObject *pyobj; /* Objet Python concerné */ + PyThreadState *tstate; /* Contexte d'environnement */ + PyObject *pyold; /* Conversion ou None */ + PyObject *pynew; /* Conversion ou None */ PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Retour obtenu */ + PyObject *pyret; /* Retour de Python */ + + pyobj = pygobject_new(G_OBJECT(item)); + + tstate = get_pychrysalide_main_tstate(); + + if (tstate != NULL) + PyEval_RestoreThread(tstate); + + if (has_python_method(pyobj, "_change_content")) + { + if (old != NULL) + pyold = pygobject_new(G_OBJECT(old)); + else + { + pyold = Py_None; + Py_INCREF(pyold); + } - /** - * Normalement, l'objet Python est enregistré dans la liste de Chrysalide - * 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 - * par la procédure de pygobject, qui obligerait à connaître le type précis - * de l'instance GLib manipulée. - */ - target = pygobject_new(G_OBJECT(item)); + if (new != NULL) + pynew = pygobject_new(G_OBJECT(new)); + else + { + pynew = Py_None; + Py_INCREF(pynew); + } + + args = PyTuple_New(2); + PyTuple_SetItem(args, 0, pyold); + PyTuple_SetItem(args, 1, pynew); - args = PyTuple_New(2); - PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(old))); - PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(new))); + pyret = run_python_method(pyobj, "_change_content", args); - value = run_python_method(target, "change_view", args); + Py_DECREF(args); + Py_DECREF(pyret); - Py_XDECREF(value); - Py_DECREF(args); - Py_DECREF(target); + } + + if (tstate != NULL) + PyEval_SaveThread(); } /****************************************************************************** * * -* Paramètres : item = élément à actualiser. * -* panel = vue du contenu chargé analysé modifiée. * +* Paramètres : item = instance à consulter. * +* old = ancienne vue du contenu chargé analysé. * +* new = nouvelle vue du contenu chargé analysé. * * * -* Description : Réagit à un changement de contenu. * +* Description : Réagit à un changement de vue du contenu en cours d'analyse. * * * * Retour : - * * * @@ -162,79 +162,61 @@ static void _change_editor_item_view_python_wrapper(GEditorItem *item, GLoadedPa * * ******************************************************************************/ -static void _update_editor_item_view_python_wrapper(GEditorItem *item, GLoadedPanel *panel) +static void py_editor_item_change_view_wrapper(GEditorItem *item, GLoadedPanel *old, GLoadedPanel *new) { - PyObject *target; /* Version Python de l'élément */ + PyObject *pyobj; /* Objet Python concerné */ + PyThreadState *tstate; /* Contexte d'environnement */ + PyObject *pyold; /* Conversion ou None */ + PyObject *pynew; /* Conversion ou None */ PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Retour obtenu */ - - /** - * Normalement, l'objet Python est enregistré dans la liste de Chrysalide - * 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 - * par la procédure de pygobject, qui obligerait à connaître le type précis - * de l'instance GLib manipulée. - */ - target = pygobject_new(G_OBJECT(item)); - - args = PyTuple_New(1); - PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(panel))); + PyObject *pyret; /* Retour de Python */ - value = run_python_method(target, "update_view", args); + pyobj = pygobject_new(G_OBJECT(item)); - Py_XDECREF(value); - Py_DECREF(args); - Py_DECREF(target); + tstate = get_pychrysalide_main_tstate(); -} + if (tstate != NULL) + PyEval_RestoreThread(tstate); + if (has_python_method(pyobj, "_change_view")) + { + if (old != NULL) + pyold = pygobject_new(G_OBJECT(old)); + else + { + pyold = Py_None; + Py_INCREF(pyold); + } -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Réagit à un changement de contenu chargé en cours d'analyse. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ + if (new != NULL) + pynew = pygobject_new(G_OBJECT(new)); + else + { + pynew = Py_None; + Py_INCREF(pynew); + } -static PyObject *py_editor_item_change_content(PyObject *self, PyObject *args) -{ - Py_RETURN_NONE; + args = PyTuple_New(2); + PyTuple_SetItem(args, 0, pyold); + PyTuple_SetItem(args, 1, pynew); -} + pyret = run_python_method(pyobj, "_change_view", args); + Py_DECREF(args); + Py_DECREF(pyret); -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Réagit à un changement de vue du contenu en cours d'analyse. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ + } -static PyObject *py_editor_item_change_view(PyObject *self, PyObject *args) -{ - Py_RETURN_NONE; + if (tstate != NULL) + PyEval_SaveThread(); } /****************************************************************************** * * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * +* Paramètres : item = instance à consulter. * +* panel = vue du contenu chargé analysé modifiée. * * * * Description : Réagit à une modification de la vue du contenu analysé. * * * @@ -244,44 +226,44 @@ static PyObject *py_editor_item_change_view(PyObject *self, PyObject *args) * * ******************************************************************************/ -static PyObject *py_editor_item_update_view(PyObject *self, PyObject *args) +static void py_editor_item_update_view_wrapper(GEditorItem *item, GLoadedPanel *panel) { - Py_RETURN_NONE; + PyObject *pyobj; /* Objet Python concerné */ + PyThreadState *tstate; /* Contexte d'environnement */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *pyret; /* Retour de Python */ -} + pyobj = pygobject_new(G_OBJECT(item)); + tstate = get_pychrysalide_main_tstate(); -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Procède à l'enregistrement d'un élément reactif de l'éditeur.* -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ + if (tstate != NULL) + PyEval_RestoreThread(tstate); -static PyObject *py_editor_item_register(PyObject *self, PyObject *args) -{ - //GEditorItem *item; /* Version GLib de l'élément */ + if (has_python_method(pyobj, "_update_view")) + { + args = PyTuple_New(1); + PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(panel))); - //item = G_EDITOR_ITEM(pygobject_get(self)); + pyret = run_python_method(pyobj, "_update_view", args); - //item->update_binary = _change_editor_item_content_python_wrapper; - //item->update_view = _change_editor_item_view_python_wrapper; - //item->update_content = _update_editor_item_view_python_wrapper; + Py_DECREF(args); + Py_DECREF(pyret); - Py_INCREF(self); - //register_editor_item(item); + } - Py_RETURN_NONE; + if (tstate != NULL) + PyEval_SaveThread(); } + +/* ---------------------------------------------------------------------------------- */ +/* FONCTIONNALITES D'UN ELEMENT */ +/* ---------------------------------------------------------------------------------- */ + + /****************************************************************************** * * * Paramètres : - * @@ -297,26 +279,6 @@ static PyObject *py_editor_item_register(PyObject *self, PyObject *args) PyTypeObject *get_python_editor_item_type(void) { static PyMethodDef py_editor_item_methods[] = { - { - "change_content", py_editor_item_change_content, - METH_VARARGS, - "change_content($self, /)\n--\n\nCalled by Chrysalide on each content change, if the item is registered." - }, - { - "change_view", py_editor_item_change_view, - METH_VARARGS, - "change_view($self, /)\n--\n\nCalled by Chrysalide on each view change, if the item is registered." - }, - { - "update_view", py_editor_item_update_view, - METH_VARARGS, - "update_view($self, /)\n--\n\nCalled by Chrysalide on each view content change, if the item is registered." - }, - { - "register", py_editor_item_register, - METH_NOARGS, - "register($self, /)\n--\n\nregister($self, /)\n--\n\nRegister the item as editor item." - }, { NULL } }; |