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 <campbell@blender.org>2022-04-13 09:40:07 +0300
committerCampbell Barton <campbell@blender.org>2022-04-20 05:19:35 +0300
commitf438344cf243632e497772cf1f855b9c8856fd37 (patch)
treed7121f1e456c2f499ba0e92dd2f38869c39b844c /source/blender/python/intern/bpy_rna_types_capi.c
parent6d9268c2c7362ec772a3ff956ee888e877682a01 (diff)
PyAPI: temporary context override support
Support a way to temporarily override the context from Python. - Added method `Context.temp_override` context manager. - Special support for windowing variables "window", "area" and "region", other context members such as "active_object". - Nesting context overrides is supported. - Previous windowing members are restored when the context exists unless they have been removed. - Overriding context members by passing a dictionary into operators in `bpy.ops` has been deprecated and warns when used. This allows the window in a newly loaded file to be used, see: T92464 Reviewed by: mont29 Ref D13126
Diffstat (limited to 'source/blender/python/intern/bpy_rna_types_capi.c')
-rw-r--r--source/blender/python/intern/bpy_rna_types_capi.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_rna_types_capi.c b/source/blender/python/intern/bpy_rna_types_capi.c
index a5299bc1616..376195ab845 100644
--- a/source/blender/python/intern/bpy_rna_types_capi.c
+++ b/source/blender/python/intern/bpy_rna_types_capi.c
@@ -22,6 +22,7 @@
#include "bpy_library.h"
#include "bpy_rna.h"
#include "bpy_rna_callback.h"
+#include "bpy_rna_context.h"
#include "bpy_rna_data.h"
#include "bpy_rna_id_collection.h"
#include "bpy_rna_text.h"
@@ -159,6 +160,17 @@ static struct PyGetSetDef pyrna_windowmanager_getset[] = {
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Context Type
+ * \{ */
+
+static struct PyMethodDef pyrna_context_methods[] = {
+ {NULL, NULL, 0, NULL}, /* #BPY_rna_context_temp_override_method_def */
+ {NULL, NULL, 0, NULL},
+};
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Space Type
* \{ */
@@ -254,6 +266,10 @@ void BPY_rna_types_extend_capi(void)
/* WindowManager */
pyrna_struct_type_extend_capi(
&RNA_WindowManager, pyrna_windowmanager_methods, pyrna_windowmanager_getset);
+
+ /* Context */
+ ARRAY_SET_ITEMS(pyrna_context_methods, BPY_rna_context_temp_override_method_def);
+ pyrna_struct_type_extend_capi(&RNA_Context, pyrna_context_methods, NULL);
}
/** \} */