diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-09-04 02:37:09 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-09-04 02:37:09 +0400 |
commit | 02f951c3a05f6586f12d129c70adffd8315ec3b7 (patch) | |
tree | fea0ba96dffe2ee86a781046c57c52863532f73f /release | |
parent | fc975a91484a1346049071fa9c6c8877820245cd (diff) |
allow execution mode to be given as an argument to operators from python (requested by algorith)
example. bpy.ops.tfm.rotate('INVOKE_REGION_WIN', pivot=(0,1,2), ......)
bpy_array.c - was too strict with types, 0 should be allowed as well as 0.0 in a float array.
Diffstat (limited to 'release')
-rw-r--r-- | release/ui/bpy_ops.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/release/ui/bpy_ops.py b/release/ui/bpy_ops.py index aa9bfb460f0..dff8125fca1 100644 --- a/release/ui/bpy_ops.py +++ b/release/ui/bpy_ops.py @@ -5,6 +5,18 @@ from bpy.__ops__ import dir as op_dir from bpy.__ops__ import call as op_call from bpy.__ops__ import get_rna as op_get_rna +# Keep in sync with WM_types.h +context_dict = { + 'INVOKE_DEFAULT':0, + 'INVOKE_REGION_WIN':1, + 'INVOKE_AREA':2, + 'INVOKE_SCREEN':3, + 'EXEC_DEFAULT':4, + 'EXEC_REGION_WIN':5, + 'EXEC_AREA':6, + 'EXEC_SCREEN':7, +} + class bpy_ops(object): ''' Fake module like class. @@ -94,10 +106,22 @@ class bpy_ops_submodule_op(object): # submod.foo -> SUBMOD_OT_foo return self.module.upper() + '_OT_' + self.func - def __call__(self, **kw): + def __call__(self, *args, **kw): # Get the operator from blender - return op_call(self.idname(), kw) + if len(args) > 1: + raise ValueError("only one argument for the execution context is supported ") + + if args: + try: + context = context_dict[args[0]] + except: + raise ValueError("Expected a single context argument in: " + str(list(context_dict.keys()))) + + return op_call(self.idname(), kw, context) + + else: + return op_call(self.idname(), kw) def get_rna(self): ''' |