diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-06-12 05:17:50 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-06-12 05:18:47 +0300 |
commit | 2459a1a214b950cc8baa4e8fcb48e7dfada58b77 (patch) | |
tree | e903730a6c7632832f1c2a09a02460f979679957 /release | |
parent | 017b8dfe47b56c64f6d2d708f9f358cf66dedc41 (diff) |
WM: optionally override the context with a module for wm.context_toggle
This may be used with other wm.context_* operators in the future.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/startup/bl_operators/wm.py | 22 |
1 files changed, 19 insertions, 3 deletions
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): |