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-20 05:49:13 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-04-21 12:09:06 +0300
commitf0862773b4ddfffd657690d6407e8bafbeed8838 (patch)
tree17001790cc910fb11832f0a17eb5baea0512b99a
parentfbbfecba2392c277eba7db0db0bdb3bd40653355 (diff)
Docs: update examples to use Context.temp_override
-rw-r--r--doc/python_api/examples/bpy.ops.1.py12
-rw-r--r--doc/python_api/examples/bpy.ops.3.py13
-rw-r--r--doc/python_api/examples/bpy.ops.py5
3 files changed, 18 insertions, 12 deletions
diff --git a/doc/python_api/examples/bpy.ops.1.py b/doc/python_api/examples/bpy.ops.1.py
index efc9f00b0ae..9b690823a18 100644
--- a/doc/python_api/examples/bpy.ops.1.py
+++ b/doc/python_api/examples/bpy.ops.1.py
@@ -9,7 +9,7 @@ operator in the different part of the user interface.
The context overrides are passed as a dictionary, with keys matching the context
member names in bpy.context.
For example to override ``bpy.context.active_object``,
-you would pass ``{'active_object': object}``.
+you would pass ``{'active_object': object}`` to :class:`bpy.types.Context.temp_override`.
.. note::
@@ -17,8 +17,10 @@ you would pass ``{'active_object': object}``.
(otherwise, you'll have to find and gather all needed data yourself).
"""
-# remove all objects in scene rather than the selected ones
+# Remove all objects in scene rather than the selected ones.
import bpy
-override = bpy.context.copy()
-override['selected_objects'] = list(bpy.context.scene.objects)
-bpy.ops.object.delete(override)
+from bpy import context
+override = context.copy()
+override["selected_objects"] = list(context.scene.objects)
+with context.temp_override(**override):
+ bpy.ops.object.delete()
diff --git a/doc/python_api/examples/bpy.ops.3.py b/doc/python_api/examples/bpy.ops.3.py
index 7dec69cf566..e068ab0c0cf 100644
--- a/doc/python_api/examples/bpy.ops.3.py
+++ b/doc/python_api/examples/bpy.ops.3.py
@@ -1,17 +1,16 @@
"""
It is also possible to run an operator in a particular part of the user
-interface. For this we need to pass the window, screen, area and sometimes
-a region.
+interface. For this we need to pass the window, area and sometimes a region.
"""
-# maximize 3d view in all windows
+# Maximize 3d view in all windows.
import bpy
+from bpy import context
-for window in bpy.context.window_manager.windows:
+for window in context.window_manager.windows:
screen = window.screen
-
for area in screen.areas:
if area.type == 'VIEW_3D':
- override = {'window': window, 'screen': screen, 'area': area}
- bpy.ops.screen.screen_full_area(override)
+ with context.temp_override(window=window, area=area):
+ bpy.ops.screen.screen_full_area()
break
diff --git a/doc/python_api/examples/bpy.ops.py b/doc/python_api/examples/bpy.ops.py
index 76c494ad4f5..e8d545fc855 100644
--- a/doc/python_api/examples/bpy.ops.py
+++ b/doc/python_api/examples/bpy.ops.py
@@ -33,6 +33,11 @@ There are 3 optional positional arguments (documented in detail below).
bpy.ops.test.operator(override_context, execution_context, undo)
- override_context - ``dict`` type.
+
+ .. deprecated:: 3.2
+
+ :class:`bpy.types.Context.temp_override` should be used instead of this argument.
+
- execution_context - ``str`` (enum).
- undo - ``bool`` type.