summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/gui/core
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-12-14 16:38:10 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-12-14 16:38:10 (GMT)
commit97fa09113c7988e4b4639190ba9bc51f9ced4d33 (patch)
tree1b4fe85843b4cdbf685e5116a96c4f387a865561 /plugins/pychrysalide/gui/core
parente526727b94444030a3ae4dc6d4431cb72aea31e0 (diff)
Extended the Python API to build custom GUI panels.
Diffstat (limited to 'plugins/pychrysalide/gui/core')
-rw-r--r--plugins/pychrysalide/gui/core/Makefile.am3
-rw-r--r--plugins/pychrysalide/gui/core/module.c2
-rw-r--r--plugins/pychrysalide/gui/core/panels.c122
-rw-r--r--plugins/pychrysalide/gui/core/panels.h39
4 files changed, 165 insertions, 1 deletions
diff --git a/plugins/pychrysalide/gui/core/Makefile.am b/plugins/pychrysalide/gui/core/Makefile.am
index 08e50f1..4f7e05b 100644
--- a/plugins/pychrysalide/gui/core/Makefile.am
+++ b/plugins/pychrysalide/gui/core/Makefile.am
@@ -3,7 +3,8 @@ noinst_LTLIBRARIES = libpychrysaguicore.la
libpychrysaguicore_la_SOURCES = \
items.h items.c \
- module.h module.c
+ module.h module.c \
+ panels.h panels.c
libpychrysaguicore_la_LDFLAGS =
diff --git a/plugins/pychrysalide/gui/core/module.c b/plugins/pychrysalide/gui/core/module.c
index f90c70c..8a28c08 100644
--- a/plugins/pychrysalide/gui/core/module.c
+++ b/plugins/pychrysalide/gui/core/module.c
@@ -29,6 +29,7 @@
#include "items.h"
+#include "panels.h"
#include "../../helpers.h"
@@ -89,6 +90,7 @@ bool populate_gui_core_module(void)
result = true;
if (result) result = ensure_python_items_is_registered();
+ if (result) result = populate_gui_core_module_with_panels();
assert(result);
diff --git a/plugins/pychrysalide/gui/core/panels.c b/plugins/pychrysalide/gui/core/panels.c
new file mode 100644
index 0000000..3b88b18
--- /dev/null
+++ b/plugins/pychrysalide/gui/core/panels.c
@@ -0,0 +1,122 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * panels.c - équivalent Python du fichier "gui/core/panels.c"
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "panels.h"
+
+
+#include <pygobject.h>
+
+
+#include <core/params.h>
+#include <gui/core/panels.h>
+
+
+#include "../../access.h"
+#include "../../helpers.h"
+#include "../panels/panel.h"
+
+
+
+/* Enregistre un panneau comme partie intégrante de l'éditeur. */
+static PyObject *py_panels_register_item(PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Enregistre un panneau comme partie intégrante de l'éditeur. *
+* *
+* Retour : None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_panels_register_item(PyObject *self, PyObject *args)
+{
+ GPanelItem *item; /* Panneau à traiter */
+ GGenConfig *config; /* Configuration à consulter */
+ int ret; /* Bilan de lecture des args. */
+
+ config = NULL;
+
+ ret = PyArg_ParseTuple(args, "O&", convert_to_panel_item, &item);
+ if (!ret) return NULL;
+
+ if (config == NULL)
+ config = get_main_configuration();
+
+ register_panel_item(item, config);
+
+ /**
+ * Si Python ne voit plus la variable représentant le panneau utilisée,
+ * il va la supprimer, ce qui va supprimer le composant GTK.
+ *
+ * On sera donc en situation de Use-After-Free, dont les conséquences
+ * arrivent très vite.
+ */
+ pygobject_new(G_OBJECT(item));
+
+ Py_RETURN_NONE;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Définit une extension du module 'gui.core' à compléter. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool populate_gui_core_module_with_panels(void)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *module; /* Module à recompléter */
+
+ static PyMethodDef py_panels_methods[] = {
+
+ { "register_panel", py_panels_register_item,
+ METH_VARARGS,
+ "register_panel(item, config, /)\n--\n\nRegister a panel for the GUI."
+ },
+ { NULL }
+
+ };
+
+ module = get_access_to_python_module("pychrysalide.gui.core");
+
+ result = register_python_module_methods(module, py_panels_methods);
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/gui/core/panels.h b/plugins/pychrysalide/gui/core/panels.h
new file mode 100644
index 0000000..fd17908
--- /dev/null
+++ b/plugins/pychrysalide/gui/core/panels.h
@@ -0,0 +1,39 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * panels.h - prototypes pour l'équivalent Python du fichier "gui/core/panels.h"
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _PLUGINS_PYCHRYSALIDE_GUI_CORE_PANELS_H
+#define _PLUGINS_PYCHRYSALIDE_GUI_CORE_PANELS_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Définit une extension du module 'gui.core' à compléter. */
+bool populate_gui_core_module_with_panels(void);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_GUI_CORE_PANELS_H */