[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48350] trunk/blender: bge.logic.keyboard. getClipboard() and .setClipboard methods

Dalai Felinto dfelinto at gmail.com
Wed Jun 27 23:57:35 CEST 2012


Revision: 48350
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48350
Author:   dfelinto
Date:     2012-06-27 21:57:33 +0000 (Wed, 27 Jun 2012)
Log Message:
-----------
bge.logic.keyboard.getClipboard() and .setClipboard methods
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

Modified Paths:
--------------
    trunk/blender/doc/python_api/rst/bge.types.rst
    trunk/blender/source/gameengine/GameLogic/CMakeLists.txt
    trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp
    trunk/blender/source/gameengine/GameLogic/SConscript

Modified: trunk/blender/doc/python_api/rst/bge.types.rst
===================================================================
--- trunk/blender/doc/python_api/rst/bge.types.rst	2012-06-27 21:57:24 UTC (rev 48349)
+++ trunk/blender/doc/python_api/rst/bge.types.rst	2012-06-27 21:57:33 UTC (rev 48350)
@@ -72,6 +72,20 @@
 
       :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.

Modified: trunk/blender/source/gameengine/GameLogic/CMakeLists.txt
===================================================================
--- trunk/blender/source/gameengine/GameLogic/CMakeLists.txt	2012-06-27 21:57:24 UTC (rev 48349)
+++ trunk/blender/source/gameengine/GameLogic/CMakeLists.txt	2012-06-27 21:57:33 UTC (rev 48350)
@@ -32,6 +32,7 @@
 	../../../intern/container
 	../../../intern/moto/include
 	../../../intern/string
+	../../../intern/ghost
 )
 
 set(INC_SYS

Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp	2012-06-27 21:57:24 UTC (rev 48349)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp	2012-06-27 21:57:33 UTC (rev 48350)
@@ -28,6 +28,8 @@
 #include "SCA_PythonKeyboard.h"
 #include "SCA_IInputDevice.h"
 
+#include "GHOST_C-api.h"
+
 /* ------------------------------------------------------------------------- */
 /* Native functions                                                          */
 /* ------------------------------------------------------------------------- */
@@ -55,6 +57,23 @@
 /* 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 @@
 };
 
 PyMethodDef SCA_PythonKeyboard::Methods[] = {
+	{"getClipboard", (PyCFunction) gPyGetClipboard, METH_VARARGS, "getCliboard doc"},
+	{"setClipboard", (PyCFunction) gPySetClipboard, METH_VARARGS, "setCliboard doc"},
 	{NULL,NULL} //Sentinel
 };
 

Modified: trunk/blender/source/gameengine/GameLogic/SConscript
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SConscript	2012-06-27 21:57:24 UTC (rev 48349)
+++ trunk/blender/source/gameengine/GameLogic/SConscript	2012-06-27 21:57:33 UTC (rev 48350)
@@ -3,7 +3,7 @@
 
 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'




More information about the Bf-blender-cvs mailing list