[Bf-blender-cvs] [f0862773b4d] draw-deferred-compilation-experiment: Docs: update examples to use Context.temp_override

Campbell Barton noreply at git.blender.org
Thu Apr 21 11:14:09 CEST 2022


Commit: f0862773b4ddfffd657690d6407e8bafbeed8838
Author: Campbell Barton
Date:   Wed Apr 20 12:49:13 2022 +1000
Branches: draw-deferred-compilation-experiment
https://developer.blender.org/rBf0862773b4ddfffd657690d6407e8bafbeed8838

Docs: update examples to use Context.temp_override

===================================================================

M	doc/python_api/examples/bpy.ops.1.py
M	doc/python_api/examples/bpy.ops.3.py
M	doc/python_api/examples/bpy.ops.py

===================================================================

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.



More information about the Bf-blender-cvs mailing list