diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2010-11-21 21:30:12 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2010-11-21 21:30:12 +0000 |
commit | faf1817409cbd5550123e0e9feef562e98e4e75e (patch) | |
tree | 42de5c5f0b347aa865b9670fa3bad59d45a01904 /navit/binding/python/navit.c | |
parent | 9c466478ff2dac553e14a97e62979cdeccec19fe (diff) | |
parent | 0a095f392cd1f4f45cb34061d64414108572926f (diff) | |
download | navit-svn-R0_2_0.tar.gz |
Now correct tagR0_2_0
git-svn-id: http://svn.code.sf.net/p/navit/code/tags/R0_2_0/navit@3708 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/binding/python/navit.c')
-rw-r--r-- | navit/binding/python/navit.c | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/navit/binding/python/navit.c b/navit/binding/python/navit.c new file mode 100644 index 00000000..ada8cd7f --- /dev/null +++ b/navit/binding/python/navit.c @@ -0,0 +1,135 @@ +/** + * 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 "navit.h" + +typedef struct { + PyObject_HEAD + struct navit *navit; +} navitObject; + +static PyObject * +navit_get_attr_py(navitObject *self, PyObject *args) +{ + char *name; + struct attr attr; + if (!PyArg_ParseTuple(args, "s", &name)) + return NULL; + if (!navit_get_attr(self->navit, attr_from_name(name), &attr, NULL)) { + dbg(0,"get_attr not ok\n"); + Py_RETURN_NONE; + } + dbg(0,"get_attr ok\n"); + return python_object_from_attr(&attr); +} + +static PyObject * +navit_set_center_py(navitObject *self, PyObject *args) +{ + PyObject *pcoord; + if (!PyArg_ParseTuple(args, "O!", &pcoord_Type, &pcoord)) + return NULL; + navit_set_center(self->navit, pcoord_py_get(pcoord), 0); + Py_RETURN_NONE; +} + +static PyObject * +navit_set_destination_py(navitObject *self, PyObject *args) +{ + PyObject *pcoord; + const char *description; + int async; + if (!PyArg_ParseTuple(args, "O!si", &pcoord_Type, &pcoord, &description, &async)) + return NULL; + navit_set_destination(self->navit, pcoord_py_get(pcoord), description, async); + Py_RETURN_NONE; +} + +static PyObject * +navit_set_position_py(navitObject *self, PyObject *args) +{ + PyObject *pcoord; + if (!PyArg_ParseTuple(args, "O!", &pcoord_Type, &pcoord)) + return NULL; + navit_set_position(self->navit, pcoord_py_get(pcoord)); + Py_RETURN_NONE; +} + + +static PyObject * +navit_zoom_to_route_py(navitObject *self, PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + navit_zoom_to_route(self->navit,0); + Py_RETURN_NONE; +} + + + + +static PyMethodDef navit_methods[] = { + {"get_attr", (PyCFunction) navit_get_attr_py, METH_VARARGS }, + {"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 }, +}; + + +static PyObject * +navit_getattr_py(PyObject *self, char *name) +{ + return Py_FindMethod(navit_methods, self, name); +} + +static void +navit_destroy_py(navitObject *self) +{ +} + +PyTypeObject navit_Type = { + Obj_HEAD + .tp_name="navit", + .tp_basicsize=sizeof(navitObject), + .tp_dealloc=(destructor)navit_destroy_py, + .tp_getattr=navit_getattr_py, +}; + +PyObject * +navit_py(PyObject *self, PyObject *args) +{ + navitObject *ret; + + dbg(0,"enter\n"); + ret=PyObject_NEW(navitObject, &navit_Type); + return (PyObject *)ret; +} + +PyObject * +navit_py_ref(struct navit *navit) +{ + dbg(0,"navit=%p\n", navit); + navitObject *ret=PyObject_NEW(navitObject, &navit_Type); + ret->navit=navit; + return (PyObject *)ret; +} |