diff options
Diffstat (limited to 'plugins/pychrysalide')
| -rw-r--r-- | plugins/pychrysalide/Makefile.am | 15 | ||||
| -rw-r--r-- | plugins/pychrysalide/bindings.c | 43 | ||||
| -rw-r--r-- | plugins/pychrysalide/bindings.h | 4 | ||||
| -rw-r--r-- | plugins/pychrysalide/core-ui.c | 52 | ||||
| -rw-r--r-- | plugins/pychrysalide/gtkext/Makefile.am | 30 | ||||
| -rw-r--r-- | plugins/pychrysalide/gtkext/module.c | 34 | ||||
| -rw-r--r-- | plugins/pychrysalide/gtkext/panel.c | 130 | ||||
| -rw-r--r-- | plugins/pychrysalide/gtkext/panel.h | 42 | ||||
| -rw-r--r-- | plugins/pychrysalide/helpers-ui.c | 141 | ||||
| -rw-r--r-- | plugins/pychrysalide/helpers-ui.h | 44 | ||||
| -rw-r--r-- | plugins/pychrysalide/helpers.c | 121 | ||||
| -rw-r--r-- | plugins/pychrysalide/helpers.h | 13 | 
12 files changed, 474 insertions, 195 deletions
| diff --git a/plugins/pychrysalide/Makefile.am b/plugins/pychrysalide/Makefile.am index f0cd477..c574727 100644 --- a/plugins/pychrysalide/Makefile.am +++ b/plugins/pychrysalide/Makefile.am @@ -15,12 +15,6 @@ endif  # if BUILD_GTK_SUPPORT -# GTKEXT_LIBADD =								\ -# 	gtkext/libpychrysagtkext.la - -# GTKEXT_SUBDIR = 							\ -# 	gtkext -  # GUI_LIBADD =								\  # 	gui/libpychrysagui.la @@ -51,7 +45,6 @@ AM_CFLAGS = $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) $(TOOLKIT_CFL  # 	common/libpychrysacommon.la				\  # 	core/libpychrysacore.la					\  # 	debug/libpychrysadebug.la				\ -# 	$(GTKEXT_LIBADD)						\  # 	$(GUI_LIBADD)							\  # 	mangling/libpychrysamangling.la			\  # 	plugins/libpychrysaplugins.la @@ -78,11 +71,13 @@ EXTRA_pychrysalideui_la_DEPENDENCIES = pychrysalide.la  pychrysalideui_la_SOURCES =					\  	core-ui-int.h							\ -	core-ui.h core-ui.c +	core-ui.h core-ui.c						\ +	helpers-ui.h helpers-ui.c  pychrysalideui_la_LIBADD =					\  	arch/libpychrysaarchui.la				\ -	glibext/libpychrysaglibextui.la +	glibext/libpychrysaglibextui.la			\ +	gtkext/libpychrysagtkext.la  # -ldl: dladdr(), dlerror()  pychrysalideui_la_LDFLAGS =					\ @@ -100,4 +95,4 @@ dev_HEADERS = $(pychrysalide_la_SOURCES:%c=)  #SUBDIRS = analysis arch common core debug  $(GTKEXT_SUBDIR) $(GUI_SUBDIR) mangling plugins -SUBDIRS = analysis arch common core format glibext plugins +SUBDIRS = analysis arch common core format glibext gtkext plugins diff --git a/plugins/pychrysalide/bindings.c b/plugins/pychrysalide/bindings.c index 5bc96a6..f120c3b 100644 --- a/plugins/pychrysalide/bindings.c +++ b/plugins/pychrysalide/bindings.c @@ -53,10 +53,6 @@  #include "glibext/module.h"  /* #include "debug/module.h" */  #include "format/module.h" -/* #ifdef INCLUDE_GTK_SUPPORT */ -/* #   include "gtkext/module.h" */ -/* #   include "gui/module.h" */ -/* #endif */  /* #include "mangling/module.h" */  #include "plugins/module.h" @@ -150,7 +146,7 @@ static void ensure_native_pygobject_type(PyTypeObject **);  static PyObject *get_existing_modules(void);  /* Définit les différents modules du support Python. */ -static PyObject *create_basic_modules(void); +static PyObject *create_basic_modules(const pyinit_details_t *);  /* Inscrit les défintions des objets Python de Chrysalide. */  static bool populate_python_modules(const pyinit_details_t *); @@ -980,7 +976,7 @@ static PyObject *get_existing_modules(void)  /******************************************************************************  *                                                                             * -*  Paramètres  : -                                                            * +*  Paramètres  : details = précisions de chargement complémentaires.          *  *                                                                             *  *  Description : Définit les différents modules du support Python.            *  *                                                                             * @@ -990,7 +986,7 @@ static PyObject *get_existing_modules(void)  *                                                                             *  ******************************************************************************/ -static PyObject *create_basic_modules(void) +static PyObject *create_basic_modules(const pyinit_details_t *details)  {      PyObject *result;                       /* Module Python à retourner   */      bool status;                            /* Bilan des inclusions        */ @@ -1038,14 +1034,17 @@ static PyObject *create_basic_modules(void)      */      if (status) status = add_format_module(result);      /* -#ifdef INCLUDE_GTK_SUPPORT -    if (status) status = add_gtkext_module(result); -    if (status) status = add_gui_module(result); -#endif      if (status) status = add_mangling_module(result);      */      if (status) status = add_plugins_module(result); +    /** +     * Ajout de modules UI supplémentaires éventuels. +     */ + +    if (status && details->add_extra != NULL) +        status = details->add_extra(result); +      if (!status)      {          Py_DECREF(result); @@ -1083,8 +1082,8 @@ static bool populate_python_modules(const pyinit_details_t *details)       * un chargement préliminaire, si besoin est.       */ -    if (details->populate_extra) -        result = details->populate_extra(); +    if (details->populate_extra != NULL) +        result = details->populate_extra(false);      else          result = true; @@ -1103,14 +1102,22 @@ static bool populate_python_modules(const pyinit_details_t *details)      */      if (result) result = populate_format_module();      /* -#ifdef INCLUDE_GTK_SUPPORT -    if (result) result = populate_gtkext_module(); -    if (result) result = populate_gui_module(); -#endif      if (result) result = populate_mangling_module();      */      if (result) result = populate_plugins_module(); +    /** +     * Certaines définitions reposent sur une déclinaison de GtkWidget, +     * dont le chargement va remplacer la définition statique de GObject +     * par une version allouée dynamiquement. +     * +     * De telles définitions doivent donc être prise en compte à la fin +     * du chargement. +     */ + +    if (result && details->populate_extra != NULL) +        result = details->populate_extra(true); +      return result;  } @@ -1204,7 +1211,7 @@ PyObject *init_python_pychrysalide_module(const pyinit_details_t *details)      ensure_native_pygobject_type(&py_gobj_def); -    result = create_basic_modules(); +    result = create_basic_modules(details);      if (result == NULL)          PyErr_SetString(PyExc_SystemError, "failed to create all PyChrysalide modules."); diff --git a/plugins/pychrysalide/bindings.h b/plugins/pychrysalide/bindings.h index 6bf2efa..036f852 100644 --- a/plugins/pychrysalide/bindings.h +++ b/plugins/pychrysalide/bindings.h @@ -55,7 +55,9 @@ typedef struct _pyinit_details_t  {      bool standalone;                        /* Chargement depuis Python ?  */ -    bool (* populate_extra) (void);         /* Ajout de types ?            */ +    bool (* add_extra) (PyObject *);        /* Ajout de modules ?          */ + +    bool (* populate_extra) (bool);         /* Ajout de types ?            */      /**       * Prototype de la fonction de création, à garder synchronisé avec diff --git a/plugins/pychrysalide/core-ui.c b/plugins/pychrysalide/core-ui.c index ebc32cb..0ea15df 100644 --- a/plugins/pychrysalide/core-ui.c +++ b/plugins/pychrysalide/core-ui.c @@ -36,6 +36,8 @@  #include "core-ui-int.h"  #include "arch/module-ui.h"  #include "glibext/module-ui.h" +#include "gtkext/module.h" +//#include "gui/module.h" @@ -83,8 +85,11 @@ static void g_pychrysalide_plugin_ui_handle_native_plugins_loaded_event(GPluginM  /* --------------------------- POINT D'ENTREE POUR PYTHON --------------------------- */ +/*Ajoute des modules UI aux extensions Python. */ +static bool add_python_ui_modules(PyObject *); +  /* Inscrit les défintions des objets UI Python de Chrysalide. */ -static bool populate_python_modules_ui(void); +static bool populate_python_modules_ui(bool); @@ -401,7 +406,32 @@ static void g_pychrysalide_plugin_ui_handle_native_plugins_loaded_event(GPluginM  /******************************************************************************  *                                                                             * -*  Paramètres  : -                                                            * +*  Paramètres  : super = module dont la définition est à compléter.           * +*                                                                             * +*  Description : Ajoute des modules UI aux extensions Python.                 * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool add_python_ui_modules(PyObject *super) +{ +    bool result;                            /* Bilan à retourner           */ + +    result = true; + +    if (result) result = add_gtkext_module(super); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : modify = autorisation de motification du type GObject.       *  *                                                                             *  *  Description : Inscrit les défintions des objets UI Python de Chrysalide.   *  *                                                                             * @@ -411,14 +441,25 @@ static void g_pychrysalide_plugin_ui_handle_native_plugins_loaded_event(GPluginM  *                                                                             *  ******************************************************************************/ -static bool populate_python_modules_ui(void) +static bool populate_python_modules_ui(bool modify)  {      bool result;                            /* Bilan à retourner           */      result = true; -    if (result) result = populate_arch_module_ui(); -    if (result) result = populate_glibext_module_ui(); +    if (!modify) +    { +        if (result) result = populate_arch_module_ui(); +        if (result) result = populate_glibext_module_ui(); + +    } + +    else +    { +        if (result) result = populate_gtkext_module(); +        //if (result) result = populate_gui_module(); + +    }      return result; @@ -444,6 +485,7 @@ PyMODINIT_FUNC PyInit_pychrysalideui(void)      details.standalone = _standalone; +    details.add_extra = add_python_ui_modules;      details.populate_extra = populate_python_modules_ui;      details.create_self = g_pychrysalide_plugin_ui_new; diff --git a/plugins/pychrysalide/gtkext/Makefile.am b/plugins/pychrysalide/gtkext/Makefile.am index 2e1260f..1d91751 100644 --- a/plugins/pychrysalide/gtkext/Makefile.am +++ b/plugins/pychrysalide/gtkext/Makefile.am @@ -1,19 +1,23 @@  noinst_LTLIBRARIES = libpychrysagtkext.la +# libpychrysagtkext_la_SOURCES =				\ +# 	blockdisplay.h blockdisplay.c			\ +# 	bufferdisplay.h bufferdisplay.c			\ +# 	displaypanel.h displaypanel.c			\ +# 	dockable.h dockable.c					\ +# 	easygtk.h easygtk.c						\ +# 	module.h module.c						\ +# 	named.h named.c +  libpychrysagtkext_la_SOURCES =				\ -	blockdisplay.h blockdisplay.c			\ -	bufferdisplay.h bufferdisplay.c			\ -	displaypanel.h displaypanel.c			\ -	dockable.h dockable.c					\ -	easygtk.h easygtk.c						\ -	module.h module.c						\ -	named.h named.c - -libpychrysagtkext_la_LIBADD =				\ -	graph/libpychrysagtkextgraph.la - -libpychrysagtkext_la_CFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ +	panel.h panel.c							\ +	module.h module.c + +# libpychrysagtkext_la_LIBADD =				\ +# 	graph/libpychrysagtkextgraph.la + +libpychrysagtkext_la_CFLAGS = $(LIBGTK4_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \  	-I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT @@ -22,4 +26,4 @@ devdir = $(includedir)/chrysalide/$(subdir)  dev_HEADERS = $(libpychrysagtkext_la_SOURCES:%c=) -SUBDIRS = graph +#SUBDIRS = graph diff --git a/plugins/pychrysalide/gtkext/module.c b/plugins/pychrysalide/gtkext/module.c index f8264af..fa59b2b 100644 --- a/plugins/pychrysalide/gtkext/module.c +++ b/plugins/pychrysalide/gtkext/module.c @@ -2,7 +2,7 @@  /* Chrysalide - Outil d'analyse de fichiers binaires   * module.c - intégration du répertoire gtkext en tant que module   * - * Copyright (C) 2018-2019 Cyrille Bagard + * Copyright (C) 2018-2025 Cyrille Bagard   *   *  This file is part of Chrysalide.   * @@ -28,13 +28,13 @@  #include <assert.h> -#include "blockdisplay.h" -#include "bufferdisplay.h" -#include "displaypanel.h" -#include "dockable.h" -#include "easygtk.h" -#include "named.h" -#include "graph/module.h" +//#include "blockdisplay.h" +//#include "bufferdisplay.h" +//#include "displaypanel.h" +//#include "dockable.h" +//#include "named.h" +#include "panel.h" +//#include "graph/module.h"  #include "../helpers.h" @@ -71,7 +71,7 @@ bool add_gtkext_module(PyObject *super)      result = (module != NULL); -    if (result) result = add_gtkext_graph_module(module); +    //if (result) result = add_gtkext_graph_module(module);      if (!result)          Py_XDECREF(module); @@ -99,14 +99,16 @@ bool populate_gtkext_module(void)      result = true; -    if (result) result = ensure_python_block_display_is_registered(); -    if (result) result = ensure_python_buffer_display_is_registered(); -    if (result) result = ensure_python_display_panel_is_registered(); -    if (result) result = ensure_python_dockable_is_registered(); -    if (result) result = ensure_python_easygtk_is_registered(); -    if (result) result = ensure_python_built_named_widget_is_registered(); +    if (result) result = ensure_python_tiled_panel_is_registered(); -    if (result) result = populate_gtkext_graph_module(); +    //if (result) result = ensure_python_block_display_is_registered(); +    //if (result) result = ensure_python_buffer_display_is_registered(); +    //if (result) result = ensure_python_display_panel_is_registered(); +    //if (result) result = ensure_python_dockable_is_registered(); +    //if (result) result = ensure_python_easygtk_is_registered(); +    //if (result) result = ensure_python_built_named_widget_is_registered(); + +    //if (result) result = populate_gtkext_graph_module();      assert(result); diff --git a/plugins/pychrysalide/gtkext/panel.c b/plugins/pychrysalide/gtkext/panel.c new file mode 100644 index 0000000..9f6589a --- /dev/null +++ b/plugins/pychrysalide/gtkext/panel.c @@ -0,0 +1,130 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * panel.c - prototypes pour l'équivalent Python du fichier "gtkext/panel.c" + * + * Copyright (C) 2025 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 "panel.h" + + +#include <pygobject.h> + + +#include <gtkext/panel.h> + + +#include "../access.h" +#include "../helpers.h" +#include "../helpers-ui.h" + + + +#define TILED_PANEL_DOC                                                     \ +    "The TiledPanel class defines a panel widget for the framework main"    \ +    " window." + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Fournit un accès à une définition de type à diffuser.        * +*                                                                             * +*  Retour      : Définition d'objet pour Python.                              * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +PyTypeObject *get_python_tiled_panel_type(void) +{ +    static PyMethodDef py_tiled_panel_methods[] = { +        { NULL } +    }; + +    static PyGetSetDef py_tiled_panel_getseters[] = { +        { NULL } +    }; + +    static PyTypeObject py_tiled_panel_type = { + +        PyVarObject_HEAD_INIT(NULL, 0) + +        .tp_name        = "pychrysalide.gtkext.TiledPanel", +        .tp_basicsize   = sizeof(PyGObject), + +        .tp_flags       = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + +        .tp_doc         = TILED_PANEL_DOC, + +        .tp_methods     = py_tiled_panel_methods, +        .tp_getset      = py_tiled_panel_getseters, + +    }; + +    static PyTypeObject *result = NULL; + +    if (result == NULL) +        result = define_python_dynamic_type(&py_tiled_panel_type); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Prend en charge l'objet 'pychrysalide.gtkext.TiledPanel'.    * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool ensure_python_tiled_panel_is_registered(void) +{ +    PyTypeObject *type;                     /* Type Python 'TiledPanel'    */ +    PyObject *module;                       /* Module à recompléter        */ +    PyObject *dict;                         /* Dictionnaire du module      */ + +    type = get_python_tiled_panel_type(); + +    if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) +    { +        module = get_access_to_python_module("pychrysalide.gtkext"); + +        dict = PyModule_GetDict(module); + +        if (!ensure_gtk_widget_is_registered()) +            return false; + +        if (!register_class_for_pygobject(dict, GTK_TYPE_TILED_PANEL, type)) +            return false; + +    } + +    return true; + +} diff --git a/plugins/pychrysalide/gtkext/panel.h b/plugins/pychrysalide/gtkext/panel.h new file mode 100644 index 0000000..c5cbe86 --- /dev/null +++ b/plugins/pychrysalide/gtkext/panel.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * panel.h - prototypes pour l'équivalent Python du fichier "gtkext/panel.h" + * + * Copyright (C) 2025 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_GTKEXT_PANEL_H +#define _PLUGINS_PYCHRYSALIDE_GTKEXT_PANEL_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_tiled_panel_type(void); + +/* Prend en charge l'objet 'pychrysalide.gtkext.TiledPanel'. */ +bool ensure_python_tiled_panel_is_registered(void); + + + +#endif  /* _PLUGINS_PYCHRYSALIDE_GTKEXT_PANEL_H */ diff --git a/plugins/pychrysalide/helpers-ui.c b/plugins/pychrysalide/helpers-ui.c new file mode 100644 index 0000000..982e676 --- /dev/null +++ b/plugins/pychrysalide/helpers-ui.c @@ -0,0 +1,141 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * helpers-ui.c - simplification des interactions UI de base avec Python + * + * Copyright (C) 2025 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 Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "helpers-ui.h" + + +#include <assert.h> +#include <pygobject.h> +#include <gtk/gtk.h> + + +#include "bindings.h" + + + +/* ---------------------------------------------------------------------------------- */ +/*                             CONFORTS CIBLANT PYGOBJECT                             */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Assure une prise en charge de l'objet Gtk.WIdget.            * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool ensure_gtk_widget_is_registered(void) +{ +    bool result;                            /* Bilan à retourner           */ +    PyObject *gtk_mod;                      /* Module Python Gtk           */ +    PyObject *widget_type;                  /* Module "GtkWidget"          */ + +    /** +     * Afin d'éviter le message d'avertissement suivant, la version attendue +     * est demandée : +     * +     *    PyGIWarning: Gtk was imported without specifying a version first. +     *    Use gi.require_version('Gtk', '4.0') before import to ensure that the right version gets loaded. +     * +     */ +    result = import_namespace_from_gi_repository("Gtk", "4.0"); + +    if (result) +    { +        gtk_mod = PyImport_ImportModule("gi.repository.Gtk"); +        assert(gtk_mod != NULL); + +        widget_type = PyObject_GetAttrString(gtk_mod, "Widget"); + +        result = (widget_type != NULL); + +        Py_DECREF(gtk_mod); +        Py_XDECREF(widget_type); + +    } + +    return result; + +} + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : arg = argument quelconque à tenter de convertir.             * +*                dst = destination des valeurs récupérées en cas de succès.   * +*                                                                             * +*  Description : Tente de convertir en instance de composant GTK.             * +*                                                                             * +*  Retour      : Bilan de l'opération, voire indications supplémentaires.     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +int convert_to_gtk_widget(PyObject *arg, void *dst) +{ +    int result;                             /* Bilan à retourner           */ +    PyObject *gtk_mod;                      /* Module Python Gtk           */ +    PyObject *widget_type;                  /* Module "GtkWidget"          */ +    int ret;                                /* Bilan d'une conversion      */ + +    result = 0; + +    gtk_mod = PyImport_ImportModule("gi.repository.Gtk"); + +    if (gtk_mod == NULL) +    { +        PyErr_SetString(PyExc_TypeError, "unable to find the Gtk Python module"); +        goto done; +    } + +    widget_type = PyObject_GetAttrString(gtk_mod, "Widget"); + +    Py_DECREF(gtk_mod); + +    ret = PyObject_TypeCheck(arg, (PyTypeObject *)widget_type); + +    Py_DECREF(widget_type); + +    if (!ret) +    { +        PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to GTK widget"); +        goto done; +    } + +    *((GtkWidget **)dst) = GTK_WIDGET(pygobject_get(arg)); + +    result = 1; + + done: + +    return result; + +} diff --git a/plugins/pychrysalide/helpers-ui.h b/plugins/pychrysalide/helpers-ui.h new file mode 100644 index 0000000..b575905 --- /dev/null +++ b/plugins/pychrysalide/helpers-ui.h @@ -0,0 +1,44 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * helpers-ui.h - prototypes pour la simplification des interactions UI de base avec Python + * + * Copyright (C) 2025 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 Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_HELPERS_UI_H +#define _PLUGINS_PYCHRYSALIDE_HELPERS_UI_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* --------------------------- CONFORTS CIBLANT PYGOBJECT --------------------------- */ + + +/* Assure une prise en charge de l'objet Gtk.WIdget. */ +bool ensure_gtk_widget_is_registered(void); + +/* Tente de convertir en instance de composant GTK. */ +int convert_to_gtk_widget(PyObject *, void *); + + + +#endif  /* _PLUGINS_PYCHRYSALIDE_HELPERS_UI_H */ diff --git a/plugins/pychrysalide/helpers.c b/plugins/pychrysalide/helpers.c index 0c84278..4ff768c 100644 --- a/plugins/pychrysalide/helpers.c +++ b/plugins/pychrysalide/helpers.c @@ -2,7 +2,7 @@  /* Chrysalide - Outil d'analyse de fichiers binaires   * helpers.c - simplification des interactions de base avec Python   * - * Copyright (C) 2018-2024 Cyrille Bagard + * Copyright (C) 2018-2025 Cyrille Bagard   *   *  This file is part of Chrysalide.   * @@ -32,9 +32,6 @@  #include <stdlib.h>  #include <string.h>  #include <strings.h> -#ifdef INCLUDE_GTK_SUPPORT -#   include <gtk/gtk.h> -#endif  #include <i18n.h> @@ -1260,122 +1257,6 @@ int convert_to_gobject(PyObject *arg, void *dst)  #if 0 -#ifdef INCLUDE_GTK_SUPPORT - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : arg = argument quelconque à tenter de convertir.             * -*                dst = destination des valeurs récupérées en cas de succès.   * -*                                                                             * -*  Description : Tente de convertir en instance de composant GTK.             * -*                                                                             * -*  Retour      : Bilan de l'opération, voire indications supplémentaires.     * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -int convert_to_gtk_widget(PyObject *arg, void *dst) -{ -    int result;                             /* Bilan à retourner           */ -    PyObject *gtk_mod;                      /* Module Python Gtk           */ -    PyObject *widget_type;                  /* Module "GtkWidget"          */ -    int ret;                                /* Bilan d'une conversion      */ - -    result = 0; - -    gtk_mod = PyImport_ImportModule("gi.repository.Gtk"); - -    if (gtk_mod == NULL) -    { -        PyErr_SetString(PyExc_TypeError, "unable to find the Gtk Python module"); -        goto done; -    } - -    widget_type = PyObject_GetAttrString(gtk_mod, "Widget"); - -    Py_DECREF(gtk_mod); - -    ret = PyObject_TypeCheck(arg, (PyTypeObject *)widget_type); - -    Py_DECREF(widget_type); - -    if (!ret) -    { -        PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to GTK widget"); -        goto done; -    } - -    *((GtkWidget **)dst) = GTK_WIDGET(pygobject_get(arg)); - -    result = 1; - - done: - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : arg = argument quelconque à tenter de convertir.             * -*                dst = destination des valeurs récupérées en cas de succès.   * -*                                                                             * -*  Description : Tente de convertir en instance de conteneur GTK.             * -*                                                                             * -*  Retour      : Bilan de l'opération, voire indications supplémentaires.     * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -int convert_to_gtk_container(PyObject *arg, void *dst) -{ -    int result;                             /* Bilan à retourner           */ -    PyObject *gtk_mod;                      /* Module Python Gtk           */ -    PyObject *container_type;               /* Module "GtkContainer"          */ -    int ret;                                /* Bilan d'une conversion      */ - -    result = 0; - -    gtk_mod = PyImport_ImportModule("gi.repository.Gtk"); - -    if (gtk_mod == NULL) -    { -        PyErr_SetString(PyExc_TypeError, "unable to find the Gtk Python module"); -        goto done; -    } - -    container_type = PyObject_GetAttrString(gtk_mod, "Container"); - -    Py_DECREF(gtk_mod); - -    ret = PyObject_TypeCheck(arg, (PyTypeObject *)container_type); - -    Py_DECREF(container_type); - -    if (!ret) -    { -        PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to GTK container"); -        goto done; -    } - -    *((GtkContainer **)dst) = GTK_CONTAINER(pygobject_get(arg)); - -    result = 1; - - done: - -    return result; - -} - - -#endif - -  /******************************************************************************  *                                                                             *  *  Paramètres  : color = couleur dans sa définition native à copier.          * diff --git a/plugins/pychrysalide/helpers.h b/plugins/pychrysalide/helpers.h index 745d013..f1c6337 100644 --- a/plugins/pychrysalide/helpers.h +++ b/plugins/pychrysalide/helpers.h @@ -2,7 +2,7 @@  /* Chrysalide - Outil d'analyse de fichiers binaires   * helpers.h - prototypes pour la simplification des interactions de base avec Python   * - * Copyright (C) 2018-2024 Cyrille Bagard + * Copyright (C) 2018-2025 Cyrille Bagard   *   *  This file is part of Chrysalide.   * @@ -313,17 +313,6 @@ int convert_to_gobject(PyObject *, void *);  #if 0 -#ifdef INCLUDE_GTK_SUPPORT - -/* Tente de convertir en instance de composant GTK. */ -int convert_to_gtk_widget(PyObject *, void *); - -/* Tente de convertir en instance de conteneur GTK. */ -int convert_to_gtk_container(PyObject *, void *); - -#endif - -  #if !defined(INCLUDE_GTK_SUPPORT) && !defined(HOMEMADE_RGBA)  #   define HOMEMADE_RGBA | 
