summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/gui/panels/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/gui/panels/log.c')
-rw-r--r--plugins/pychrysa/gui/panels/log.c108
1 files changed, 64 insertions, 44 deletions
diff --git a/plugins/pychrysa/gui/panels/log.c b/plugins/pychrysa/gui/panels/log.c
index 00f4e9e..ba68fe9 100644
--- a/plugins/pychrysa/gui/panels/log.c
+++ b/plugins/pychrysa/gui/panels/log.c
@@ -25,11 +25,14 @@
#include "log.h"
-
#include <pygobject.h>
-#include "../../quirks.h"
+#include <gui/panels/log.h>
+
+
+#include "panel.h"
+#include "../../helpers.h"
@@ -37,7 +40,7 @@
static PyObject *py_log_panel_log_message(PyObject *, PyObject *);
/* Définit les constantes pour les types de message. */
-static bool define_python_log_constants(PyObject *);
+static bool define_python_log_constants(PyTypeObject *);
@@ -90,7 +93,7 @@ static PyObject *py_log_panel_log_message(PyObject *self, PyObject *args)
/******************************************************************************
* *
-* Paramètres : dict = dictionnaire à compléter. *
+* Paramètres : obj_type = type dont le dictionnaire est à compléter. *
* *
* Description : Définit les constantes pour les types de message. *
* *
@@ -100,52 +103,42 @@ static PyObject *py_log_panel_log_message(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static bool define_python_log_constants(PyObject *dict)
+static bool define_python_log_constants(PyTypeObject *obj_type)
{
- int ret; /* Bilan d'un ajout */
-
- ret = PyDict_SetItemString(dict, "LMT_INFO", PyInt_FromLong(LMT_INFO));
- if (ret == -1) return false;
-
- ret = PyDict_SetItemString(dict, "LMT_BAD_BINARY", PyInt_FromLong(LMT_BAD_BINARY));
- if (ret == -1) return false;
+ bool result; /* Bilan à retourner */
- ret = PyDict_SetItemString(dict, "LMT_PROCESS", PyInt_FromLong(LMT_PROCESS));
- if (ret == -1) return false;
+ result = true;
- ret = PyDict_SetItemString(dict, "LMT_ERROR", PyInt_FromLong(LMT_ERROR));
- if (ret == -1) return false;
+ result &= PyDict_AddIntMacro(obj_type, LMT_INFO);
+ result &= PyDict_AddIntMacro(obj_type, LMT_BAD_BINARY);
+ result &= PyDict_AddIntMacro(obj_type, LMT_PROCESS);
+ result &= PyDict_AddIntMacro(obj_type, LMT_ERROR);
+ result &= PyDict_AddIntMacro(obj_type, LMT_WARNING);
- ret = PyDict_SetItemString(dict, "LMT_WARNING", PyInt_FromLong(LMT_WARNING));
- if (ret == -1) return false;
-
- return true;
+ return result;
}
/******************************************************************************
* *
-* Paramètres : module = module dont la définition est à compléter. *
+* Paramètres : - *
* *
-* Description : Prend en charge l'objet 'pychrysalide.gui.panels.LogPanel'. *
+* Description : Fournit un accès à une définition de type à diffuser. *
* *
-* Retour : Bilan de l'opération. *
+* Retour : Définition d'objet pour Python. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool register_python_log_panel(PyObject *module)
+PyTypeObject *get_python_log_panel_type(void)
{
- //PyObject *parent_mod; /* Module Python-EditorItem */
- int ret; /* Bilan d'un appel */
-
static PyMethodDef py_log_panel_methods[] = {
{
"log_message", (PyCFunction)py_log_panel_log_message,
METH_VARARGS | METH_STATIC,
- "Display a message in the log window."
+ "log_message(type, msg, /)\n--\n\nDisplay a message in the log window, if any."
},
{ NULL }
};
@@ -156,35 +149,62 @@ bool register_python_log_panel(PyObject *module)
static PyTypeObject py_log_panel_type = {
- PyObject_HEAD_INIT(NULL)
+ PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "pychrysalide.gui.panels.LogPanel",
- .tp_basicsize = sizeof(PyObject),
+ .tp_basicsize = sizeof(PyGObject),
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
.tp_doc = "PyChrysalide log panel",
.tp_methods = py_log_panel_methods,
- .tp_getset = py_log_panel_getseters,
+ .tp_getset = py_log_panel_getseters
};
- /*
- parent_mod = PyImport_ImportModule("pychrysalide.gui.panels");
- if (parent_mod == NULL) return false;
-
- py_log_panel_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "PanelItem");
- Py_DECREF(parent_mod);
- */
- if (PyType_Ready(&py_log_panel_type) < 0)
+
+ return &py_log_panel_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.gui.panels.LogPanel'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_log_panel(PyObject *module)
+{
+ PyTypeObject *py_log_panel_type; /* Type Python 'LoadedBinary' */
+ int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_log_panel_type = get_python_log_panel_type();
+
+ py_log_panel_type->tp_base = get_python_panel_item_type();
+ py_log_panel_type->tp_basicsize = py_log_panel_type->tp_base->tp_basicsize;
+
+ if (PyType_Ready(py_log_panel_type) != 0)
return false;
- if (!define_python_log_constants(py_log_panel_type.tp_dict))
+ if (!define_python_log_constants(py_log_panel_type))
return false;
- Py_INCREF(&py_log_panel_type);
- ret = PyModule_AddObject(module, "LogPanel", (PyObject *)&py_log_panel_type);
+ Py_INCREF(py_log_panel_type);
+ ret = PyModule_AddObject(module, "LogPanel", (PyObject *)py_log_panel_type);
+ if (ret != 0) return false;
- return (ret == 0);
+ dict = PyModule_GetDict(module);
+ pygobject_register_class(dict, "LogPanel", G_TYPE_LOG_PANEL, py_log_panel_type,
+ Py_BuildValue("(O)", py_log_panel_type->tp_base));
+
+ return true;
}