diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-08-29 07:18:02 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-08-29 07:18:02 +0400 |
commit | 4d368cb298380d2a30fe757df8fa3ac46b071087 (patch) | |
tree | f97b5b066ae3a01f27fda3e8219d2e2963600d3e /source | |
parent | 7e4eb371fe4333799b9ad763170679d4e56b242a (diff) |
svn merge -r 16293:HEAD https://svn.blender.org/svnroot/bf-blender/trunk/blender
Diffstat (limited to 'source')
-rw-r--r-- | source/gameengine/GamePlayer/ghost/GPG_Application.cpp | 1 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 29 | ||||
-rw-r--r-- | source/gameengine/PyDoc/GameKeys.py | 9 |
3 files changed, 39 insertions, 0 deletions
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index 68b685e7847..a690beb9f38 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -726,6 +726,7 @@ void GPG_Application::stopEngine() } else { printf("Error, GameLogic.globalDict could not be marshal'd\n"); } + Py_DECREF(gameLogic); } else { printf("Error, GameLogic.globalDict was removed\n"); } diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index cb215958cc4..1d626f15b0c 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1129,9 +1129,38 @@ static char GameKeys_module_documentation[] = "This modules provides defines for key-codes" ; +static char gPyEventToString_doc[] = +"Take a valid event from the GameKeys module or Keyboard Sensor and return a name" +; +static PyObject* gPyEventToString(PyObject*, PyObject* value) +{ + PyObject* mod, *dict, *key, *val, *ret = NULL; + int pos = 0; + + mod = PyImport_ImportModule( "GameKeys" ); + if (!mod) + return NULL; + + dict = PyModule_GetDict(mod); + + while (PyDict_Next(dict, &pos, &key, &val)) { + if (PyObject_Compare(value, val)==0) { + ret = key; + break; + } + } + + PyErr_Clear(); // incase there was an error clearing + Py_DECREF(mod); + if (!ret) PyErr_SetString(PyExc_ValueError, "expected a valid int keyboard event"); + else Py_INCREF(ret); + + return ret; +} static struct PyMethodDef gamekeys_methods[] = { + {"EventToString", (PyCFunction)gPyEventToString, METH_O, gPyEventToString_doc}, { NULL, (PyCFunction) NULL, 0, NULL } }; diff --git a/source/gameengine/PyDoc/GameKeys.py b/source/gameengine/PyDoc/GameKeys.py index 268fb9cc172..1a0a737718e 100644 --- a/source/gameengine/PyDoc/GameKeys.py +++ b/source/gameengine/PyDoc/GameKeys.py @@ -164,3 +164,12 @@ Example:: # Activate Right! """ + +def EventToString(event): + """ + Return the string name of a key event. Will raise a ValueError error if its invalid. + + @type event: int + @param event: key event from GameKeys or the keyboard sensor. + @rtype: string + """ |