diff options
author | Campbell Barton <campbell@blender.org> | 2022-04-13 09:40:07 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-04-20 05:19:35 +0300 |
commit | f438344cf243632e497772cf1f855b9c8856fd37 (patch) | |
tree | d7121f1e456c2f499ba0e92dd2f38869c39b844c /doc/python_api/examples/bpy.types.Context.temp_override.1.py | |
parent | 6d9268c2c7362ec772a3ff956ee888e877682a01 (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 'doc/python_api/examples/bpy.types.Context.temp_override.1.py')
-rw-r--r-- | doc/python_api/examples/bpy.types.Context.temp_override.1.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/doc/python_api/examples/bpy.types.Context.temp_override.1.py b/doc/python_api/examples/bpy.types.Context.temp_override.1.py new file mode 100644 index 00000000000..68f0eef93c3 --- /dev/null +++ b/doc/python_api/examples/bpy.types.Context.temp_override.1.py @@ -0,0 +1,19 @@ +""" +Overriding the context can be used to temporarily activate another ``window`` / ``area`` & ``region``, +as well as other members such as the ``active_object`` or ``bone``. + +Notes: + +- When overriding window, area and regions: the arguments must be consistent, + so any region argument that's passed in must be contained by the current area or the area passed in. + The same goes for the area needing to be contained in the current window. + +- Temporary context overrides may be nested, when this is done, members will be added to the existing overrides. + +- Context members are restored outside the scope of the context. + The only exception to this is when the data is no longer available. + + In the event windowing data was removed (for example), the state of the context is left as-is. + While this isn't likely to happen, explicit window operation such as closing windows or loading a new file + remove the windowing data that was set before the temporary context was created. +""" |