[pygtksourceview] Manually wrap gtksourceview2.Gutter methods



commit 9e95e912d7dcad839a8c4a527e587e5a523a7a01
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Sat Aug 15 10:01:21 2009 +0200

    Manually wrap gtksourceview2.Gutter methods
    
    *_data_func methods needs to be manually wrapped
    (gtk_source_gutter_set_cell_data_func)
    (gtk_source_gutter_set_cell_size_func)
    
    add pygtksourceview-private.h
    
    include pygtksourceview-private.h into Makefile

 Makefile.am               |    2 +-
 gtksourceview2.override   |  172 +++++++++++++++++++++++++++++++++++++++++++++
 pygtksourceview-private.h |   31 ++++++++
 3 files changed, 204 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 06ad8fe..57e3bde 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,7 +33,7 @@ pyexec_LTLIBRARIES = gtksourceview2.la
 gtksourceview2_la_LDFLAGS = -module -avoid-version -export-symbols-regex initgtksourceview2 $(no_undefined) $(pyd_ext)
 gtksourceview2_la_CFLAGS = $(PYGTKSOURCEVIEW_CFLAGS)
 gtksourceview2_la_LIBADD = $(PYGTKSOURCEVIEW_LIBS) $(PYTHON_LIBS)
-gtksourceview2_la_SOURCES = gtksourceview2module.c 
+gtksourceview2_la_SOURCES = gtksourceview2module.c pygtksourceview-private.h
 nodist_gtksourceview2_la_SOURCES = gtksourceview2.c
 gtksourceview2.c: gtksourceview2.defs gtksourceview2.override
 CLEANFILES = gtksourceview2.c
diff --git a/gtksourceview2.override b/gtksourceview2.override
index b29f01e..508f1e4 100644
--- a/gtksourceview2.override
+++ b/gtksourceview2.override
@@ -4,6 +4,8 @@ headers
 #define NO_IMPORT_PYGOBJECT
 #include "pygobject.h"
 
+#include "pygtksourceview-private.h"
+
 #include <gtksourceview/gtksourceview.h>
 #include <gtksourceview/gtksourceview-typebuiltins.h>
 #include <gtksourceview/gtksourcelanguagemanager.h>
@@ -96,6 +98,21 @@ pylist_to_strv (PyObject *list,
     return TRUE;
 }
 
+void
+pygtksourceview_custom_destroy_notify(gpointer user_data)
+{
+    PyGtkSourceViewCustomNotify *cunote = user_data;
+    PyGILState_STATE state;
+
+    g_return_if_fail(user_data);
+    state = pyg_gil_state_ensure();
+    Py_XDECREF(cunote->func);
+    Py_XDECREF(cunote->data);
+    pyg_gil_state_release(state);
+    
+    g_free(cunote);
+}
+
 %%
 modulename gtksourceview2
 
@@ -469,3 +486,158 @@ _wrap_gtk_source_view_get_mark_category_background(PyGObject *self,
         return(Py_None);
     }
 }
+
+%%
+override gtk_source_gutter_set_cell_data_func kwargs
+static void
+pygtksourceview_cell_data_func_marshal (GtkSourceGutter *gutter,
+					GtkCellRenderer *cell,
+					gint line_number,
+					gboolean current_line,
+					gpointer data)
+{
+    PyGILState_STATE state;
+    PyGtkSourceViewCustomNotify *cunote = data;
+    PyObject *retobj;
+    PyObject *pygutter, *pycell;
+
+    g_assert (cunote->func);
+
+    state = pyg_gil_state_ensure();
+
+    pygutter = pygobject_new((GObject *)gutter);
+    pycell = pygobject_new((GObject *)cell);
+    
+    if (cunote->data)
+        retobj = PyEval_CallFunction(cunote->func, "(NNiiO)",
+                                     pygutter, pycell,
+                                     line_number, current_line, cunote->data);
+    else
+        retobj = PyEval_CallFunction(cunote->func, "(NNii)",
+                                     pygutter, pycell,
+                                     line_number, current_line);
+
+    if (retobj == NULL) {
+        PyErr_Print();
+    } else
+        Py_DECREF(retobj);
+
+    pyg_gil_state_release(state);
+}
+
+static PyObject *
+_wrap_gtk_source_gutter_set_cell_data_func (PyGObject *self,
+					    PyObject *args,
+                                            PyObject *kwargs)
+{
+    PyObject *pycell, *pyfunc, *pyarg = NULL;
+    GtkCellRenderer *cell;
+    PyGtkSourceViewCustomNotify *cunote;
+
+    if (!PyArg_ParseTuple(args, "OO|O:GtkSourceGutter.set_cell_data_func",
+                          &pycell, &pyfunc, &pyarg))
+        return NULL;
+
+    if (pygobject_check(pycell, &PyGtkCellRenderer_Type))
+        cell = GTK_CELL_RENDERER(pygobject_get(pycell));
+    else {
+        PyErr_SetString(PyExc_TypeError,
+                        "first argument must be a GtkCellRenderer");
+        return NULL;
+    }
+
+    if (pyfunc == Py_None) {
+	PyErr_SetString(PyExc_TypeError,
+                        "Function can't be None");
+    } else {
+	cunote = g_new0(PyGtkSourceViewCustomNotify, 1);
+	cunote->func = pyfunc;
+	cunote->data = pyarg;
+	Py_INCREF(cunote->func);
+	Py_XINCREF(cunote->data);
+
+	gtk_source_gutter_set_cell_data_func(GTK_SOURCE_GUTTER(self->obj), cell,
+					pygtksourceview_cell_data_func_marshal,
+                                        cunote,
+                                        pygtksourceview_custom_destroy_notify);
+    }
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+%%
+override gtk_source_gutter_set_cell_size_func kwargs
+static void
+pygtksourceview_cell_size_func_marshal (GtkSourceGutter *gutter,
+					GtkCellRenderer *cell,
+					gpointer data)
+{
+    PyGILState_STATE state;
+    PyGtkSourceViewCustomNotify *cunote = data;
+    PyObject *retobj;
+    PyObject *pygutter, *pycell;
+
+    g_assert (cunote->func);
+
+    state = pyg_gil_state_ensure();
+
+    pygutter = pygobject_new((GObject *)gutter);
+    pycell = pygobject_new((GObject *)cell);
+    
+    if (cunote->data)
+        retobj = PyEval_CallFunction(cunote->func, "(NNO)",
+                                     pygutter, pycell,
+                                     cunote->data);
+    else
+        retobj = PyEval_CallFunction(cunote->func, "(NN)",
+                                     pygutter, pycell);
+
+    if (retobj == NULL) {
+        PyErr_Print();
+    } else
+        Py_DECREF(retobj);
+
+    pyg_gil_state_release(state);
+}
+
+static PyObject *
+_wrap_gtk_source_gutter_set_cell_size_func (PyGObject *self,
+					    PyObject *args,
+                                            PyObject *kwargs)
+{
+    PyObject *pycell, *pyfunc, *pyarg = NULL;
+    GtkCellRenderer *cell;
+    PyGtkSourceViewCustomNotify *cunote;
+
+    if (!PyArg_ParseTuple(args, "OO|O:GtkSourceGutter.set_cell_size_func",
+                          &pycell, &pyfunc, &pyarg))
+        return NULL;
+
+    if (pygobject_check(pycell, &PyGtkCellRenderer_Type))
+        cell = GTK_CELL_RENDERER(pygobject_get(pycell));
+    else {
+        PyErr_SetString(PyExc_TypeError,
+                        "first argument must be a GtkCellRenderer");
+        return NULL;
+    }
+
+    if (pyfunc == Py_None) {
+	PyErr_SetString(PyExc_TypeError,
+                        "func must be a callable object");
+    } else {
+	cunote = g_new0(PyGtkSourceViewCustomNotify, 1);
+	cunote->func = pyfunc;
+	cunote->data = pyarg;
+	Py_INCREF(cunote->func);
+	Py_XINCREF(cunote->data);
+
+	gtk_source_gutter_set_cell_size_func(GTK_SOURCE_GUTTER(self->obj), cell,
+					pygtksourceview_cell_size_func_marshal,
+                                        cunote,
+                                        pygtksourceview_custom_destroy_notify);
+    }
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
diff --git a/pygtksourceview-private.h b/pygtksourceview-private.h
new file mode 100644
index 0000000..040476d
--- /dev/null
+++ b/pygtksourceview-private.h
@@ -0,0 +1,31 @@
+/* PyGtkSourceView2 - Python bindings for GtkSourceView2.
+   Copyright (C) 2009 - Gian Mario Tagliaretti <gianmt gnome org>
+   
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License
+   as published by the Free Software Foundation;
+   
+   This program 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 Lesser 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 _PYGTKSOURCEVIEW_PRIVATE_H_
+#define _PYGTKSOURCEVIEW_PRIVATE_H_
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+typedef struct {
+    PyObject *func, *data;
+} PyGtkSourceViewCustomNotify;
+
+void pygtksourceview_custom_destroy_notify(gpointer user_data);
+
+#endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]