diff options
Diffstat (limited to 'plugins/pychrysalide/glibext/loadedpanel.c')
-rw-r--r-- | plugins/pychrysalide/glibext/loadedpanel.c | 191 |
1 files changed, 150 insertions, 41 deletions
diff --git a/plugins/pychrysalide/glibext/loadedpanel.c b/plugins/pychrysalide/glibext/loadedpanel.c index d6b743b..6e87cde 100644 --- a/plugins/pychrysalide/glibext/loadedpanel.c +++ b/plugins/pychrysalide/glibext/loadedpanel.c @@ -30,29 +30,46 @@ #include <i18n.h> -#include <glibext/gloadedpanel.h> +#include <glibext/gloadedpanel-int.h> +#include "constants.h" #include "linecursor.h" #include "../access.h" #include "../helpers.h" +/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */ + + +/* Procède à l'initialisation de l'interface de génération. */ +static void py_loaded_panel_interface_init(GLoadedPanelIface *, gpointer *); + +/* S'assure qu'un emplacement donné est visible à l'écran. */ +static void py_loaded_panel_scroll_to_cursor_wrapper(GLoadedPanel *, const GLineCursor *, ScrollPositionTweak, bool); + + + +/* ------------------------- CONNEXION AVEC L'API DE PYTHON ------------------------- */ + + /* S'assure qu'un emplacement donné est visible à l'écran. */ static PyObject *py_loaded_panel_scroll_to_cursor(PyObject *, PyObject *); -/* Définit les constantes pour l'affichage des contenus chargés. */ -static bool py_loaded_panel_define_constants(PyTypeObject *); +/* ---------------------------------------------------------------------------------- */ +/* GLUE POUR CREATION DEPUIS PYTHON */ +/* ---------------------------------------------------------------------------------- */ + /****************************************************************************** * * -* Paramètres : self = classe représentant un tampon de code. * -* args = arguments fournis à l'appel. * +* Paramètres : iface = interface GLib à initialiser. * +* unused = adresse non utilisée ici. * * * -* Description : S'assure qu'un emplacement donné est visible à l'écran. * +* Description : Procède à l'initialisation de l'interface de génération. * * * * Retour : - * * * @@ -60,56 +77,143 @@ static bool py_loaded_panel_define_constants(PyTypeObject *); * * ******************************************************************************/ -static PyObject *py_loaded_panel_scroll_to_cursor(PyObject *self, PyObject *args) +static void py_loaded_panel_interface_init(GLoadedPanelIface *iface, gpointer *unused) { - GLineCursor *cursor; /* Emplacement à cibler */ - unsigned long tweak; /* Adapation à effectuer */ - int move; /* Déplacement à l'écran ? */ - int ret; /* Bilan de lecture des args. */ - GLoadedPanel *panel; /* Panneau à manipuler */ - ret = PyArg_ParseTuple(args, "O&kp", convert_to_line_cursor, &cursor, &tweak, &move); - if (!ret) return NULL; +#define LOADED_PANEL_DOC \ + "LoadPanel defines an interface for all panels which can be included" \ + " inside the main graphical window.\n" \ + "\n" \ + "A typical class declaration for a new implementation looks like:\n" \ + "\n" \ + " class NewImplem(GObject.Object, LoadedPanel():\n" \ + " ...\n" \ + "\n" \ + "The following methods have to be defined for new implementations:\n" \ + "* pychrysalide.glibext.LoadedPanel._scroll_to_cursor();\n" + + iface->scroll = py_loaded_panel_scroll_to_cursor_wrapper; + +} + + +/****************************************************************************** +* * +* Paramètres : panel = composant GTK à manipuler. * +* cursor = emplacement à présenter à l'écran. * +* tweak = adaptation finale à effectuer. * +* move = doit-on déplacer le curseur à l'adresse indiquée ? * +* * +* Description : S'assure qu'un emplacement donné est visible à l'écran. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ - if (!IS_VALID_STP(tweak)) +static void py_loaded_panel_scroll_to_cursor_wrapper(GLoadedPanel *panel, const GLineCursor *cursor, ScrollPositionTweak tweak, bool move) +{ + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ + PyObject *tweak_obj; /* Détails en versionPython */ + PyObject *move_obj; /* Consigne de déplacement */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *pyobj; /* Objet Python concerné */ + PyObject *pyret; /* Bilan de consultation */ + +#define LOADED_PANEL_SCROLL_TO_CURSOR_WRAPPER PYTHON_WRAPPER_DEF \ +( \ + _scroll_to_cursor, "$self, cursor, tweak, move, /", \ + METH_VARARGS, \ + "Abstract method used to ensure a given address is displayed in the view" \ + " panel.\n" \ + "\n" \ + "The *cursor* argument is a pychrysalide.glibext.LineCursor location. The" \ + " *tweak* parameter defines the final adjustment for new location and the" \ + " *move* order is a boolean value which implies a scroll operation if" \ + " requiered." \ +) + + gstate = PyGILState_Ensure(); + + pyobj = pygobject_new(G_OBJECT(panel)); + + if (has_python_method(pyobj, "_scroll_to_cursor")) { - PyErr_SetString(PyExc_ValueError, _("invalid position tweak")); - return NULL; - } + tweak_obj = cast_with_constants_group_from_type(get_python_loaded_panel_type(), + "ScrollPositionTweak", tweak); - panel = G_LOADED_PANEL(pygobject_get(self)); + move_obj = (move ? Py_True : Py_False); + Py_INCREF(move_obj); - g_loaded_panel_scroll_to_cursor(panel, cursor, tweak, move); + args = PyTuple_New(3); + PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(cursor))); + PyTuple_SetItem(args, 1, tweak_obj); + PyTuple_SetItem(args, 2, move_obj); - Py_RETURN_NONE; + pyret = run_python_method(pyobj, "_scroll_to_cursor", args); + + Py_XDECREF(pyret); + + Py_DECREF(args); + + } + + Py_DECREF(pyobj); + + PyGILState_Release(gstate); } + +/* ---------------------------------------------------------------------------------- */ +/* CONNEXION AVEC L'API DE PYTHON */ +/* ---------------------------------------------------------------------------------- */ + + /****************************************************************************** * * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* Paramètres : self = classe représentant un tampon de code. * +* args = arguments fournis à l'appel. * * * -* Description : Définit les constantes pour l'affichage des contenus chargés.* +* Description : S'assure qu'un emplacement donné est visible à l'écran. * * * -* Retour : true en cas de succès de l'opération, false sinon. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -static bool py_loaded_panel_define_constants(PyTypeObject *obj_type) +static PyObject *py_loaded_panel_scroll_to_cursor(PyObject *self, PyObject *args) { - bool result; /* Bilan à retourner */ + GLineCursor *cursor; /* Emplacement à cibler */ + ScrollPositionTweak tweak; /* Adapation à effectuer */ + int move; /* Déplacement à l'écran ? */ + int ret; /* Bilan de lecture des args. */ + GLoadedPanel *panel; /* Panneau à manipuler */ + +#define LOADED_PANEL_SCROLL_TO_CURSOR_METHOD PYTHON_METHOD_DEF \ +( \ + scroll_to_cursor, "$self, cursor, tweak, move, /", \ + METH_VARARGS, py_loaded_panel, \ + "Ensure a given address is displayed in the view panel.\n" \ + "\n" \ + "The *cursor* argument is a pychrysalide.glibext.LineCursor location. The" \ + " *tweak* parameter defines the final adjustment for new location and the" \ + " *move* order is a boolean value which implies a scroll operation if" \ + " requiered." \ +) + + ret = PyArg_ParseTuple(args, "O&O&p", convert_to_line_cursor, &cursor, + convert_to_scroll_position_tweak, &tweak, &move); + if (!ret) return NULL; - result = true; + panel = G_LOADED_PANEL(pygobject_get(self)); - result &= PyDict_AddULongMacro(obj_type, SPT_RAW); - result &= PyDict_AddULongMacro(obj_type, SPT_TOP); - result &= PyDict_AddULongMacro(obj_type, SPT_CENTER); - result &= PyDict_AddULongMacro(obj_type, SPT_BOTTOM); + g_loaded_panel_scroll_to_cursor(panel, cursor, tweak, move); - return result; + Py_RETURN_NONE; } @@ -129,11 +233,8 @@ static bool py_loaded_panel_define_constants(PyTypeObject *obj_type) PyTypeObject *get_python_loaded_panel_type(void) { static PyMethodDef py_loaded_panel_methods[] = { - { - "scroll_to_cursor", py_loaded_panel_scroll_to_cursor, - METH_VARARGS, - "scroll_to_cursor($self, cursor, tweak, move, /)\n--\n\nEnsure a given address is displayed in the view panel." - }, + LOADED_PANEL_SCROLL_TO_CURSOR_WRAPPER, + LOADED_PANEL_SCROLL_TO_CURSOR_METHOD, { NULL } }; @@ -146,11 +247,11 @@ PyTypeObject *get_python_loaded_panel_type(void) PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "pychrysalide.glibext.LoadedPanel", - //.tp_basicsize = sizeof(PyGObject), + .tp_basicsize = sizeof(PyObject), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_doc = "PyChrysalide loaded panel", + .tp_doc = LOADED_PANEL_DOC, .tp_methods = py_loaded_panel_methods, .tp_getset = py_loaded_panel_getseters, @@ -180,6 +281,14 @@ bool ensure_python_loaded_panel_is_registered(void) PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ + static GInterfaceInfo info = { /* Paramètres d'inscription */ + + .interface_init = (GInterfaceInitFunc)py_loaded_panel_interface_init, + .interface_finalize = NULL, + .interface_data = NULL, + + }; + type = get_python_loaded_panel_type(); if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) @@ -188,10 +297,10 @@ bool ensure_python_loaded_panel_is_registered(void) dict = PyModule_GetDict(module); - if (!register_interface_for_pygobject(dict, G_TYPE_LOADED_PANEL, type)) + if (!register_interface_for_pygobject_2(dict, G_TYPE_LOADED_PANEL, type, &info)) return false; - if (!py_loaded_panel_define_constants(type)) + if (!define_loaded_panel_constants(type)) return false; } |