include $(top_srcdir)/Makefile.inc
AM_CPPFLAGS = @NAVIT_CFLAGS@ @PYTHON_CFLAGS@ -I$(top_srcdir)/navit -DMODULE=binding_python
modulebinding_LTLIBRARIES = libbinding_python.la
-libbinding_python_la_SOURCES = binding_python.c main.c navit.c pcoord.c route.c navigation.c common.h
+libbinding_python_la_SOURCES = binding_python.c main.c navit.c pcoord.c route.c navigation.c attr.c common.h
libbinding_python_la_LIBADD = @PYTHON_LIBS@
--- /dev/null
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 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 General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "common.h"
+#include "item.h"
+#include "attr.h"
+
+typedef struct {
+ PyObject_HEAD
+ int ref;
+ struct attr *attr;
+} attrObject;
+
+static PyObject *
+attr_func(attrObject *self, PyObject *args)
+{
+ const char *file;
+ int ret;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ ret=0;
+ return Py_BuildValue("i",ret);
+}
+
+
+
+static PyMethodDef attr_methods[] = {
+ {"func", (PyCFunction) attr_func, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+attr_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(attr_methods, self, name);
+}
+
+static void
+attr_destroy_py(attrObject *self)
+{
+ if (! self->ref)
+ attr_free(self->attr);
+}
+
+PyTypeObject attr_Type = {
+ Obj_HEAD
+ .tp_name="attr",
+ .tp_basicsize=sizeof(attrObject),
+ .tp_dealloc=(destructor)attr_destroy_py,
+ .tp_getattr=attr_getattr_py,
+};
+
+struct attr *
+attr_py_get(PyObject *self)
+{
+ return ((attrObject *)self)->attr;
+}
+
+PyObject *
+attr_new_py(PyObject *self, PyObject *args)
+{
+ attrObject *ret;
+ const char *name,*value;
+ if (!PyArg_ParseTuple(args, "ss", &name, &value))
+ return NULL;
+ ret=PyObject_NEW(attrObject, &attr_Type);
+ ret->attr=attr_new_from_text(name, value);
+ ret->ref=0;
+ return (PyObject *)ret;
+}
+
+PyObject *
+attr_new_py_ref(struct attr *attr)
+{
+ attrObject *ret;
+
+ ret=PyObject_NEW(attrObject, &attr_Type);
+ ret->ref=1;
+ ret->attr=attr;
+ return (PyObject *)ret;
+}
+
}
+static PyObject *
+map_set_attr_py(mapObject *self, PyObject *args)
+{
+ PyObject *attr;
+ if (!PyArg_ParseTuple(args, "O!", &attr_Type, &attr))
+ return NULL;
+ map_set_attr(self->m, attr_py_get(attr));
+ Py_RETURN_NONE;
+}
+
+
static PyMethodDef map_methods[] = {
{"dump_file", (PyCFunction) map_dump_file_py, METH_VARARGS },
{"map_rect_new", (PyCFunction) map_rect_new_py, METH_VARARGS },
+ {"set_attr", (PyCFunction) map_set_attr_py, METH_VARARGS },
{NULL, NULL },
};
}
static PyMethodDef navitMethods[]={
+ {"attr", attr_new_py, METH_VARARGS},
{"coord", coord_new_py, METH_VARARGS, "Create a new coordinate point."},
{"coord_rect", coord_rect_new_py, METH_VARARGS, "Create a new coordinate rectangle."},
{"map", map_new_py, METH_VARARGS, "Create a new map."},
struct route;
PyObject * route_py(PyObject *self, PyObject *args);
PyObject * route_py_ref(struct route *route);
+
+extern PyTypeObject attr_Type;
+PyObject * attr_new_py(PyObject *self, PyObject *args);
+PyObject * attr_new_py_ref(struct attr *attr);
+struct attr * attr_py_get(PyObject *self);
}
+static PyObject *
+navit_zoom_to_route_py(navitObject *self, PyObject *args)
+{
+ PyObject *pcoord;
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ navit_zoom_to_route(self->navit);
+ Py_RETURN_NONE;
+}
+
+
static PyMethodDef navit_methods[] = {
{"set_center", (PyCFunction) navit_set_center_py, METH_VARARGS },
{"set_destination", (PyCFunction) navit_set_destination_py, METH_VARARGS },
{"set_position", (PyCFunction) navit_set_position_py, METH_VARARGS },
+ {"zoom_to_route", (PyCFunction) navit_zoom_to_route_py, METH_VARARGS },
{NULL, NULL },
};
typedef struct {
PyObject_HEAD
+ int ref;
+ struct template *template;
} templateObject;
static PyObject *
static void
template_destroy_py(templateObject *self)
{
+ if (! self->ref)
+ template_destroy(self->template);
}
PyTypeObject template_Type = {
.tp_getattr=template_getattr_py,
};
+struct template *
+template_py_get(PyObject *self)
+{
+ return ((templateObject *)self)->template;
+}
+
+PyObject *
+template_new_py(PyObject *self, PyObject *args)
+{
+ templateObject *ret;
+
+ ret=PyObject_NEW(templateObject, &template_Type);
+ ret->template=template_new();
+ ret->ref=0;
+ return (PyObject *)ret;
+}
+
PyObject *
-template_py(PyObject *self, PyObject *args)
+template_new_py_ref(struct template *template)
{
templateObject *ret;
ret=PyObject_NEW(templateObject, &template_Type);
+ ret->ref=1;
+ ret->template=template;
return (PyObject *)ret;
}