summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/gtkext
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-08-16 09:16:53 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-08-16 09:16:53 (GMT)
commitfb315963527f6412273829f09513325e446eb6c9 (patch)
tree361f19767812a8f758545e8daa2973fe0b3c9de7 /plugins/pychrysalide/gtkext
parent36945bffa2ca648b58c99905ebf9b1b536a9188a (diff)
Reorganized the Python plugin code.
Diffstat (limited to 'plugins/pychrysalide/gtkext')
-rw-r--r--plugins/pychrysalide/gtkext/blockdisplay.c26
-rw-r--r--plugins/pychrysalide/gtkext/blockdisplay.h2
-rw-r--r--plugins/pychrysalide/gtkext/bufferdisplay.c26
-rw-r--r--plugins/pychrysalide/gtkext/bufferdisplay.h2
-rw-r--r--plugins/pychrysalide/gtkext/displaypanel.c34
-rw-r--r--plugins/pychrysalide/gtkext/displaypanel.h2
-rw-r--r--plugins/pychrysalide/gtkext/dockable.c20
-rw-r--r--plugins/pychrysalide/gtkext/dockable.h2
-rw-r--r--plugins/pychrysalide/gtkext/module.c50
-rw-r--r--plugins/pychrysalide/gtkext/module.h7
10 files changed, 111 insertions, 60 deletions
diff --git a/plugins/pychrysalide/gtkext/blockdisplay.c b/plugins/pychrysalide/gtkext/blockdisplay.c
index c2ccfbb..6d53528 100644
--- a/plugins/pychrysalide/gtkext/blockdisplay.c
+++ b/plugins/pychrysalide/gtkext/blockdisplay.c
@@ -33,6 +33,7 @@
#include "bufferdisplay.h"
+#include "../access.h"
#include "../helpers.h"
@@ -97,19 +98,28 @@ PyTypeObject *get_python_block_display_type(void)
* *
******************************************************************************/
-bool register_python_block_display(PyObject *module)
+bool ensure_python_block_display_is_registered(void)
{
- bool result; /* Bilan à retourner */
- PyTypeObject *py_block_display_type; /* Type Python 'BlockDisplay' */
+ PyTypeObject *type; /* Type Python 'BlockDisplay' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_block_display_type = get_python_block_display_type();
+ type = get_python_block_display_type();
- dict = PyModule_GetDict(module);
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.gtkext");
- result = register_class_for_pygobject(dict, GTK_TYPE_BLOCK_DISPLAY,
- py_block_display_type, get_python_buffer_display_type());
+ dict = PyModule_GetDict(module);
- return result;
+ if (!ensure_python_buffer_display_is_registered())
+ return false;
+
+ if (!register_class_for_pygobject(dict, GTK_TYPE_BLOCK_DISPLAY, type, get_python_buffer_display_type()))
+ return false;
+
+ }
+
+ return true;
}
diff --git a/plugins/pychrysalide/gtkext/blockdisplay.h b/plugins/pychrysalide/gtkext/blockdisplay.h
index ab15ac5..30ee0db 100644
--- a/plugins/pychrysalide/gtkext/blockdisplay.h
+++ b/plugins/pychrysalide/gtkext/blockdisplay.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_block_display_type(void);
/* Prend en charge l'objet 'pychrysalide.gtkext.BlockDisplay'. */
-bool register_python_block_display(PyObject *module);
+bool ensure_python_block_display_is_registered(void);
diff --git a/plugins/pychrysalide/gtkext/bufferdisplay.c b/plugins/pychrysalide/gtkext/bufferdisplay.c
index 9aa1bca..d7f0bbd 100644
--- a/plugins/pychrysalide/gtkext/bufferdisplay.c
+++ b/plugins/pychrysalide/gtkext/bufferdisplay.c
@@ -33,6 +33,7 @@
#include "displaypanel.h"
+#include "../access.h"
#include "../helpers.h"
@@ -97,19 +98,28 @@ PyTypeObject *get_python_buffer_display_type(void)
* *
******************************************************************************/
-bool register_python_buffer_display(PyObject *module)
+bool ensure_python_buffer_display_is_registered(void)
{
- bool result; /* Bilan à retourner */
- PyTypeObject *py_buffer_display_type; /* Type Python 'BufferDisplay' */
+ PyTypeObject *type; /* Type Python 'BufferDisplay' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_buffer_display_type = get_python_buffer_display_type();
+ type = get_python_buffer_display_type();
- dict = PyModule_GetDict(module);
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.gtkext");
- result = register_class_for_pygobject(dict, GTK_TYPE_BUFFER_DISPLAY,
- py_buffer_display_type, get_python_display_panel_type());
+ dict = PyModule_GetDict(module);
- return result;
+ if (!ensure_python_display_panel_is_registered())
+ return false;
+
+ if (!register_class_for_pygobject(dict, GTK_TYPE_BUFFER_DISPLAY, type, get_python_display_panel_type()))
+ return false;
+
+ }
+
+ return true;
}
diff --git a/plugins/pychrysalide/gtkext/bufferdisplay.h b/plugins/pychrysalide/gtkext/bufferdisplay.h
index 4a21fb9..7f0b878 100644
--- a/plugins/pychrysalide/gtkext/bufferdisplay.h
+++ b/plugins/pychrysalide/gtkext/bufferdisplay.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_buffer_display_type(void);
/* Prend en charge l'objet 'pychrysalide.gtkext.BufferDisplay'. */
-bool register_python_buffer_display(PyObject *module);
+bool ensure_python_buffer_display_is_registered(void);
diff --git a/plugins/pychrysalide/gtkext/displaypanel.c b/plugins/pychrysalide/gtkext/displaypanel.c
index 16bd1d9..079ac73 100644
--- a/plugins/pychrysalide/gtkext/displaypanel.c
+++ b/plugins/pychrysalide/gtkext/displaypanel.c
@@ -32,6 +32,7 @@
#include <gtkext/gtkdisplaypanel.h>
+#include "../access.h"
#include "../helpers.h"
#include "../arch/vmpa.h"
@@ -152,32 +153,41 @@ PyTypeObject *get_python_display_panel_type(void)
* *
******************************************************************************/
-bool register_python_display_panel(PyObject *module)
+bool ensure_python_display_panel_is_registered(void)
{
bool result; /* Bilan à retourner */
- PyTypeObject *py_display_panel_type; /* Type Python 'DisplayPanel' */
+ PyTypeObject *type; /* Type Python 'DisplayPanel' */
PyObject *parent_mod; /* Module Python Fixed */
PyObject *fixed; /* Module "GtkFixed" */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
result = false;
- py_display_panel_type = get_python_display_panel_type();
+ type = get_python_display_panel_type();
- parent_mod = PyImport_ImportModule("gi.repository.Gtk");
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.gtkext");
- if (parent_mod == NULL)
- goto rpdp_exit;
+ parent_mod = PyImport_ImportModule("gi.repository.Gtk");
- fixed = PyObject_GetAttrString(parent_mod, "Fixed");
+ if (parent_mod == NULL)
+ goto rpdp_exit;
- Py_DECREF(parent_mod);
+ fixed = PyObject_GetAttrString(parent_mod, "Fixed");
- dict = PyModule_GetDict(module);
+ Py_DECREF(parent_mod);
- result = register_class_for_pygobject(dict, GTK_TYPE_DISPLAY_PANEL,
- py_display_panel_type, (PyTypeObject *)fixed);
- Py_DECREF(fixed);
+ dict = PyModule_GetDict(module);
+
+ result = register_class_for_pygobject(dict, GTK_TYPE_DISPLAY_PANEL, type, (PyTypeObject *)fixed);
+ Py_DECREF(fixed);
+
+ }
+
+ else
+ result = true;
rpdp_exit:
diff --git a/plugins/pychrysalide/gtkext/displaypanel.h b/plugins/pychrysalide/gtkext/displaypanel.h
index 318a9f6..d16a415 100644
--- a/plugins/pychrysalide/gtkext/displaypanel.h
+++ b/plugins/pychrysalide/gtkext/displaypanel.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_display_panel_type(void);
/* Prend en charge l'objet 'pychrysalide.gtkext.DisplayPanel'. */
-bool register_python_display_panel(PyObject *module);
+bool ensure_python_display_panel_is_registered(void);
diff --git a/plugins/pychrysalide/gtkext/dockable.c b/plugins/pychrysalide/gtkext/dockable.c
index 9c66159..f67e0fa 100644
--- a/plugins/pychrysalide/gtkext/dockable.c
+++ b/plugins/pychrysalide/gtkext/dockable.c
@@ -31,6 +31,9 @@
#include <gtkext/gtkdockable.h>
+#include "../access.h"
+
+
/******************************************************************************
* *
@@ -87,15 +90,22 @@ PyTypeObject *get_python_gtk_dockable_type(void)
* *
******************************************************************************/
-bool register_python_gtk_dockable(PyObject *module)
+bool ensure_python_gtk_dockable_is_registered(void)
{
- PyTypeObject *py_gtk_dockable_type; /* Type Python 'LineGenerator' */
+ PyTypeObject *type; /* Type Python 'GtkDockable' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_gtk_dockable_type = get_python_gtk_dockable_type();
+ type = get_python_gtk_dockable_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.gtkext");
+
+ dict = PyModule_GetDict(module);
+ pyg_register_interface(dict, "LineGenerator", GTK_TYPE_DOCKABLE, type);
- dict = PyModule_GetDict(module);
- pyg_register_interface(dict, "LineGenerator", GTK_TYPE_DOCKABLE, py_gtk_dockable_type);
+ }
return true;
diff --git a/plugins/pychrysalide/gtkext/dockable.h b/plugins/pychrysalide/gtkext/dockable.h
index dfec74d..29df25c 100644
--- a/plugins/pychrysalide/gtkext/dockable.h
+++ b/plugins/pychrysalide/gtkext/dockable.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_gtk_dockable_type(void);
/* Prend en charge l'objet 'pychrysalide.gtkext.GtkDockable'. */
-bool register_python_gtk_dockable(PyObject *);
+bool ensure_python_gtk_dockable_is_registered(void);
diff --git a/plugins/pychrysalide/gtkext/module.c b/plugins/pychrysalide/gtkext/module.c
index 8b2cc5e..2108b04 100644
--- a/plugins/pychrysalide/gtkext/module.c
+++ b/plugins/pychrysalide/gtkext/module.c
@@ -32,26 +32,26 @@
#include "bufferdisplay.h"
#include "displaypanel.h"
#include "dockable.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 'gtkext' au module Python. *
+* Description : Ajoute le module 'gtkext' à un module Python. *
* *
-* Retour : - *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool add_gtkext_module_to_python_module(PyObject *super)
+bool add_gtkext_module(PyObject *super)
{
bool result; /* Bilan à retourner */
PyObject *module; /* Sous-module mis en place */
- int ret; /* Bilan d'un appel */
static PyModuleDef py_chrysalide_gtkext_module = {
@@ -64,29 +64,37 @@ bool add_gtkext_module_to_python_module(PyObject *super)
};
- result = false;
+ module = build_python_module(super, &py_chrysalide_gtkext_module);
- module = PyModule_Create(&py_chrysalide_gtkext_module);
- if (module == NULL) return false;
+ result = (module != NULL);
- ret = PyState_AddModule(super, &py_chrysalide_gtkext_module);
- if (ret != 0) goto agmtpm_exit;
+ return result;
- ret = _PyImport_FixupBuiltin(module, "pychrysalide.gtkext");
- if (ret != 0) goto agmtpm_exit;
+}
- Py_INCREF(module);
- ret = PyModule_AddObject(super, "gtkext", module);
- if (ret != 0) goto agmtpm_exit;
- result = true;
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Intègre les objets du module 'gtkext'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- result &= register_python_display_panel(module);
- result &= register_python_buffer_display(module);
- result &= register_python_block_display(module);
- result &= register_python_gtk_dockable(module);
+bool populate_gtkext_module(void)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
- agmtpm_exit:
+ 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_gtk_dockable_is_registered();
assert(result);
diff --git a/plugins/pychrysalide/gtkext/module.h b/plugins/pychrysalide/gtkext/module.h
index 8d346cb..975055a 100644
--- a/plugins/pychrysalide/gtkext/module.h
+++ b/plugins/pychrysalide/gtkext/module.h
@@ -31,8 +31,11 @@
-/* Ajoute le module 'gtkext' au module Python. */
-bool add_gtkext_module_to_python_module(PyObject *);
+/* Ajoute le module 'gtkext' à un module Python. */
+bool add_gtkext_module(PyObject *);
+
+/* Intègre les objets du module 'gtkext'. */
+bool populate_gtkext_module(void);