summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-12-16 12:40:29 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-12-16 12:40:29 +0000
commit388d8f506a67dcf745c26f0c59d6609bcdafa7a5 (patch)
treedc69730a1c11a9ffaf5825fb4671294540b4306d
parent7d4a44ebe7d6783fe8ae380e882828a7a7b9dad7 (diff)
downloadnavit-388d8f506a67dcf745c26f0c59d6609bcdafa7a5.tar.gz
Add:binding_python:Make it do actually something useful
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1805 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/binding/python/Makefile.am2
-rw-r--r--navit/binding/python/binding_python.c19
-rw-r--r--navit/binding/python/common.h36
-rw-r--r--navit/binding/python/main.c73
-rw-r--r--navit/binding/python/navit.c106
-rw-r--r--navit/binding/python/navit.xml.python7
-rw-r--r--navit/binding/python/pcoord.c88
-rw-r--r--navit/binding/python/startup.py8
-rw-r--r--navit/binding/python/template.c73
9 files changed, 406 insertions, 6 deletions
diff --git a/navit/binding/python/Makefile.am b/navit/binding/python/Makefile.am
index 1d7911954..777ad0d43 100644
--- a/navit/binding/python/Makefile.am
+++ b/navit/binding/python/Makefile.am
@@ -1,5 +1,5 @@
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
+libbinding_python_la_SOURCES = binding_python.c main.c navit.c pcoord.c
libbinding_python_la_LIBADD = @PYTHON_LIBS@
diff --git a/navit/binding/python/binding_python.c b/navit/binding/python/binding_python.c
index 2bbac12fe..d8dec6642 100644
--- a/navit/binding/python/binding_python.c
+++ b/navit/binding/python/binding_python.c
@@ -19,7 +19,7 @@
#include "config.h"
#include <glib.h>
-#include <Python.h>
+#include "common.h"
#include <fcntl.h>
#include "coord.h"
#include "projection.h"
@@ -272,13 +272,25 @@ mapset_destroy_py(mapsetObject *self)
mapset_destroy(self->ms);
}
-
+static PyObject *
+config_load_py(PyObject *self, PyObject *args)
+{
+ const char *file;
+ int ret;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ ret=config_load(file, NULL);
+ return Py_BuildValue("i",ret);
+}
static PyMethodDef navitMethods[]={
{"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."},
{"mapset", mapset_new_py, METH_VARARGS, "Create a new mapset."},
+ {"config_load", config_load_py, METH_VARARGS, "Load a config"},
+ {"main", main_py, METH_VARARGS, "Get Main Object"},
+ {"pcoord", pcoord_py, METH_VARARGS},
{NULL, NULL, 0, NULL}
};
@@ -289,8 +301,6 @@ plugin_init(void)
int fd,size;
char buffer[65536];
- return;
-
Py_Initialize();
Py_InitModule("navit", navitMethods);
fd=open("startup.py",O_RDONLY);
@@ -303,5 +313,4 @@ plugin_init(void)
}
Py_Finalize();
- exit(0);
}
diff --git a/navit/binding/python/common.h b/navit/binding/python/common.h
new file mode 100644
index 000000000..cdc9e8576
--- /dev/null
+++ b/navit/binding/python/common.h
@@ -0,0 +1,36 @@
+/**
+ * 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 <Python.h>
+#include "debug.h"
+
+#if defined(MS_WINDOWS) || defined(__CYGWIN__)
+#define Obj_HEAD PyObject_HEAD_INIT(NULL);
+#else
+#define Obj_HEAD PyObject_HEAD_INIT(&PyType_Type)
+#endif
+
+struct navit;
+
+PyObject * main_py(PyObject *self, PyObject *args);
+PyObject * navit_py(PyObject *self, PyObject *args);
+PyObject * navit_py_ref(struct navit *navit);
+extern PyTypeObject pcoord_Type;
+PyObject * pcoord_py(PyObject *self, PyObject *args);
+struct pcoord *pcoord_py_get(PyObject *self);
diff --git a/navit/binding/python/main.c b/navit/binding/python/main.c
new file mode 100644
index 000000000..7e059fef0
--- /dev/null
+++ b/navit/binding/python/main.c
@@ -0,0 +1,73 @@
+/**
+ * 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 "main.h"
+
+typedef struct {
+ PyObject_HEAD
+} mainObject;
+
+static PyObject *
+main_navit(PyObject *self, PyObject *args)
+{
+ struct navit *navit;
+ const char *file;
+ int ret=0;
+ navit=main_get_navit(NULL);
+ return navit_py_ref(navit);
+}
+
+
+
+static PyMethodDef main_methods[] = {
+ {"navit", (PyCFunction) main_navit, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+main_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(main_methods, self, name);
+}
+
+static void
+main_destroy_py(mainObject *self)
+{
+}
+
+PyTypeObject main_Type = {
+ Obj_HEAD
+ .tp_name="main",
+ .tp_basicsize=sizeof(mainObject),
+ .tp_dealloc=(destructor)main_destroy_py,
+ .tp_getattr=main_getattr_py,
+};
+
+PyObject *
+main_py(PyObject *self, PyObject *args)
+{
+ mainObject *ret;
+
+ dbg(0,"enter\n");
+ ret=PyObject_NEW(mainObject, &main_Type);
+ return (PyObject *)ret;
+}
+
diff --git a/navit/binding/python/navit.c b/navit/binding/python/navit.c
new file mode 100644
index 000000000..e35b93119
--- /dev/null
+++ b/navit/binding/python/navit.c
@@ -0,0 +1,106 @@
+/**
+ * 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 "navit.h"
+
+typedef struct {
+ PyObject_HEAD
+ struct navit *navit;
+} navitObject;
+
+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));
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+navit_set_destination_py(navitObject *self, PyObject *args)
+{
+ PyObject *pcoord;
+ const char *description;
+ if (!PyArg_ParseTuple(args, "O!s", &pcoord_Type, &pcoord, &description))
+ return NULL;
+ navit_set_destination(self->navit, pcoord_py_get(pcoord), description);
+ 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 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 },
+ {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;
+}
diff --git a/navit/binding/python/navit.xml.python b/navit/binding/python/navit.xml.python
new file mode 100644
index 000000000..ec3e99de5
--- /dev/null
+++ b/navit/binding/python/navit.xml.python
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE config SYSTEM "navit.dtd">
+<config xmlns:xi="http://www.w3.org/2001/XInclude">
+ <plugins>
+ <plugin path="$NAVIT_LIBDIR/*/${NAVIT_LIBPREFIX}libbinding_python.so" active="yes"/>
+ </plugins>
+</config>
diff --git a/navit/binding/python/pcoord.c b/navit/binding/python/pcoord.c
new file mode 100644
index 000000000..a4cb2640d
--- /dev/null
+++ b/navit/binding/python/pcoord.c
@@ -0,0 +1,88 @@
+/**
+ * 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 "coord.h"
+
+typedef struct {
+ PyObject_HEAD
+ struct pcoord pc;
+} pcoordObject;
+
+static PyObject *
+pcoord_func(pcoordObject *self, PyObject *args)
+{
+ const char *file;
+ int ret=0;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ return Py_BuildValue("i",ret);
+}
+
+
+
+static PyMethodDef pcoord_methods[] = {
+ {"func", (PyCFunction) pcoord_func, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+pcoord_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(pcoord_methods, self, name);
+}
+
+static void
+pcoord_destroy_py(pcoordObject *self)
+{
+}
+
+PyTypeObject pcoord_Type = {
+ Obj_HEAD
+ .tp_name="pcoord",
+ .tp_basicsize=sizeof(pcoordObject),
+ .tp_dealloc=(destructor)pcoord_destroy_py,
+ .tp_getattr=pcoord_getattr_py,
+};
+
+PyObject *
+pcoord_py(PyObject *self, PyObject *args)
+{
+ pcoordObject *ret;
+ const char *str;
+ enum projection pro;
+ struct coord c;
+ if (!PyArg_ParseTuple(args, "si", &str, &pro))
+ return NULL;
+ ret=PyObject_NEW(pcoordObject, &pcoord_Type);
+ coord_parse(str, pro, &c);
+ ret->pc.pro=pro;
+ ret->pc.x=c.x;
+ ret->pc.y=c.y;
+ dbg(0,"0x%x,0x%x\n", c.x, c.y);
+ return (PyObject *)ret;
+}
+
+struct pcoord *
+pcoord_py_get(PyObject *self)
+{
+ return &((pcoordObject *)self)->pc;
+}
+
diff --git a/navit/binding/python/startup.py b/navit/binding/python/startup.py
new file mode 100644
index 000000000..02b207003
--- /dev/null
+++ b/navit/binding/python/startup.py
@@ -0,0 +1,8 @@
+import navit
+navit.config_load("navit.xml.local")
+pos=navit.pcoord("5023.7493 N 00730.2898 E",1);
+dest=navit.pcoord("5023.6604 N 00729.8500 E",1);
+inst=navit.main().navit();
+inst.set_position(pos);
+inst.set_destination(dest,"Test");
+inst.set_center(pos);
diff --git a/navit/binding/python/template.c b/navit/binding/python/template.c
new file mode 100644
index 000000000..00613eab8
--- /dev/null
+++ b/navit/binding/python/template.c
@@ -0,0 +1,73 @@
+/**
+ * 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 "template.h"
+
+typedef struct {
+ PyObject_HEAD
+} templateObject;
+
+static PyObject *
+template_func(templateObject *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 template_methods[] = {
+ {"func", (PyCFunction) template_func, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+template_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(template_methods, self, name);
+}
+
+static void
+template_destroy_py(templateObject *self)
+{
+}
+
+PyTypeObject template_Type = {
+ Obj_HEAD
+ .tp_name="template",
+ .tp_basicsize=sizeof(templateObject),
+ .tp_dealloc=(destructor)template_destroy_py,
+ .tp_getattr=template_getattr_py,
+};
+
+PyObject *
+template_py(PyObject *self, PyObject *args)
+{
+ templateObject *ret;
+
+ ret=PyObject_NEW(templateObject, &template_Type);
+ return (PyObject *)ret;
+}
+