Add pointlog2svg utility for the thesis
[numtypysics.git] / PythonInput.h
blobbe16668d1e4d2fbcd1005dac6b53650710f80009
2 /*
3 * Python Input Module for NumptyPhysics
4 * Copyright (c) 2009 Thomas Perl <thpinfo.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
18 #ifndef PYTHONINPUT_H
19 #define PYTHONINPUT_H
21 #ifdef HAVE_PYTHON
23 #include <Python.h>
24 #include "SDL/SDL.h"
26 class PythonInput {
27 private:
28 PyThreadState* m_python_threadstate;
29 static int m_width;
30 int m_height;
32 PyObject* create_module();
33 static PyObject* post_event(PyObject* self, PyObject *event);
34 public:
35 PythonInput(int width, int height)
36 : m_height(height)
38 m_width = width;
39 PyObject* numpty_module;
40 PyObject* input_module;
42 /* Initialize the Python Interpreter */
43 setenv("PYTHONPATH", ".", 1);
44 PyEval_InitThreads();
45 Py_Initialize();
47 /* Add the glue module and load tuioinput */
48 numpty_module = create_module();
49 input_module = PyImport_ImportModule("tuioinput");
50 if (input_module == NULL) {
51 PyErr_Print();
53 Py_DECREF(input_module);
54 Py_DECREF(numpty_module);
56 m_python_threadstate = PyEval_SaveThread();
59 ~PythonInput()
61 PyEval_RestoreThread(m_python_threadstate);
62 /* Could/should call Py_Finalize() here, but crashes */
66 #endif /* HAVE_PYTHON */
68 #endif