[libchamplain] Update champlain and champlainmemphis python bindings.



commit ed0d1aecd9603c84d1af923ad08ce13a5d07d648
Author: Victor Godoy Poluceno <victorpoluceno gmail com>
Date:   Mon May 3 18:18:10 2010 -0300

    Update champlain and champlainmemphis python bindings.
    
    Add new wraped functions and properly dispose of gboxed objects.

 bindings/python/champlain/pychamplain.override     |   89 +++++++++++
 .../python/champlain/pychamplainmemphis.override   |  163 ++++++++++++++++++++
 .../python/champlain/pychamplainmemphismodule.c    |   10 ++
 bindings/python/champlain/pychamplainmodule.c      |   10 ++
 4 files changed, 272 insertions(+), 0 deletions(-)
---
diff --git a/bindings/python/champlain/pychamplain.override b/bindings/python/champlain/pychamplain.override
index 719d608..2d4d292 100644
--- a/bindings/python/champlain/pychamplain.override
+++ b/bindings/python/champlain/pychamplain.override
@@ -491,7 +491,66 @@ _wrap_champlain_point__set_lon(PyGBoxed *self, PyObject *value,
     pyg_boxed_get(self, ChamplainPoint)->lon = val;
     return 0;
 }
+%%
+override-attr ChamplainBoundingBox.left
+static int
+_wrap_champlain_bounding_box__set_left (PyGBoxed *self, PyObject *value, 
+    void *closure)
+{
+    gdouble val;
+
+    val = PyFloat_AsDouble(value);
+    if (PyErr_Occurred())
+        return -1;
+
+    pyg_boxed_get(self, ChamplainBoundingBox)->left = val;
+    return 0;
+}
+%%
+override-attr ChamplainBoundingBox.right
+static int
+_wrap_champlain_bounding_box__set_right (PyGBoxed *self, PyObject *value, 
+    void *closure)
+{
+    gdouble val;
+
+    val = PyFloat_AsDouble(value);
+    if (PyErr_Occurred())
+        return -1;
+
+    pyg_boxed_get(self, ChamplainBoundingBox)->right = val;
+    return 0;
+}
+%%
+override-attr ChamplainBoundingBox.top
+static int
+_wrap_champlain_bounding_box__set_top (PyGBoxed *self, PyObject *value, 
+    void *closure)
+{
+    gdouble val;
+
+    val = PyFloat_AsDouble(value);
+    if (PyErr_Occurred())
+        return -1;
+
+    pyg_boxed_get(self, ChamplainBoundingBox)->top = val;
+    return 0;
+}
+%%
+override-attr ChamplainBoundingBox.bottom
+static int
+_wrap_champlain_bounding_box__set_bottom (PyGBoxed *self, PyObject *value, 
+    void *closure)
+{
+    gdouble val;
+
+    val = PyFloat_AsDouble(value);
+    if (PyErr_Occurred())
+        return -1;
 
+    pyg_boxed_get(self, ChamplainBoundingBox)->bottom = val;
+    return 0;
+}
 %%
 override champlain_selection_layer_get_selected_markers kwargs
 static PyObject *
@@ -562,3 +621,33 @@ _wrap_champlain_polygon_tp_dealloc (PyObject *self)
 {
     self->ob_type->tp_free((PyObject*)self);
 }
+%%
+override champlain_file_cache_new_full kwargs
+static PyObject *
+_wrap_champlain_file_cache_new_full(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = { "size_limit", "cache_dir", "persistent", NULL };
+    PyObject *py_size_limit = NULL;
+    char *cache_dir = NULL;
+    int persistent;
+    ChamplainFileCache *ret;
+    guint size_limit = 0;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,"Ozi:file_cache_new_full", kwlist, &py_size_limit, &cache_dir, &persistent))
+        return NULL;
+    if (py_size_limit) {
+        if (PyLong_Check(py_size_limit))
+            size_limit = PyLong_AsUnsignedLong(py_size_limit);
+        else if (PyInt_Check(py_size_limit))
+            size_limit = PyInt_AsLong(py_size_limit);
+        else
+            PyErr_SetString(PyExc_TypeError, "Parameter 'size_limit' must be an int or a long");
+        if (PyErr_Occurred())
+            return NULL;
+    }
+    
+    ret = champlain_file_cache_new_full(size_limit, cache_dir, persistent);
+    
+    /* pygobject_new handles NULL checking */
+    return pygobject_new((GObject *)ret);
+}
diff --git a/bindings/python/champlain/pychamplainmemphis.override b/bindings/python/champlain/pychamplainmemphis.override
index ba88a71..0c57c6a 100644
--- a/bindings/python/champlain/pychamplainmemphis.override
+++ b/bindings/python/champlain/pychamplainmemphis.override
@@ -1,4 +1,101 @@
 %%
+body
+
+static int
+_wrap_memphis_rule_new(PyGBoxed *self, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = { NULL };
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,":Memphis.Rule.__init__", kwlist))
+        return -1;
+    self->gtype = MEMPHIS_TYPE_RULE;
+    self->free_on_dealloc = FALSE;
+    self->boxed = memphis_rule_new();
+
+    if (!self->boxed) {
+        PyErr_SetString(PyExc_RuntimeError, "could not create MemphisRule object");
+        return -1;
+    }
+    self->free_on_dealloc = TRUE;
+    return 0;
+}
+
+static PyObject *
+_wrap_memphis_rule_copy(PyObject *self)
+{
+    MemphisRule *ret;
+
+    
+    ret = memphis_rule_copy(pyg_boxed_get(self, MemphisRule));
+    
+    /* pyg_boxed_new handles NULL checking */
+    return pyg_boxed_new(MEMPHIS_TYPE_RULE, ret, TRUE, TRUE);
+}
+
+static PyObject *
+_wrap_memphis_rule_free(PyObject *self)
+{
+    
+    memphis_rule_free(pyg_boxed_get(self, MemphisRule));
+    
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+static const PyMethodDef _PyChamplainMemphisRule_methods[] = {
+    { "copy", (PyCFunction)_wrap_memphis_rule_copy, METH_NOARGS,
+      NULL },
+    { "free", (PyCFunction)_wrap_memphis_rule_free, METH_NOARGS,
+      NULL },
+    { NULL, NULL, 0, NULL }
+};
+
+PyTypeObject G_GNUC_INTERNAL PyChamplainMemphisRule_Type = {
+    PyObject_HEAD_INIT(NULL)
+    0,                                 /* ob_size */
+    "memphis.Rule",                   /* tp_name */
+    sizeof(PyGBoxed),          /* tp_basicsize */
+    0,                                 /* tp_itemsize */
+    /* methods */
+    (destructor)0,        /* tp_dealloc */
+    (printfunc)0,                      /* tp_print */
+    (getattrfunc)0,       /* tp_getattr */
+    (setattrfunc)0,       /* tp_setattr */
+    (cmpfunc)0,           /* tp_compare */
+    (reprfunc)0,             /* tp_repr */
+    (PyNumberMethods*)0,     /* tp_as_number */
+    (PySequenceMethods*)0, /* tp_as_sequence */
+    (PyMappingMethods*)0,   /* tp_as_mapping */
+    (hashfunc)0,             /* tp_hash */
+    (ternaryfunc)0,          /* tp_call */
+    (reprfunc)0,              /* tp_str */
+    (getattrofunc)0,     /* tp_getattro */
+    (setattrofunc)0,     /* tp_setattro */
+    (PyBufferProcs*)0,  /* tp_as_buffer */
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,                      /* tp_flags */
+    NULL,                        /* Documentation string */
+    (traverseproc)0,     /* tp_traverse */
+    (inquiry)0,             /* tp_clear */
+    (richcmpfunc)0,   /* tp_richcompare */
+    0,             /* tp_weaklistoffset */
+    (getiterfunc)0,          /* tp_iter */
+    (iternextfunc)0,     /* tp_iternext */
+    (struct PyMethodDef*)_PyChamplainMemphisRule_methods, /* tp_methods */
+    (struct PyMemberDef*)0,              /* tp_members */
+    (struct PyGetSetDef*)0,  /* tp_getset */
+    NULL,                              /* tp_base */
+    NULL,                              /* tp_dict */
+    (descrgetfunc)0,    /* tp_descr_get */
+    (descrsetfunc)0,    /* tp_descr_set */
+    0,                 /* tp_dictoffset */
+    (initproc)_wrap_memphis_rule_new,             /* tp_init */
+    (allocfunc)0,           /* tp_alloc */
+    (newfunc)0,               /* tp_new */
+    (freefunc)0,             /* tp_free */
+    (inquiry)0              /* tp_is_gc */
+};
+
+%%
 headers
 #include <Python.h>
 #include <pygobject.h>
@@ -79,3 +176,69 @@ _wrap_champlain_bounding_box__set_bottom (PyGBoxed *self, PyObject *value,
     pyg_boxed_get(self, ChamplainBoundingBox)->bottom = val;
     return 0;
 }
+%%
+override champlain_memphis_tile_source_get_rule_ids kwargs
+static PyObject *
+_wrap_champlain_memphis_tile_source_get_rule_ids(PyGObject *self, PyObject *args) 
+{
+    GList *iter, *list;
+    PyObject *ret;
+
+    list = champlain_memphis_tile_source_get_rule_ids(
+        CHAMPLAIN_MEMPHIS_TILE_SOURCE(self->obj));
+
+    if ((ret = PyList_New(0)) == NULL)
+        return NULL;
+
+    for(iter = list; iter != NULL; iter = iter->next) {
+        PyList_Append(ret, PyString_FromString(iter->data));
+    }
+    g_list_free(list);
+    g_list_free(iter);
+    return ret;
+}
+%%
+override champlain_bounding_box_get_center kwargs
+static PyObject *
+_wrap_champlain_bounding_box_get_center(PyGObject *self, PyObject *args) 
+{
+    gdouble lat, lon;
+    champlain_bounding_box_get_center(CHAMPLAIN_BOUNDING_BOX(self->obj), &lat, &lon);
+    return Py_BuildValue("(dd)", lat, lon);
+}
+%%
+override champlain_memphis_tile_source_get_rule kwargs
+static PyObject *
+_wrap_champlain_memphis_tile_source_get_rule(PyGObject *self, PyObject *args, PyObject *kwargs) 
+{
+    static char *kwlist[] = { "id", NULL };
+    char *id = NULL;
+    MemphisRule *ret = NULL;
+    
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,"s:memphis_tile_source_get_rule", 
+            kwlist, &id))
+        return NULL;
+
+    ret = champlain_memphis_tile_source_get_rule(CHAMPLAIN_MEMPHIS_TILE_SOURCE(self->obj), id);
+     
+    /* pygobject_new handles NULL checking */
+    return pyg_boxed_new(MEMPHIS_TYPE_RULE, ret, TRUE, TRUE);
+}
+%%
+override champlain_memphis_tile_source_set_rule kwargs
+static PyObject *
+_wrap_champlain_memphis_tile_source_set_rule(PyGObject *self, PyObject *args, PyObject *kwargs) 
+{
+    static char *kwlist[] = { "rule", NULL };
+    PyGObject *rule = NULL;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:memphis_tile_source_set_rule", 
+            kwlist, &PyChamplainMemphisRule_Type, &rule))
+        return NULL;
+
+    champlain_memphis_tile_source_set_rule(CHAMPLAIN_MEMPHIS_TILE_SOURCE(self->obj), 
+            MEMPHIS_RULE(rule->obj));
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
diff --git a/bindings/python/champlain/pychamplainmemphismodule.c b/bindings/python/champlain/pychamplainmemphismodule.c
index ee69c8f..8ee7e07 100644
--- a/bindings/python/champlain/pychamplainmemphismodule.c
+++ b/bindings/python/champlain/pychamplainmemphismodule.c
@@ -5,6 +5,14 @@
 #include <champlain/champlain-memphis.h>
 #include "pychamplainmemphis.h" 
 
+static void
+sink_champlain_map_data_source (GObject *object)
+{
+    if (g_object_is_floating (object)) {
+        g_object_ref_sink (object);
+    }
+}
+
 extern PyMethodDef champlainmemphis_functions[];
 DL_EXPORT(void) initchamplainmemphis (void);
 
@@ -15,6 +23,8 @@ initchamplainmemphis (void)
 
     init_pygobject ();
 
+    pygobject_register_sinkfunc (CHAMPLAIN_TYPE_MAP_DATA_SOURCE, sink_champlain_map_data_source);
+
     m = Py_InitModule ("champlainmemphis", champlainmemphis_functions);
     d = PyModule_GetDict (m);
 
diff --git a/bindings/python/champlain/pychamplainmodule.c b/bindings/python/champlain/pychamplainmodule.c
index 264e3a0..b39db20 100644
--- a/bindings/python/champlain/pychamplainmodule.c
+++ b/bindings/python/champlain/pychamplainmodule.c
@@ -4,6 +4,14 @@
 #include "pychamplain.h"
 #include <champlain/champlain.h>
 
+static void
+sink_champlain_map_source (GObject *object)
+{
+    if (g_object_is_floating (object)) {
+        g_object_ref_sink (object);
+    }
+}
+
 DL_EXPORT(void) initchamplain (void);
 extern PyMethodDef champlain_functions[];
 
@@ -14,6 +22,8 @@ initchamplain (void)
 
     init_pygobject ();
 
+    pygobject_register_sinkfunc (CHAMPLAIN_TYPE_MAP_SOURCE, sink_champlain_map_source);
+
     m = Py_InitModule ("champlain", champlain_functions);
     d = PyModule_GetDict (m);
 



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