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,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
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 "BLI_listbase.h"
|
|
|
|
#include "BKE_context.h"
|
2009-01-02 07:54:38 +00:00
|
|
|
#include "BKE_report.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 "DNA_windowmanager_types.h"
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
2009-11-29 01:49:22 +00:00
|
|
|
#include "UI_interface.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 "ED_screen.h"
|
|
|
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
#include "bpy_rna.h"
|
2008-12-28 08:41:49 +00:00
|
|
|
#include "bpy_util.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
|
|
|
|
2009-06-18 19:51:22 +00:00
|
|
|
#include "../generic/bpy_internal_import.h" // our own imports
|
|
|
|
|
2009-10-31 13:31:23 +00:00
|
|
|
#define PYOP_ATTR_UINAME "bl_label"
|
|
|
|
#define PYOP_ATTR_IDNAME "bl_idname" /* the name given by python */
|
|
|
|
#define PYOP_ATTR_IDNAME_BL "_bl_idname" /* our own name converted into blender syntax, users wont see this */
|
|
|
|
#define PYOP_ATTR_DESCRIPTION "__doc__" /* use pythons docstring */
|
|
|
|
#define PYOP_ATTR_REGISTER "bl_register" /* True/False. if this python operator should be registered */
|
|
|
|
#define PYOP_ATTR_UNDO "bl_undo" /* True/False. if this python operator should be undone */
|
2009-03-18 22:22:58 +00:00
|
|
|
|
2008-12-28 08:41:49 +00:00
|
|
|
static struct BPY_flag_def pyop_ret_flags[] = {
|
|
|
|
{"RUNNING_MODAL", OPERATOR_RUNNING_MODAL},
|
|
|
|
{"CANCELLED", OPERATOR_CANCELLED},
|
|
|
|
{"FINISHED", OPERATOR_FINISHED},
|
|
|
|
{"PASS_THROUGH", OPERATOR_PASS_THROUGH},
|
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
|
2008-12-28 13:03:37 +00:00
|
|
|
/* This invoke function can take events and
|
|
|
|
*
|
|
|
|
* It is up to the pyot->py_invoke() python func to run pyot->py_exec()
|
|
|
|
* the invoke function gets the keyword props as a dict, but can parse them
|
|
|
|
* to py_exec like this...
|
|
|
|
*
|
|
|
|
* def op_exec(x=-1, y=-1, text=""):
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* def op_invoke(event, prop_defs):
|
|
|
|
* prop_defs['x'] = event['x']
|
|
|
|
* ...
|
|
|
|
* op_exec(**prop_defs)
|
|
|
|
*
|
|
|
|
* when there is no invoke function, C calls exec and sets the props.
|
2009-03-16 15:54:43 +00:00
|
|
|
* python class instance is stored in op->customdata so exec() can access
|
2008-12-28 13:03:37 +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
|
|
|
|
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
#define PYOP_EXEC 1
|
|
|
|
#define PYOP_INVOKE 2
|
|
|
|
#define PYOP_POLL 3
|
2009-11-29 01:49:22 +00:00
|
|
|
#define PYOP_DRAW 4
|
2009-03-16 15:54:43 +00:00
|
|
|
|
2009-04-11 16:17:39 +00:00
|
|
|
extern void BPY_update_modules( void ); //XXX temp solution
|
|
|
|
|
2009-11-29 01:49:22 +00:00
|
|
|
static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperator *op, wmEvent *event, uiLayout *layout)
|
2009-03-16 15:54:43 +00:00
|
|
|
{
|
2009-09-18 13:02:20 +00:00
|
|
|
PyObject *py_class = ot->pyop_data;
|
2009-03-16 15:54:43 +00:00
|
|
|
PyObject *args;
|
2009-05-20 09:17:21 +00:00
|
|
|
PyObject *ret= NULL, *py_class_instance, *item= NULL;
|
2009-03-16 15:54:43 +00:00
|
|
|
int ret_flag= (mode==PYOP_POLL ? 0:OPERATOR_CANCELLED);
|
2009-06-06 17:32:06 +00:00
|
|
|
PointerRNA ptr_context;
|
2009-06-18 19:51:22 +00:00
|
|
|
PointerRNA ptr_operator;
|
2009-04-01 12:43:07 +00:00
|
|
|
|
2009-08-07 16:20:19 +00:00
|
|
|
PyGILState_STATE gilstate;
|
2009-06-18 19:51:22 +00:00
|
|
|
|
2009-08-07 16:20:19 +00:00
|
|
|
bpy_context_set(C, &gilstate);
|
2009-04-01 12:43:07 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
args = PyTuple_New(1);
|
2009-11-02 08:32:00 +00:00
|
|
|
|
|
|
|
/* poll has no 'op', should be ok still */
|
|
|
|
/* use an rna instance as the first arg */
|
|
|
|
RNA_pointer_create(NULL, &RNA_Operator, op, &ptr_operator);
|
|
|
|
PyTuple_SET_ITEM(args, 0, pyrna_struct_CreatePyObject(&ptr_operator));
|
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
py_class_instance = PyObject_Call(py_class, args, NULL);
|
2009-03-16 15:54:43 +00:00
|
|
|
Py_DECREF(args);
|
|
|
|
|
2009-11-23 18:08:42 +00:00
|
|
|
if (py_class_instance==NULL) { /* Initializing the class worked, now run its invoke function */
|
|
|
|
PyErr_Print();
|
|
|
|
PyErr_Clear();
|
|
|
|
}
|
|
|
|
else {
|
2009-06-18 19:51:22 +00:00
|
|
|
RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context);
|
2009-11-13 16:08:03 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
if (mode==PYOP_INVOKE) {
|
2009-11-29 01:49:22 +00:00
|
|
|
PointerRNA ptr_event;
|
2009-04-01 12:43:07 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, "invoke");
|
2009-06-18 19:51:22 +00:00
|
|
|
args = PyTuple_New(3);
|
2009-11-13 16:08:03 +00:00
|
|
|
|
2009-06-21 14:30:59 +00:00
|
|
|
RNA_pointer_create(NULL, &RNA_Event, event, &ptr_event);
|
2009-06-18 19:51:22 +00:00
|
|
|
|
|
|
|
// PyTuple_SET_ITEM "steals" object reference, it is
|
|
|
|
// an object passed shouldn't be DECREF'ed
|
|
|
|
PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
|
2009-06-21 14:30:59 +00:00
|
|
|
PyTuple_SET_ITEM(args, 2, pyrna_struct_CreatePyObject(&ptr_event));
|
2009-03-16 15:54:43 +00:00
|
|
|
}
|
|
|
|
else if (mode==PYOP_EXEC) {
|
2009-06-18 19:51:22 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, "execute");
|
2009-06-06 17:32:06 +00:00
|
|
|
args = PyTuple_New(2);
|
|
|
|
|
2009-06-18 19:51:22 +00:00
|
|
|
PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
|
2009-03-16 15:54:43 +00:00
|
|
|
}
|
|
|
|
else if (mode==PYOP_POLL) {
|
2009-04-01 12:43:07 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, "poll");
|
2009-03-16 15:54:43 +00:00
|
|
|
args = PyTuple_New(2);
|
2009-09-18 13:02:20 +00:00
|
|
|
PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
|
2009-03-16 15:54:43 +00:00
|
|
|
}
|
2009-11-29 01:49:22 +00:00
|
|
|
else if (mode==PYOP_DRAW) {
|
|
|
|
PointerRNA ptr_layout;
|
|
|
|
item= PyObject_GetAttrString(py_class, "draw");
|
|
|
|
args = PyTuple_New(2);
|
|
|
|
|
|
|
|
RNA_pointer_create(NULL, &RNA_UILayout, layout, &ptr_layout);
|
|
|
|
|
|
|
|
// PyTuple_SET_ITEM "steals" object reference, it is
|
|
|
|
// an object passed shouldn't be DECREF'ed
|
|
|
|
PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
|
|
|
|
#if 0
|
|
|
|
PyTuple_SET_ITEM(args, 2, pyrna_struct_CreatePyObject(&ptr_layout));
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
/* mimic panels */
|
|
|
|
PyObject *py_layout= pyrna_struct_CreatePyObject(&ptr_layout);
|
|
|
|
PyObject *pyname= PyUnicode_FromString("layout");
|
|
|
|
|
|
|
|
if(PyObject_GenericSetAttr(py_class_instance, pyname, py_layout)) {
|
|
|
|
PyErr_Print();
|
|
|
|
PyErr_Clear();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Py_DECREF(py_layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_DECREF(pyname);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2009-03-16 15:54:43 +00:00
|
|
|
PyTuple_SET_ITEM(args, 0, py_class_instance);
|
2009-11-13 16:08:03 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
ret = PyObject_Call(item, args, NULL);
|
2009-11-13 16:08:03 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
Py_DECREF(args);
|
|
|
|
Py_DECREF(item);
|
|
|
|
}
|
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
if (ret == NULL) { /* covers py_class_instance failing too */
|
2009-09-18 13:02:20 +00:00
|
|
|
if(op)
|
|
|
|
BPy_errors_to_report(op->reports);
|
2008-12-28 08:41:49 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-03-16 15:54:43 +00:00
|
|
|
if (mode==PYOP_POLL) {
|
|
|
|
if (PyBool_Check(ret) == 0) {
|
2009-11-23 18:08:42 +00:00
|
|
|
PyErr_Format(PyExc_ValueError, "Python operator '%s.poll', did not return a bool value", ot->idname);
|
|
|
|
BPy_errors_to_report(op ? op->reports:NULL); /* prints and clears if NULL given */
|
2009-03-16 15:54:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret_flag= ret==Py_True ? 1:0;
|
|
|
|
}
|
2009-11-29 01:49:22 +00:00
|
|
|
} else if(mode==PYOP_DRAW) {
|
|
|
|
/* pass */
|
2009-03-16 15:54:43 +00:00
|
|
|
} else if (BPY_flag_from_seq(pyop_ret_flags, ret, &ret_flag) == -1) {
|
2009-09-18 13:02:20 +00:00
|
|
|
/* the returned value could not be converted into a flag */
|
2009-11-23 18:08:42 +00:00
|
|
|
PyErr_Format(PyExc_ValueError, "Python operator, error using return value from \"%s\"\n", ot->idname);
|
|
|
|
BPy_errors_to_report(op ? op->reports:NULL);
|
2009-06-18 19:51:22 +00:00
|
|
|
ret_flag = OPERATOR_CANCELLED;
|
2008-12-28 08:41:49 +00:00
|
|
|
}
|
2008-12-28 13:03:37 +00:00
|
|
|
/* there is no need to copy the py keyword dict modified by
|
|
|
|
* pyot->py_invoke(), back to the operator props since they are just
|
|
|
|
* thrown away anyway
|
|
|
|
*
|
|
|
|
* If we ever want to do this and use the props again,
|
PyRNA
- Support for python to convert a PyObject into a collection (uses a list of dicts - quite verbose :/)
- Operators can now take collection args when called from python.
- Support for printing operators that use collections (macro recording).
- Added RNA_pointer_as_string which prints all pointer prop values as a python dict.
Example that can run in the in test.py (F7 key)
bpy.ops.VIEW3D_OT_select_lasso(path=[{"loc":(0, 0), "time":0}, {"loc":(1000, 0), "time":0}, {"loc":(1000, 1000), "time":0}], type='SELECT')
for some reason lasso locations always print as 0,0. Need to look into why this is.
2009-06-05 12:48:58 +00:00
|
|
|
* it can be done with - pyrna_pydict_to_props(op->ptr, kw, "")
|
2008-12-28 13:03:37 +00:00
|
|
|
*/
|
2009-03-16 15:54:43 +00:00
|
|
|
|
|
|
|
Py_DECREF(ret);
|
2008-12-28 08:41:49 +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
|
|
|
|
2009-07-18 16:27:25 +00:00
|
|
|
#if 0 /* only for testing */
|
|
|
|
|
2009-06-18 19:51:22 +00:00
|
|
|
/* print operator return value */
|
|
|
|
if (mode != PYOP_POLL) {
|
|
|
|
char flag_str[100];
|
|
|
|
char class_name[100];
|
|
|
|
BPY_flag_def *flag_def = pyop_ret_flags;
|
|
|
|
|
|
|
|
strcpy(flag_str, "");
|
|
|
|
|
|
|
|
while(flag_def->name) {
|
|
|
|
if (ret_flag & flag_def->flag) {
|
|
|
|
if(flag_str[1])
|
|
|
|
sprintf(flag_str, "%s | %s", flag_str, flag_def->name);
|
|
|
|
else
|
|
|
|
strcpy(flag_str, flag_def->name);
|
|
|
|
}
|
|
|
|
flag_def++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get class name */
|
|
|
|
item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME);
|
|
|
|
strcpy(class_name, _PyUnicode_AsString(item));
|
2009-07-16 07:11:46 +00:00
|
|
|
Py_DECREF(item);
|
2009-06-18 19:51:22 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "%s's %s returned %s\n", class_name, mode == PYOP_EXEC ? "execute" : "invoke", flag_str);
|
|
|
|
}
|
2009-07-18 16:27:25 +00:00
|
|
|
#endif
|
2009-06-18 19:51:22 +00:00
|
|
|
|
2009-08-07 16:20:19 +00:00
|
|
|
bpy_context_clear(C, &gilstate);
|
2009-04-01 12:43:07 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
return ret_flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int PYTHON_OT_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2009-11-29 01:49:22 +00:00
|
|
|
return PYTHON_OT_generic(PYOP_INVOKE, C, op->type, op, event, NULL);
|
2009-03-16 15:54:43 +00:00
|
|
|
}
|
2008-12-28 08:41:49 +00:00
|
|
|
|
2009-09-04 04:29:54 +00:00
|
|
|
static int PYTHON_OT_execute(bContext *C, wmOperator *op)
|
2009-03-16 15:54:43 +00:00
|
|
|
{
|
2009-11-29 01:49:22 +00:00
|
|
|
return PYTHON_OT_generic(PYOP_EXEC, C, op->type, op, NULL, NULL);
|
2009-03-16 15:54:43 +00:00
|
|
|
}
|
2008-12-28 08:41:49 +00:00
|
|
|
|
2009-09-18 13:02:20 +00:00
|
|
|
static int PYTHON_OT_poll(bContext *C, wmOperatorType *ot)
|
2009-03-16 15:54:43 +00:00
|
|
|
{
|
2009-11-29 01:49:22 +00:00
|
|
|
return PYTHON_OT_generic(PYOP_POLL, C, ot, NULL, NULL, NULL);
|
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-11-29 01:49:22 +00:00
|
|
|
static void PYTHON_OT_draw(bContext *C, wmOperator *op, uiLayout *layout)
|
|
|
|
{
|
|
|
|
PYTHON_OT_generic(PYOP_DRAW, C, op->type, op, NULL, layout);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
|
|
|
{
|
2009-04-01 12:43:07 +00:00
|
|
|
PyObject *py_class = (PyObject *)userdata;
|
2009-11-02 00:20:07 +00:00
|
|
|
PyObject *item;
|
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
|
|
|
|
|
|
|
/* identifiers */
|
2009-07-19 13:32:02 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME_BL);
|
2009-04-01 12:43:07 +00:00
|
|
|
ot->idname= _PyUnicode_AsString(item);
|
2009-07-16 07:11:46 +00:00
|
|
|
Py_DECREF(item);
|
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-04-01 12:43:07 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, PYOP_ATTR_UINAME);
|
|
|
|
if (item) {
|
|
|
|
ot->name= _PyUnicode_AsString(item);
|
2009-07-16 07:11:46 +00:00
|
|
|
Py_DECREF(item);
|
2009-04-01 12:43:07 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ot->name= ot->idname;
|
|
|
|
PyErr_Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
item= PyObject_GetAttrString(py_class, PYOP_ATTR_DESCRIPTION);
|
2009-07-26 18:18:14 +00:00
|
|
|
ot->description= (item && PyUnicode_Check(item)) ? _PyUnicode_AsString(item):"undocumented python operator";
|
|
|
|
Py_XDECREF(item);
|
2009-04-01 12:43:07 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
/* api callbacks, detailed checks dont on adding */
|
|
|
|
if (PyObject_HasAttrString(py_class, "invoke"))
|
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
|
|
|
ot->invoke= PYTHON_OT_invoke;
|
- 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
|
|
|
//else
|
|
|
|
// ot->invoke= WM_operator_props_popup; /* could have an option for standard invokes */
|
|
|
|
|
2009-06-18 19:51:22 +00:00
|
|
|
if (PyObject_HasAttrString(py_class, "execute"))
|
2009-09-04 04:29:54 +00:00
|
|
|
ot->exec= PYTHON_OT_execute;
|
2009-03-16 15:54:43 +00:00
|
|
|
if (PyObject_HasAttrString(py_class, "poll"))
|
2009-09-18 13:02:20 +00:00
|
|
|
ot->pyop_poll= PYTHON_OT_poll;
|
2009-11-29 01:49:22 +00:00
|
|
|
if (PyObject_HasAttrString(py_class, "draw"))
|
|
|
|
ot->ui= PYTHON_OT_draw;
|
2008-12-28 08:41:49 +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
|
|
|
ot->pyop_data= userdata;
|
|
|
|
|
2009-07-16 07:11:46 +00:00
|
|
|
/* flags */
|
2009-10-08 07:54:20 +00:00
|
|
|
ot->flag= 0;
|
|
|
|
|
2009-07-16 07:11:46 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, PYOP_ATTR_REGISTER);
|
|
|
|
if (item) {
|
2009-10-08 07:54:20 +00:00
|
|
|
ot->flag |= PyObject_IsTrue(item)!=0 ? OPTYPE_REGISTER:0;
|
2009-07-16 07:11:46 +00:00
|
|
|
Py_DECREF(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyErr_Clear();
|
|
|
|
}
|
2009-10-08 07:54:20 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, PYOP_ATTR_UNDO);
|
|
|
|
if (item) {
|
|
|
|
ot->flag |= PyObject_IsTrue(item)!=0 ? OPTYPE_UNDO:0;
|
|
|
|
Py_DECREF(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyErr_Clear();
|
|
|
|
}
|
|
|
|
|
define operator properties in the class, similar to django fields
# Before
[
bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""),
bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True),
bpy.props.BoolProperty(attr="use_normals", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True),
bpy.props.BoolProperty(attr="use_uvs", name="Export UVs", description="Exort the active UV layer", default= True),
bpy.props.BoolProperty(attr="use_colors", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
]
# After
path = StringProperty(attr="", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "")
use_modifiers = BoolProperty(attr="", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True)
use_normals = BoolProperty(attr="", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True)
use_uvs = BoolProperty(attr="", name="Export UVs", description="Exort the active UV layer", default= True)
use_colors = BoolProperty(attr="", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
2009-10-31 16:40:14 +00:00
|
|
|
/* Can't use this because it returns a dict proxy
|
|
|
|
*
|
|
|
|
* item= PyObject_GetAttrString(py_class, "__dict__");
|
|
|
|
*/
|
|
|
|
item= ((PyTypeObject*)py_class)->tp_dict;
|
|
|
|
if(item) {
|
2009-11-19 14:32:12 +00:00
|
|
|
/* only call this so pyrna_deferred_register_props gives a useful error
|
|
|
|
* WM_operatortype_append_ptr will call RNA_def_struct_identifier
|
|
|
|
* later */
|
|
|
|
RNA_def_struct_identifier(ot->srna, ot->idname);
|
|
|
|
|
define operator properties in the class, similar to django fields
# Before
[
bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""),
bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True),
bpy.props.BoolProperty(attr="use_normals", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True),
bpy.props.BoolProperty(attr="use_uvs", name="Export UVs", description="Exort the active UV layer", default= True),
bpy.props.BoolProperty(attr="use_colors", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
]
# After
path = StringProperty(attr="", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "")
use_modifiers = BoolProperty(attr="", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True)
use_normals = BoolProperty(attr="", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True)
use_uvs = BoolProperty(attr="", name="Export UVs", description="Exort the active UV layer", default= True)
use_colors = BoolProperty(attr="", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
2009-10-31 16:40:14 +00:00
|
|
|
if(pyrna_deferred_register_props(ot->srna, item)!=0) {
|
2009-11-19 14:32:12 +00:00
|
|
|
/* failed to register operator props */
|
define operator properties in the class, similar to django fields
# Before
[
bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""),
bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True),
bpy.props.BoolProperty(attr="use_normals", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True),
bpy.props.BoolProperty(attr="use_uvs", name="Export UVs", description="Exort the active UV layer", default= True),
bpy.props.BoolProperty(attr="use_colors", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
]
# After
path = StringProperty(attr="", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "")
use_modifiers = BoolProperty(attr="", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True)
use_normals = BoolProperty(attr="", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True)
use_uvs = BoolProperty(attr="", name="Export UVs", description="Exort the active UV layer", default= True)
use_colors = BoolProperty(attr="", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
2009-10-31 16:40:14 +00:00
|
|
|
PyErr_Print();
|
|
|
|
PyErr_Clear();
|
2009-11-19 14:32:12 +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
|
|
|
}
|
define operator properties in the class, similar to django fields
# Before
[
bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""),
bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True),
bpy.props.BoolProperty(attr="use_normals", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True),
bpy.props.BoolProperty(attr="use_uvs", name="Export UVs", description="Exort the active UV layer", default= True),
bpy.props.BoolProperty(attr="use_colors", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
]
# After
path = StringProperty(attr="", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "")
use_modifiers = BoolProperty(attr="", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True)
use_normals = BoolProperty(attr="", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True)
use_uvs = BoolProperty(attr="", name="Export UVs", description="Exort the active UV layer", default= True)
use_colors = BoolProperty(attr="", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
2009-10-31 16:40:14 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-03-16 15:54:43 +00:00
|
|
|
PyErr_Clear();
|
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-03-16 15:54:43 +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
|
|
|
/* pyOperators - Operators defined IN Python */
|
2009-04-01 12:43:07 +00:00
|
|
|
PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
|
2009-03-18 22:22:58 +00:00
|
|
|
{
|
2009-04-01 12:43:07 +00:00
|
|
|
PyObject *base_class, *item;
|
2009-06-18 19:51:22 +00:00
|
|
|
wmOperatorType *ot;
|
2009-03-16 15:54:43 +00:00
|
|
|
|
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
char *idname= NULL;
|
2009-07-19 13:32:02 +00:00
|
|
|
char idname_bl[OP_MAX_TYPENAME]; /* converted to blender syntax */
|
2009-04-01 12:43:07 +00:00
|
|
|
|
|
|
|
static struct BPY_class_attr_check pyop_class_attr_values[]= {
|
2009-07-19 13:32:02 +00:00
|
|
|
{PYOP_ATTR_IDNAME, 's', -1, OP_MAX_TYPENAME-3, 0}, /* -3 because a.b -> A_OT_b */
|
|
|
|
{PYOP_ATTR_UINAME, 's', -1,-1, BPY_CLASS_ATTR_OPTIONAL},
|
|
|
|
{PYOP_ATTR_DESCRIPTION, 's', -1,-1, BPY_CLASS_ATTR_NONE_OK},
|
|
|
|
{"execute", 'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL},
|
|
|
|
{"invoke", 'f', 3, -1, BPY_CLASS_ATTR_OPTIONAL},
|
|
|
|
{"poll", 'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL},
|
2009-11-29 01:49:22 +00:00
|
|
|
{"draw", 'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL},
|
2009-04-01 12:43:07 +00:00
|
|
|
{NULL, 0, 0, 0}
|
|
|
|
};
|
2009-03-18 22:22:58 +00:00
|
|
|
|
|
|
|
// in python would be...
|
|
|
|
//PyObject *optype = PyObject_GetAttrString(PyObject_GetAttrString(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), "types"), "Operator");
|
2009-11-13 11:10:29 +00:00
|
|
|
|
|
|
|
//PyObject bpy_mod= PyDict_GetItemString(PyEval_GetGlobals(), "bpy");
|
|
|
|
PyObject *bpy_mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
|
|
|
|
base_class = PyObject_GetAttrStringArgs(bpy_mod, 2, "types", "Operator");
|
|
|
|
Py_DECREF(bpy_mod);
|
2009-03-21 06:55:30 +00:00
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
if(BPY_class_validate("Operator", py_class, base_class, pyop_class_attr_values, NULL) < 0) {
|
|
|
|
return NULL; /* BPY_class_validate sets the error */
|
2008-12-27 16:35:15 +00:00
|
|
|
}
|
2009-07-16 07:11:46 +00:00
|
|
|
Py_DECREF(base_class);
|
2009-04-01 12:43:07 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
/* class name is used for operator ID - this can be changed later if we want */
|
2009-04-01 12:43:07 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME);
|
2009-03-18 22:22:58 +00:00
|
|
|
idname = _PyUnicode_AsString(item);
|
2009-07-19 13:32:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* annoying conversion! */
|
|
|
|
WM_operator_bl_idname(idname_bl, idname);
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
|
|
|
item= PyUnicode_FromString(idname_bl);
|
|
|
|
PyObject_SetAttrString(py_class, PYOP_ATTR_IDNAME_BL, item);
|
|
|
|
idname = _PyUnicode_AsString(item);
|
2009-07-16 07:11:46 +00:00
|
|
|
Py_DECREF(item);
|
2009-07-19 13:32:02 +00:00
|
|
|
/* end annoying conversion! */
|
|
|
|
|
2009-03-18 22:22:58 +00:00
|
|
|
|
2009-06-18 19:51:22 +00:00
|
|
|
/* remove if it already exists */
|
2009-07-08 21:31:28 +00:00
|
|
|
if ((ot=WM_operatortype_exists(idname))) {
|
|
|
|
if(ot->pyop_data) {
|
2009-06-30 19:20:45 +00:00
|
|
|
Py_XDECREF((PyObject*)ot->pyop_data);
|
2009-07-08 21:31:28 +00:00
|
|
|
}
|
2009-06-18 19:51:22 +00:00
|
|
|
WM_operatortype_remove(idname);
|
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-03-16 15:54:43 +00:00
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
Py_INCREF(py_class);
|
|
|
|
WM_operatortype_append_ptr(PYTHON_OT_wrapper, py_class);
|
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
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
PyObject *PYOP_wrap_remove(PyObject *self, PyObject *value)
|
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-04-01 12:43:07 +00:00
|
|
|
PyObject *py_class;
|
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
|
|
|
char *idname= NULL;
|
|
|
|
wmOperatorType *ot;
|
2009-04-01 12:43:07 +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
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
if (PyUnicode_Check(value))
|
|
|
|
idname = _PyUnicode_AsString(value);
|
|
|
|
else if (PyCFunction_Check(value)) {
|
|
|
|
PyObject *cfunc_self = PyCFunction_GetSelf(value);
|
|
|
|
if (cfunc_self)
|
|
|
|
idname = _PyUnicode_AsString(cfunc_self);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idname==NULL) {
|
|
|
|
PyErr_SetString( PyExc_ValueError, "Expected the operator name as a string or the operator function");
|
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
|
|
|
return NULL;
|
2009-03-16 15:54:43 +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
|
|
|
|
2009-07-08 21:31:28 +00:00
|
|
|
if (!(ot= WM_operatortype_exists(idname))) {
|
2008-12-28 08:41:49 +00:00
|
|
|
PyErr_Format( PyExc_AttributeError, "Operator \"%s\" does not exists, cant remove", idname);
|
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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
if (!(py_class= (PyObject *)ot->pyop_data)) {
|
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
|
|
|
PyErr_Format( PyExc_AttributeError, "Operator \"%s\" was not created by python", idname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
Py_XDECREF(py_class);
|
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
|
|
|
|
|
|
|
WM_operatortype_remove(idname);
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|