bge.logic.keyboard.getClipboard() and .setClipboard methods
authorDalai Felinto <dfelinto@gmail.com>
Wed, 27 Jun 2012 21:57:33 +0000 (21:57 +0000)
committerDalai Felinto <dfelinto@gmail.com>
Wed, 27 Jun 2012 21:57:33 +0000 (21:57 +0000)
the idea of using methods instead of attributes is to avoid users abusing of the system calls.

Thanks Campbell Barton for reviewing and small corrections

doc/python_api/rst/bge.types.rst
source/gameengine/GameLogic/CMakeLists.txt
source/gameengine/GameLogic/SCA_PythonKeyboard.cpp
source/gameengine/GameLogic/SConscript

index ff85df1f68b4d2143e5b952017e9279f3140f93a..ad963094ce26d8362d0beaed8f791d38f05fbae3 100644 (file)
@@ -72,6 +72,20 @@ Game Types (bge.types)
 
       :type: dictionary {:ref:`keycode<keyboard-keys>`::ref:`status<input-status>`, ...}
 
+
+   .. function:: getClipboard()
+
+      Gets the clipboard text.
+
+      :rtype: string
+
+   .. function:: setClipboard(text)
+
+      Sets the clipboard text.
+
+      :arg text: New clipboard text
+      :type text: string
+
 .. class:: SCA_PythonMouse(PyObjectPlus)
 
    The current mouse.
index 64f198f72a077cbb138f6bd8e510e9f7ed87cc9d..e511704c7f484466ca4e2df3bf1e6e6b43e937a4 100644 (file)
@@ -32,6 +32,7 @@ set(INC
        ../../../intern/container
        ../../../intern/moto/include
        ../../../intern/string
+       ../../../intern/ghost
 )
 
 set(INC_SYS
index 46c43b5e339d58489394362f0b16956bd6e43073..f83b23f510cec441dd7cad994f1603109d91c00e 100644 (file)
@@ -28,6 +28,8 @@
 #include "SCA_PythonKeyboard.h"
 #include "SCA_IInputDevice.h"
 
+#include "GHOST_C-api.h"
+
 /* ------------------------------------------------------------------------- */
 /* Native functions                                                          */
 /* ------------------------------------------------------------------------- */
@@ -55,6 +57,23 @@ SCA_PythonKeyboard::~SCA_PythonKeyboard()
 /* Python functions                                                          */
 /* ------------------------------------------------------------------------- */
 
+/* clipboard */
+static PyObject* gPyGetClipboard(PyObject* args, PyObject* kwds)
+{
+       char *buf = (char *)GHOST_getClipboard(0);
+       return PyUnicode_FromString(buf?buf:"");
+}
+
+static PyObject* gPySetClipboard(PyObject* args, PyObject* value)
+{
+       char* buf;
+       if (!PyArg_ParseTuple(value,"s:setClipboard",&buf))
+               Py_RETURN_NONE;
+
+       GHOST_putClipboard((GHOST_TInt8 *)buf, 0);
+       Py_RETURN_NONE;
+}
+
 /* Integration hooks ------------------------------------------------------- */
 PyTypeObject SCA_PythonKeyboard::Type = {
        PyVarObject_HEAD_INIT(NULL, 0)
@@ -79,6 +98,8 @@ PyTypeObject SCA_PythonKeyboard::Type = {
 };
 
 PyMethodDef SCA_PythonKeyboard::Methods[] = {
+       {"getClipboard", (PyCFunction) gPyGetClipboard, METH_VARARGS, "getCliboard doc"},
+       {"setClipboard", (PyCFunction) gPySetClipboard, METH_VARARGS, "setCliboard doc"},
        {NULL,NULL} //Sentinel
 };
 
index e33169bada74c26c661586001d3a73578d5b2326..da3c0fadb51f34f7e2b46bb2c72cc552a4977d7b 100644 (file)
@@ -3,7 +3,7 @@ Import ('env')
 
 sources = env.Glob('*.cpp') + env.Glob('Joystick/*.cpp')
 
-incs = '. #/intern/string #intern/container'
+incs = '. #/intern/string #intern/container #intern/ghost'
 incs += ' #/source/gameengine/Expressions #/intern/moto/include'
 incs += ' #/source/gameengine/Rasterizer #/source/gameengine/SceneGraph'
 incs += ' #/source/blender/blenlib'