From 02f951c3a05f6586f12d129c70adffd8315ec3b7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 3 Sep 2009 22:37:09 +0000 Subject: 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. --- release/ui/bpy_ops.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'release/ui') 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): ''' -- cgit v1.2.3