summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/helpers.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-07-12 13:52:22 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-07-12 13:52:22 (GMT)
commit2bd3ea7249d1234204c1b70abac8bc46e221fb95 (patch)
treef6b0f71d430bda2e8d762afbf5d084ac58cee640 /plugins/pychrysalide/helpers.c
parent6ea1b9a8550adf84cde510c2d4446c5120c4d065 (diff)
Improved the API for loaded contents.
Diffstat (limited to 'plugins/pychrysalide/helpers.c')
-rw-r--r--plugins/pychrysalide/helpers.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/plugins/pychrysalide/helpers.c b/plugins/pychrysalide/helpers.c
index 5c7ae75..3cd528e 100644
--- a/plugins/pychrysalide/helpers.c
+++ b/plugins/pychrysalide/helpers.c
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h>
+#include <gtk/gtk.h>
#include <i18n.h>
@@ -1132,6 +1133,61 @@ int convert_to_gobject(PyObject *arg, void *dst)
}
+/******************************************************************************
+* *
+* 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;
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* TRANSFERT DES VALEURS CONSTANTES */