[Bf-blender-cvs] [2459a1a214b] master: WM: optionally override the context with a module for wm.context_toggle

Campbell Barton noreply at git.blender.org
Wed Jun 12 04:32:57 CEST 2019


Commit: 2459a1a214b950cc8baa4e8fcb48e7dfada58b77
Author: Campbell Barton
Date:   Wed Jun 12 12:17:50 2019 +1000
Branches: master
https://developer.blender.org/rB2459a1a214b950cc8baa4e8fcb48e7dfada58b77

WM: optionally override the context with a module for wm.context_toggle

This may be used with other wm.context_* operators in the future.

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

M	release/scripts/startup/bl_operators/wm.py

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

diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index 0788e3bc51c..774c8e63002 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -69,6 +69,14 @@ rna_space_type_prop = EnumProperty(
     default='EMPTY',
 )
 
+# Note, this can be used for more operators,
+# currently not used for all "WM_OT_context_" operators.
+rna_module_prop = StringProperty(
+    name="Module",
+    description="Optionally override the context with a module",
+    maxlen=1024,
+)
+
 
 def context_path_validate(context, data_path):
     try:
@@ -325,16 +333,24 @@ class WM_OT_context_toggle(Operator):
     bl_options = {'UNDO', 'INTERNAL'}
 
     data_path: rna_path_prop
+    module: rna_module_prop
 
     def execute(self, context):
         data_path = self.data_path
 
-        if context_path_validate(context, data_path) is Ellipsis:
+        module = self.module
+        if not module:
+            base = context
+        else:
+            from importlib import import_module
+            base = import_module(self.module)
+
+        if context_path_validate(base, data_path) is Ellipsis:
             return {'PASS_THROUGH'}
 
-        exec("context.%s = not (context.%s)" % (data_path, data_path))
+        exec("base.%s = not (base.%s)" % (data_path, data_path))
 
-        return operator_path_undo_return(context, data_path)
+        return operator_path_undo_return(base, data_path)
 
 
 class WM_OT_context_toggle_enum(Operator):



More information about the Bf-blender-cvs mailing list