Make Escape delete the previous stroke (again)
[numtypysics.git] / PythonInput.h
blobd40ff9272fb5b6d2a3defeac38e612aefbdc1363
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 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_width(width), m_height(height)
38 PyObject* numpty_module;
39 PyObject* input_module;
41 /* Initialize the Python Interpreter */
42 setenv("PYTHONPATH", ".", 1);
43 PyEval_InitThreads();
44 Py_Initialize();
46 /* Add the glue module and load tuioinput */
47 numpty_module = create_module();
48 input_module = PyImport_ImportModule("tuioinput");
49 if (input_module == NULL) {
50 PyErr_Print();
52 Py_DECREF(input_module);
53 Py_DECREF(numpty_module);
55 m_python_threadstate = PyEval_SaveThread();
58 ~PythonInput()
60 PyEval_RestoreThread(m_python_threadstate);
61 /* Could/should call Py_Finalize() here, but crashes */
65 #endif /* HAVE_PYTHON */
67 #endif