diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-08-16 09:16:53 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-08-16 09:16:53 (GMT) |
commit | fb315963527f6412273829f09513325e446eb6c9 (patch) | |
tree | 361f19767812a8f758545e8daa2973fe0b3c9de7 /plugins/pychrysalide/gui | |
parent | 36945bffa2ca648b58c99905ebf9b1b536a9188a (diff) |
Reorganized the Python plugin code.
Diffstat (limited to 'plugins/pychrysalide/gui')
-rw-r--r-- | plugins/pychrysalide/gui/editem.c | 22 | ||||
-rw-r--r-- | plugins/pychrysalide/gui/editem.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/gui/module.c | 55 | ||||
-rw-r--r-- | plugins/pychrysalide/gui/module.h | 7 | ||||
-rw-r--r-- | plugins/pychrysalide/gui/panels/module.c | 50 | ||||
-rw-r--r-- | plugins/pychrysalide/gui/panels/module.h | 7 | ||||
-rw-r--r-- | plugins/pychrysalide/gui/panels/panel.c | 32 | ||||
-rw-r--r-- | plugins/pychrysalide/gui/panels/panel.h | 2 |
8 files changed, 108 insertions, 69 deletions
diff --git a/plugins/pychrysalide/gui/editem.c b/plugins/pychrysalide/gui/editem.c index 8fd2c17..03ad97a 100644 --- a/plugins/pychrysalide/gui/editem.c +++ b/plugins/pychrysalide/gui/editem.c @@ -31,9 +31,8 @@ #include <gui/editem-int.h> +#include "../access.h" #include "../helpers.h" - - #include "../analysis/binary.h" #include "../gtkext/displaypanel.h" @@ -357,17 +356,24 @@ PyTypeObject *get_python_editor_item_type(void) * * ******************************************************************************/ -bool register_python_editor_item(PyObject *module) +bool ensure_python_editor_item_is_registered(void) { - PyTypeObject *py_editor_item_type; /* Type Python 'LoadedBinary' */ + PyTypeObject *type; /* Type Python 'EditorItem' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_editor_item_type = get_python_editor_item_type(); + type = get_python_editor_item_type(); + + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.gui"); + + dict = PyModule_GetDict(module); - dict = PyModule_GetDict(module); + if (!register_class_for_pygobject(dict, G_TYPE_EDITOR_ITEM, type, &PyGObject_Type)) + return false; - if (!register_class_for_pygobject(dict, G_TYPE_EDITOR_ITEM, py_editor_item_type, &PyGObject_Type)) - return false; + } return true; diff --git a/plugins/pychrysalide/gui/editem.h b/plugins/pychrysalide/gui/editem.h index e34690c..9baebee 100644 --- a/plugins/pychrysalide/gui/editem.h +++ b/plugins/pychrysalide/gui/editem.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_editor_item_type(void); /* Prend en charge l'objet 'pychrysalide.gui.EditorItem'. */ -bool register_python_editor_item(PyObject *); +bool ensure_python_editor_item_is_registered(void); diff --git a/plugins/pychrysalide/gui/module.c b/plugins/pychrysalide/gui/module.c index 192b1e6..5dd9e72 100644 --- a/plugins/pychrysalide/gui/module.c +++ b/plugins/pychrysalide/gui/module.c @@ -31,64 +31,73 @@ #include "editem.h" #include "panels/module.h" -#include "../access.h" +#include "../helpers.h" /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : super = module dont la définition est à compléter. * * * -* Description : Ajoute le module 'gui' au module Python. * +* Description : Ajoute le module 'gui' à un module Python. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool add_gui_module_to_python_module(PyObject *super) +bool add_gui_module(PyObject *super) { bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ static PyModuleDef py_chrysalide_gui_module = { .m_base = PyModuleDef_HEAD_INIT, .m_name = "pychrysalide.gui", - .m_doc = "Python module for the Chrysalide GUI", + .m_doc = "Python module for Chrysalide.gui", .m_size = -1, }; - result = false; + module = build_python_module(super, &py_chrysalide_gui_module); - module = PyModule_Create(&py_chrysalide_gui_module); - if (module == NULL) return false; + result = (module != NULL); - ret = PyState_AddModule(super, &py_chrysalide_gui_module); - if (ret != 0) goto loading_failed; + if (result) result = add_gui_panels_module(module); - ret = _PyImport_FixupBuiltin(module, "pychrysalide.gui"); - if (ret != 0) goto loading_failed; + if (!result) + Py_XDECREF(module); - Py_INCREF(module); - ret = PyModule_AddObject(super, "gui", module); - if (ret != 0) goto loading_failed; + return result; - result = true; +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'gui'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - result &= register_python_editor_item(module); +bool populate_gui_module(void) +{ + bool result; /* Bilan à retourner */ - result &= add_gui_panels_module_to_python_module(module); + result = true; - if (result) - register_access_to_python_module("pychrysalide.gui", module); + if (result) result = ensure_python_editor_item_is_registered(); - loading_failed: + if (result) result = populate_gui_panels_module(); assert(result); diff --git a/plugins/pychrysalide/gui/module.h b/plugins/pychrysalide/gui/module.h index 8609d66..f97f3b2 100644 --- a/plugins/pychrysalide/gui/module.h +++ b/plugins/pychrysalide/gui/module.h @@ -31,8 +31,11 @@ -/* Ajoute le module 'gui' au module Python. */ -bool add_gui_module_to_python_module(PyObject *); +/* Ajoute le module 'gui' à un module Python. */ +bool add_gui_module(PyObject *); + +/* Intègre les objets du module 'gui'. */ +bool populate_gui_module(void); diff --git a/plugins/pychrysalide/gui/panels/module.c b/plugins/pychrysalide/gui/panels/module.c index 21b487e..dd6b91e 100644 --- a/plugins/pychrysalide/gui/panels/module.c +++ b/plugins/pychrysalide/gui/panels/module.c @@ -29,62 +29,66 @@ #include "panel.h" -#include "../../access.h" +#include "../../helpers.h" /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : super = module dont la définition est à compléter. * * * -* Description : Ajoute le module 'gui.panels' au module Python. * +* Description : Ajoute le module 'gui.panels' à un module Python. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool add_gui_panels_module_to_python_module(PyObject *super) +bool add_gui_panels_module(PyObject *super) { bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - static PyModuleDef py_chrysalide_panels_module = { + static PyModuleDef py_chrysalide_gui_panels_module = { .m_base = PyModuleDef_HEAD_INIT, - .m_name = "gui.analysis.panels", + .m_name = "pychrysalide.gui.panels", .m_doc = "Python module for Chrysalide.gui.panels", .m_size = -1, }; - result = false; + module = build_python_module(super, &py_chrysalide_gui_panels_module); - module = PyModule_Create(&py_chrysalide_panels_module); - if (module == NULL) return false; + result = (module != NULL); - ret = PyState_AddModule(super, &py_chrysalide_panels_module); - if (ret != 0) goto loading_failed; + return result; - ret = _PyImport_FixupBuiltin(module, "pychrysalide.gui.panels"); - if (ret != 0) goto loading_failed; +} - Py_INCREF(module); - ret = PyModule_AddObject(super, "panels", module); - if (ret != 0) goto loading_failed; - result = true; +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'gui.panels'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - result &= register_python_panel_item(module); +bool populate_gui_panels_module(void) +{ + bool result; /* Bilan à retourner */ - if (result) - register_access_to_python_module("pychrysalide.gui.panels", module); + result = true; - loading_failed: + if (result) result = ensure_python_panel_item_is_registered(); assert(result); diff --git a/plugins/pychrysalide/gui/panels/module.h b/plugins/pychrysalide/gui/panels/module.h index 34fac70..559a8c4 100644 --- a/plugins/pychrysalide/gui/panels/module.h +++ b/plugins/pychrysalide/gui/panels/module.h @@ -31,8 +31,11 @@ -/* Ajoute le module 'gui.panels' au module Python. */ -bool add_gui_panels_module_to_python_module(PyObject *); +/* Ajoute le module 'gui.panels' à un module Python. */ +bool add_gui_panels_module(PyObject *); + +/* Intègre les objets du module 'gui.panels'. */ +bool populate_gui_panels_module(void); diff --git a/plugins/pychrysalide/gui/panels/panel.c b/plugins/pychrysalide/gui/panels/panel.c index 72c9e7e..6613fac 100644 --- a/plugins/pychrysalide/gui/panels/panel.c +++ b/plugins/pychrysalide/gui/panels/panel.c @@ -34,6 +34,7 @@ #include "../editem.h" +#include "../../access.h" #include "../../helpers.h" #include "../../gtkext/dockable.h" @@ -223,21 +224,34 @@ static bool py_panel_item_define_constants(PyTypeObject *obj_type) * * ******************************************************************************/ -bool register_python_panel_item(PyObject *module) +bool ensure_python_panel_item_is_registered(void) { - PyTypeObject *py_panel_item_type; /* Type Python 'LoadedBinary' */ + PyTypeObject *type; /* Type Python 'LoadedBinary' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_panel_item_type = get_python_panel_item_type(); + type = get_python_panel_item_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.gui.panels"); - if (!_register_class_for_pygobject(dict, G_TYPE_PANEL_ITEM, py_panel_item_type, - get_python_editor_item_type(), get_python_gtk_dockable_type(), NULL)) - return false; + dict = PyModule_GetDict(module); - if (!py_panel_item_define_constants(py_panel_item_type)) - return false; + if (!ensure_python_editor_item_is_registered()) + return false; + + if (!ensure_python_gtk_dockable_is_registered()) + return false; + + if (!_register_class_for_pygobject(dict, G_TYPE_PANEL_ITEM, type, + get_python_editor_item_type(), get_python_gtk_dockable_type(), NULL)) + return false; + + if (!py_panel_item_define_constants(type)) + return false; + + } return true; diff --git a/plugins/pychrysalide/gui/panels/panel.h b/plugins/pychrysalide/gui/panels/panel.h index f0406d5..7fb473b 100644 --- a/plugins/pychrysalide/gui/panels/panel.h +++ b/plugins/pychrysalide/gui/panels/panel.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_panel_item_type(void); /* Prend en charge l'objet 'pychrysalide.gui.panels.PanelItem'. */ -bool register_python_panel_item(PyObject *); +bool ensure_python_panel_item_is_registered(void); |