summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/gui
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/gui')
-rw-r--r--plugins/pychrysa/gui/editem.c69
-rw-r--r--plugins/pychrysa/gui/editem.h5
-rw-r--r--plugins/pychrysa/gui/module.c43
-rw-r--r--plugins/pychrysa/gui/panels/log.c108
-rw-r--r--plugins/pychrysa/gui/panels/log.h5
-rw-r--r--plugins/pychrysa/gui/panels/module.c43
-rw-r--r--plugins/pychrysa/gui/panels/module.h2
-rw-r--r--plugins/pychrysa/gui/panels/panel.c85
-rw-r--r--plugins/pychrysa/gui/panels/panel.h10
9 files changed, 238 insertions, 132 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;
}
diff --git a/plugins/pychrysa/gui/editem.h b/plugins/pychrysa/gui/editem.h
index 197efd5..329a79e 100644
--- a/plugins/pychrysa/gui/editem.h
+++ b/plugins/pychrysa/gui/editem.h
@@ -31,8 +31,11 @@
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_editor_item_type(void);
+
/* Prend en charge l'objet 'pychrysalide.gui.EditorItem'. */
-bool register_python_editor_item(PyObject *module);
+bool register_python_editor_item(PyObject *);
diff --git a/plugins/pychrysa/gui/module.c b/plugins/pychrysa/gui/module.c
index 605877f..0c5403e 100644
--- a/plugins/pychrysa/gui/module.c
+++ b/plugins/pychrysa/gui/module.c
@@ -25,6 +25,10 @@
#include "module.h"
+#include <assert.h>
+
+
+
#include "editem.h"
#include "panels/module.h"
@@ -44,27 +48,46 @@
bool add_gui_module_to_python_module(PyObject *super)
{
- bool result;
- PyObject *module;
+ bool result; /* Bilan à retourner */
+ PyObject *module; /* Sous-module mis en place */
int ret; /* Bilan d'un appel */
- static PyMethodDef py_gui_methods[] = {
- { NULL }
+ static PyModuleDef py_chrysalide_gui_module = {
+
+ .m_base = PyModuleDef_HEAD_INIT,
+
+ .m_name = "pychrysalide.gui",
+ .m_doc = "Python module for the Chrysalide GUI",
+
+ .m_size = -1,
+
};
- module = Py_InitModule("pychrysalide.gui", py_gui_methods);
+ result = false;
+
+ module = PyModule_Create(&py_chrysalide_gui_module);
if (module == NULL) return false;
- Py_INCREF(module);
- ret = PyModule_AddObject(super, "pychrysalide.gui", module);
+ ret = PyState_AddModule(super, &py_chrysalide_gui_module);
+ if (ret != 0) goto loading_failed;
- result = (ret == 0);
+ ret = _PyImport_FixupBuiltin(module, "pychrysalide.gui");
+ if (ret != 0) goto loading_failed;
+
+ Py_INCREF(module);
+ ret = PyModule_AddObject(super, "gui", module);
+ if (ret != 0) goto loading_failed;
- if (ret != 0) /* ... */;
+ result = true;
result &= register_python_editor_item(module);
+
result &= add_gui_panels_module_to_python_module(module);
- return true;
+ loading_failed:
+
+ assert(result);
+
+ return result;
}
diff --git a/plugins/pychrysa/gui/panels/log.c b/plugins/pychrysa/gui/panels/log.c
index 00f4e9e..ba68fe9 100644
--- a/plugins/pychrysa/gui/panels/log.c
+++ b/plugins/pychrysa/gui/panels/log.c
@@ -25,11 +25,14 @@
#include "log.h"
-
#include <pygobject.h>
-#include "../../quirks.h"
+#include <gui/panels/log.h>
+
+
+#include "panel.h"
+#include "../../helpers.h"
@@ -37,7 +40,7 @@
static PyObject *py_log_panel_log_message(PyObject *, PyObject *);
/* Définit les constantes pour les types de message. */
-static bool define_python_log_constants(PyObject *);
+static bool define_python_log_constants(PyTypeObject *);
@@ -90,7 +93,7 @@ static PyObject *py_log_panel_log_message(PyObject *self, PyObject *args)
/******************************************************************************
* *
-* Paramètres : dict = dictionnaire à compléter. *
+* Paramètres : obj_type = type dont le dictionnaire est à compléter. *
* *
* Description : Définit les constantes pour les types de message. *
* *
@@ -100,52 +103,42 @@ static PyObject *py_log_panel_log_message(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static bool define_python_log_constants(PyObject *dict)
+static bool define_python_log_constants(PyTypeObject *obj_type)
{
- int ret; /* Bilan d'un ajout */
-
- ret = PyDict_SetItemString(dict, "LMT_INFO", PyInt_FromLong(LMT_INFO));
- if (ret == -1) return false;
-
- ret = PyDict_SetItemString(dict, "LMT_BAD_BINARY", PyInt_FromLong(LMT_BAD_BINARY));
- if (ret == -1) return false;
+ bool result; /* Bilan à retourner */
- ret = PyDict_SetItemString(dict, "LMT_PROCESS", PyInt_FromLong(LMT_PROCESS));
- if (ret == -1) return false;
+ result = true;
- ret = PyDict_SetItemString(dict, "LMT_ERROR", PyInt_FromLong(LMT_ERROR));
- if (ret == -1) return false;
+ result &= PyDict_AddIntMacro(obj_type, LMT_INFO);
+ result &= PyDict_AddIntMacro(obj_type, LMT_BAD_BINARY);
+ result &= PyDict_AddIntMacro(obj_type, LMT_PROCESS);
+ result &= PyDict_AddIntMacro(obj_type, LMT_ERROR);
+ result &= PyDict_AddIntMacro(obj_type, LMT_WARNING);
- ret = PyDict_SetItemString(dict, "LMT_WARNING", PyInt_FromLong(LMT_WARNING));
- if (ret == -1) return false;
-
- return true;
+ return result;
}
/******************************************************************************
* *
-* Paramètres : module = module dont la définition est à compléter. *
+* Paramètres : - *
* *
-* Description : Prend en charge l'objet 'pychrysalide.gui.panels.LogPanel'. *
+* 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_log_panel(PyObject *module)
+PyTypeObject *get_python_log_panel_type(void)
{
- //PyObject *parent_mod; /* Module Python-EditorItem */
- int ret; /* Bilan d'un appel */
-
static PyMethodDef py_log_panel_methods[] = {
{
"log_message", (PyCFunction)py_log_panel_log_message,
METH_VARARGS | METH_STATIC,
- "Display a message in the log window."
+ "log_message(type, msg, /)\n--\n\nDisplay a message in the log window, if any."
},
{ NULL }
};
@@ -156,35 +149,62 @@ bool register_python_log_panel(PyObject *module)
static PyTypeObject py_log_panel_type = {
- PyObject_HEAD_INIT(NULL)
+ PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "pychrysalide.gui.panels.LogPanel",
- .tp_basicsize = sizeof(PyObject),
+ .tp_basicsize = sizeof(PyGObject),
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
.tp_doc = "PyChrysalide log panel",
.tp_methods = py_log_panel_methods,
- .tp_getset = py_log_panel_getseters,
+ .tp_getset = py_log_panel_getseters
};
- /*
- parent_mod = PyImport_ImportModule("pychrysalide.gui.panels");
- if (parent_mod == NULL) return false;
-
- py_log_panel_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "PanelItem");
- Py_DECREF(parent_mod);
- */
- if (PyType_Ready(&py_log_panel_type) < 0)
+
+ return &py_log_panel_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.gui.panels.LogPanel'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_log_panel(PyObject *module)
+{
+ PyTypeObject *py_log_panel_type; /* Type Python 'LoadedBinary' */
+ int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_log_panel_type = get_python_log_panel_type();
+
+ py_log_panel_type->tp_base = get_python_panel_item_type();
+ py_log_panel_type->tp_basicsize = py_log_panel_type->tp_base->tp_basicsize;
+
+ if (PyType_Ready(py_log_panel_type) != 0)
return false;
- if (!define_python_log_constants(py_log_panel_type.tp_dict))
+ if (!define_python_log_constants(py_log_panel_type))
return false;
- Py_INCREF(&py_log_panel_type);
- ret = PyModule_AddObject(module, "LogPanel", (PyObject *)&py_log_panel_type);
+ Py_INCREF(py_log_panel_type);
+ ret = PyModule_AddObject(module, "LogPanel", (PyObject *)py_log_panel_type);
+ if (ret != 0) return false;
- return (ret == 0);
+ dict = PyModule_GetDict(module);
+ pygobject_register_class(dict, "LogPanel", G_TYPE_LOG_PANEL, py_log_panel_type,
+ Py_BuildValue("(O)", py_log_panel_type->tp_base));
+
+ return true;
}
diff --git a/plugins/pychrysa/gui/panels/log.h b/plugins/pychrysa/gui/panels/log.h
index 08b1ae2..9b67e5a 100644
--- a/plugins/pychrysa/gui/panels/log.h
+++ b/plugins/pychrysa/gui/panels/log.h
@@ -29,12 +29,13 @@
#include <Python.h>
#include <stdbool.h>
-#include <gui/panels/log.h>
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_log_panel_type(void);
/* Prend en charge l'objet 'pychrysalide.gui.panels.LogPanel'. */
-bool register_python_log_panel(PyObject *module);
+bool register_python_log_panel(PyObject *);
diff --git a/plugins/pychrysa/gui/panels/module.c b/plugins/pychrysa/gui/panels/module.c
index bd13cd9..ca8845d 100644
--- a/plugins/pychrysa/gui/panels/module.c
+++ b/plugins/pychrysa/gui/panels/module.c
@@ -1,6 +1,6 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * module.c - intégration du répertoire arch en tant que module
+ * module.c - intégration du répertoire panels en tant que module
*
* Copyright (C) 2012-2013 Cyrille Bagard
*
@@ -25,6 +25,9 @@
#include "module.h"
+#include <assert.h>
+
+
#include "log.h"
#include "panel.h"
@@ -44,27 +47,45 @@
bool add_gui_panels_module_to_python_module(PyObject *super)
{
- bool result;
- PyObject *module;
+ bool result; /* Bilan à retourner */
+ PyObject *module; /* Sous-module mis en place */
int ret; /* Bilan d'un appel */
- static PyMethodDef py_gui_panels_methods[] = {
- { NULL }
+ static PyModuleDef py_chrysalide_panels_module = {
+
+ .m_base = PyModuleDef_HEAD_INIT,
+
+ .m_name = "gui.analysis.panels",
+ .m_doc = "Python module for Chrysalide.gui.panels",
+
+ .m_size = -1,
+
};
- module = Py_InitModule("pychrysalide.gui.panels", py_gui_panels_methods);
+ result = false;
+
+ module = PyModule_Create(&py_chrysalide_panels_module);
if (module == NULL) return false;
- Py_INCREF(module);
- ret = PyModule_AddObject(super, "pychrysalide.gui.panels", module);
+ ret = PyState_AddModule(super, &py_chrysalide_panels_module);
+ if (ret != 0) goto loading_failed;
+
+ ret = _PyImport_FixupBuiltin(module, "pychrysalide.gui.panels");
+ if (ret != 0) goto loading_failed;
- result = (ret == 0);
+ Py_INCREF(module);
+ ret = PyModule_AddObject(super, "panels", module);
+ if (ret != 0) goto loading_failed;
- if (ret != 0) /* ... */;
+ result = true;
result &= register_python_panel_item(module);
result &= register_python_log_panel(module);
- return true;
+ loading_failed:
+
+ assert(result);
+
+ return result;
}
diff --git a/plugins/pychrysa/gui/panels/module.h b/plugins/pychrysa/gui/panels/module.h
index c75a475..15d46a5 100644
--- a/plugins/pychrysa/gui/panels/module.h
+++ b/plugins/pychrysa/gui/panels/module.h
@@ -1,6 +1,6 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * module.h - prototypes pour l'intégration du répertoire gui.panels en tant que module
+ * module.h - prototypes pour l'intégration du répertoire panels en tant que module
*
* Copyright (C) 2012 Cyrille Bagard
*
diff --git a/plugins/pychrysa/gui/panels/panel.c b/plugins/pychrysa/gui/panels/panel.c
index 826982f..e713cc0 100644
--- a/plugins/pychrysa/gui/panels/panel.c
+++ b/plugins/pychrysa/gui/panels/panel.c
@@ -28,18 +28,24 @@
#include <pygobject.h>
-#include "../../quirks.h"
+#include <gui/panels/panel.h>
+
+
+#include "../editem.h"
/* Crée un nouvel objet Python de type 'PanelItem'. */
+#if 0
static PyObject *py_panel_item_new(PyTypeObject *, PyObject *, PyObject *);
+#endif
/* Place un panneau dans l'ensemble affiché. */
static PyObject *py_panel_item_dock(PyObject *, PyObject *);
+#if 0
/******************************************************************************
* *
* Paramètres : type = type de l'objet à instancier. *
@@ -110,6 +116,7 @@ PyObject *_py_panel_item_from_c(GPanelItem *item, PyTypeObject *type)
return pygobject_new(G_OBJECT(item));
}
+#endif
/******************************************************************************
@@ -138,40 +145,25 @@ static PyObject *py_panel_item_dock(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.panels.PanelItem'. *
+* 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_panel_item(PyObject *module)
+PyTypeObject *get_python_panel_item_type(void)
{
- PyObject *parent_mod; /* Module Python-EditorItem */
- int ret; /* Bilan d'un appel */
-
static PyMethodDef py_panel_item_methods[] = {
{
"dock", (PyCFunction)py_panel_item_dock,
METH_NOARGS,
- "Display the panel item in the right place."
+ "dock($self, /)\n--\n\nDisplay the panel item in the right place."
},
{ NULL }
};
@@ -182,34 +174,61 @@ bool register_python_panel_item(PyObject *module)
static PyTypeObject py_panel_item_type = {
- PyObject_HEAD_INIT(NULL)
+ PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "pychrysalide.gui.panels.PanelItem",
.tp_basicsize = sizeof(PyGObject),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- .tp_doc = "PyChrysalide panel item",
+ .tp_doc = "PyChrysalide panel item.",
.tp_methods = py_panel_item_methods,
.tp_getset = py_panel_item_getseters,
- .tp_new = (newfunc)py_panel_item_new,
- .tp_init = (initproc)pychrysalide_allow_args_for_gobjects
+ //.tp_new = (newfunc)py_panel_item_new,
+ //.tp_init = (initproc)pychrysalide_allow_args_for_gobjects
};
- parent_mod = PyImport_ImportModule("pychrysalide.gui");
- if (parent_mod == NULL) return false;
+ return &py_panel_item_type;
- py_panel_item_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "EditorItem");
- Py_DECREF(parent_mod);
+}
- if (PyType_Ready(&py_panel_item_type) < 0)
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.gui.panels.PanelItem'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_panel_item(PyObject *module)
+{
+ PyTypeObject *py_panel_item_type; /* Type Python 'LoadedBinary' */
+ int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_panel_item_type = get_python_panel_item_type();
+
+ py_panel_item_type->tp_base = get_python_editor_item_type();
+ py_panel_item_type->tp_basicsize = py_panel_item_type->tp_base->tp_basicsize;
+
+ if (PyType_Ready(py_panel_item_type) != 0)
return false;
- Py_INCREF(&py_panel_item_type);
- ret = PyModule_AddObject(module, "PanelItem", (PyObject *)&py_panel_item_type);
+ Py_INCREF(py_panel_item_type);
+ ret = PyModule_AddObject(module, "PanelItem", (PyObject *)py_panel_item_type);
+ if (ret != 0) return false;
+
+ dict = PyModule_GetDict(module);
+ pygobject_register_class(dict, "PanelItem", G_TYPE_PANEL_ITEM, py_panel_item_type,
+ Py_BuildValue("(O)", py_panel_item_type->tp_base));
- return (ret == 0);
+ return true;
}
diff --git a/plugins/pychrysa/gui/panels/panel.h b/plugins/pychrysa/gui/panels/panel.h
index 4c678b1..ecbee78 100644
--- a/plugins/pychrysa/gui/panels/panel.h
+++ b/plugins/pychrysa/gui/panels/panel.h
@@ -29,17 +29,13 @@
#include <Python.h>
#include <stdbool.h>
-#include <gui/panels/panel.h>
-
-/* Crée un nouvel objet Python de type 'PanelItem'. */
-PyObject *_py_panel_item_from_c(GPanelItem *, PyTypeObject *);
-
-#define py_panel_item_from_c(item) _py_panel_item_from_c(item, NULL)
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_panel_item_type(void);
/* Prend en charge l'objet 'pychrysalide.gui.panels.PanelItem'. */
-bool register_python_panel_item(PyObject *module);
+bool register_python_panel_item(PyObject *);