Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-02-02 07:14:51 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-02-02 07:23:55 +0300
commit141c6073ca39f0d59c67ebef89b094395b903a4a (patch)
tree372d9246e92117f7d74ef7688848b28710e906fd /source/blender/python
parent99b8eef6a534c2c9846b48736cb9eb007c120ec7 (diff)
WM: Event simulation support for Python
This feature is intended only for testing, to automate simulating user input. - Enabled by '--enable-event-simulate'. - Disables handling all real input events. - Access by calling `Window.event_simulate(..)` - Disabling `bpy.app.use_event_simulate` to allow handling real events (can only disable). Currently only mouse & keyboard events work well, NDOF, IME... etc could be added as needed. See D4286 for example usage.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_app.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index 992694a71c2..6172330a875 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -259,6 +259,41 @@ static int bpy_app_debug_set(PyObject *UNUSED(self), PyObject *value, void *clos
return 0;
}
+PyDoc_STRVAR(bpy_app_global_flag_doc,
+"Boolean, for application behavior (started with --enable-* matching this attribute name)"
+);
+static PyObject *bpy_app_global_flag_get(PyObject *UNUSED(self), void *closure)
+{
+ const int flag = POINTER_AS_INT(closure);
+ return PyBool_FromLong(G.f & flag);
+}
+
+static int bpy_app_global_flag_set(PyObject *UNUSED(self), PyObject *value, void *closure)
+{
+ const int flag = POINTER_AS_INT(closure);
+ const int param = PyObject_IsTrue(value);
+
+ if (param == -1) {
+ PyErr_SetString(PyExc_TypeError, "bpy.app.use_* can only be True/False");
+ return -1;
+ }
+
+ if (param) G.f |= flag;
+ else G.f &= ~flag;
+
+ return 0;
+}
+
+static int bpy_app_global_flag_set__only_disable(PyObject *UNUSED(self), PyObject *value, void *closure)
+{
+ const int param = PyObject_IsTrue(value);
+ if (param == 1) {
+ PyErr_SetString(PyExc_ValueError, "This bpy.app.use_* option can only be disabled");
+ return -1;
+ }
+ return bpy_app_global_flag_set(NULL, value, closure);
+}
+
#define BROKEN_BINARY_PATH_PYTHON_HACK
PyDoc_STRVAR(bpy_app_binary_path_python_doc,
@@ -316,12 +351,6 @@ static int bpy_app_debug_value_set(PyObject *UNUSED(self), PyObject *value, void
return 0;
}
-static PyObject *bpy_app_global_flag_get(PyObject *UNUSED(self), void *closure)
-{
- const int flag = POINTER_AS_INT(closure);
- return PyBool_FromLong(G.f & flag);
-}
-
PyDoc_STRVAR(bpy_app_tempdir_doc,
"String, the temp directory used by blender (read-only)"
);
@@ -401,6 +430,7 @@ static PyGetSetDef bpy_app_getsets[] = {
{(char *)"debug_io", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_IO},
{(char *)"use_static_override", bpy_app_use_static_override_get, bpy_app_use_static_override_set, (char *)bpy_app_use_static_override_doc, NULL},
+ {(char *)"use_event_simulate", bpy_app_global_flag_get, bpy_app_global_flag_set__only_disable, (char *)bpy_app_global_flag_doc, (void *)G_FLAG_EVENT_SIMULATE},
{(char *)"binary_path_python", bpy_app_binary_path_python_get, NULL, (char *)bpy_app_binary_path_python_doc, NULL},