2011-02-27 20:10:08 +00:00
|
|
|
/*
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
*
|
|
|
|
|
* Contributor(s): Campbell Barton
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:10:08 +00:00
|
|
|
/** \file blender/python/intern/bpy_operator_wrap.c
|
|
|
|
|
* \ingroup pythonintern
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2011-02-14 04:15:25 +00:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
#include "bpy_operator_wrap.h"
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2011-03-02 04:51:43 +00:00
|
|
|
#include "RNA_access.h"
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
|
|
#include "bpy_rna.h"
|
|
|
|
|
|
2010-01-15 22:02:32 +00:00
|
|
|
static void operator_properties_init(wmOperatorType *ot)
|
|
|
|
|
{
|
2011-03-19 11:12:48 +00:00
|
|
|
PyObject *py_class= ot->ext.data;
|
2010-01-15 22:02:32 +00:00
|
|
|
RNA_struct_blender_type_set(ot->ext.srna, ot);
|
|
|
|
|
|
2010-08-19 10:16:30 +00:00
|
|
|
/* only call this so pyrna_deferred_register_class gives a useful error
|
|
|
|
|
* WM_operatortype_append_ptr will call RNA_def_struct_identifier
|
|
|
|
|
* later */
|
|
|
|
|
RNA_def_struct_identifier(ot->srna, ot->idname);
|
2010-01-15 22:02:32 +00:00
|
|
|
|
2010-08-19 10:16:30 +00:00
|
|
|
if(pyrna_deferred_register_class(ot->srna, py_class) != 0) {
|
|
|
|
|
PyErr_Print(); /* failed to register operator props */
|
2010-01-15 22:02:32 +00:00
|
|
|
PyErr_Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-06-18 19:51:22 +00:00
|
|
|
|
2009-12-24 19:50:43 +00:00
|
|
|
void operator_wrapper(wmOperatorType *ot, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
/* take care not to overwrite anything set in
|
|
|
|
|
* WM_operatortype_append_ptr before opfunc() is called */
|
2011-03-19 11:12:48 +00:00
|
|
|
StructRNA *srna= ot->srna;
|
2009-12-24 19:50:43 +00:00
|
|
|
*ot= *((wmOperatorType *)userdata);
|
|
|
|
|
ot->srna= srna; /* restore */
|
|
|
|
|
|
2010-01-15 22:02:32 +00:00
|
|
|
operator_properties_init(ot);
|
2009-12-24 19:50:43 +00:00
|
|
|
|
2010-01-15 22:40:33 +00:00
|
|
|
{ /* XXX - not nice, set the first enum as searchable, should have a way for python to set */
|
|
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
2009-12-24 19:50:43 +00:00
|
|
|
|
2010-01-15 22:40:33 +00:00
|
|
|
RNA_pointer_create(NULL, ot->srna, NULL, &ptr);
|
2011-03-19 11:12:48 +00:00
|
|
|
prop= RNA_struct_find_property(&ptr, "type");
|
2010-01-15 22:40:33 +00:00
|
|
|
if(prop)
|
|
|
|
|
ot->prop= prop;
|
2009-12-24 19:50:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-30 22:14:32 +00:00
|
|
|
void macro_wrapper(wmOperatorType *ot, void *userdata)
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
{
|
2011-03-19 11:12:48 +00:00
|
|
|
wmOperatorType *data= (wmOperatorType *)userdata;
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
|
2009-12-30 22:14:32 +00:00
|
|
|
/* only copy a couple of things, the rest is set by the macro registration */
|
2011-03-19 11:12:48 +00:00
|
|
|
ot->name= data->name;
|
|
|
|
|
ot->idname= data->idname;
|
|
|
|
|
ot->description= data->description;
|
2009-12-30 22:14:32 +00:00
|
|
|
ot->flag |= data->flag; /* append flags to the one set by registration */
|
2011-03-19 11:12:48 +00:00
|
|
|
ot->pyop_poll= data->pyop_poll;
|
|
|
|
|
ot->ui= data->ui;
|
|
|
|
|
ot->ext= data->ext;
|
- add torus back from 2.4x as an operator
bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)
- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.
- removed OBJECT_OT_mesh_add, use the python add menu instead.
- made mesh primitive ops - MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.
- RNA scene.active_object wrapped
- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.
2009-10-10 21:23:20 +00:00
|
|
|
|
2010-01-15 22:02:32 +00:00
|
|
|
operator_properties_init(ot);
|
2009-12-05 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-13 23:25:08 +00:00
|
|
|
PyObject *PYOP_wrap_macro_define(PyObject *UNUSED(self), PyObject *args)
|
2009-12-05 19:27:26 +00:00
|
|
|
{
|
|
|
|
|
wmOperatorType *ot;
|
|
|
|
|
wmOperatorTypeMacro *otmacro;
|
|
|
|
|
PyObject *macro;
|
|
|
|
|
PointerRNA ptr_otmacro;
|
2009-12-30 22:14:32 +00:00
|
|
|
StructRNA *srna;
|
2009-12-05 19:27:26 +00:00
|
|
|
|
|
|
|
|
char *opname;
|
2009-12-30 22:14:32 +00:00
|
|
|
const char *macroname;
|
2009-12-05 19:27:26 +00:00
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "Os:_bpy.ops.macro_define", ¯o, &opname))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2010-08-13 14:42:45 +00:00
|
|
|
if (WM_operatortype_find(opname, TRUE) == NULL) {
|
2009-12-05 19:27:26 +00:00
|
|
|
PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid operator id", opname);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* identifiers */
|
2010-03-16 17:20:15 +00:00
|
|
|
srna= srna_from_self(macro, "Macro Define:");
|
2011-03-19 11:12:48 +00:00
|
|
|
macroname= RNA_struct_identifier(srna);
|
2009-12-05 19:27:26 +00:00
|
|
|
|
2011-03-19 11:12:48 +00:00
|
|
|
ot= WM_operatortype_find(macroname, TRUE);
|
2009-12-05 19:27:26 +00:00
|
|
|
|
|
|
|
|
if (!ot) {
|
|
|
|
|
PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid macro or hasn't been registered yet", macroname);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 11:12:48 +00:00
|
|
|
otmacro= WM_operatortype_macro_define(ot, opname);
|
2009-12-05 19:27:26 +00:00
|
|
|
|
|
|
|
|
RNA_pointer_create(NULL, &RNA_OperatorTypeMacro, otmacro, &ptr_otmacro);
|
|
|
|
|
|
|
|
|
|
return pyrna_struct_CreatePyObject(&ptr_otmacro);
|
|
|
|
|
}
|
|
|
|
|
|