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"
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
#include "bpy_rna.h"
|
|
|
|
#include "bpy_compat.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-03-18 22:22:58 +00:00
|
|
|
#define PYOP_ATTR_PROP "__props__"
|
|
|
|
#define PYOP_ATTR_UINAME "__label__"
|
|
|
|
#define PYOP_ATTR_IDNAME "__name__" /* use pythons class name */
|
|
|
|
#define PYOP_ATTR_DESCRIPTION "__doc__" /* use pythons docstring */
|
|
|
|
|
2008-12-28 08:41:49 +00:00
|
|
|
static PyObject *pyop_dict_from_event(wmEvent *event)
|
|
|
|
{
|
|
|
|
PyObject *dict= PyDict_New();
|
|
|
|
PyObject *item;
|
|
|
|
char *cstring, ascii[2];
|
|
|
|
|
|
|
|
/* type */
|
|
|
|
item= PyUnicode_FromString(WM_key_event_string(event->type));
|
|
|
|
PyDict_SetItemString(dict, "type", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
/* val */
|
|
|
|
switch(event->val) {
|
|
|
|
case KM_ANY:
|
|
|
|
cstring = "ANY";
|
|
|
|
break;
|
|
|
|
case KM_RELEASE:
|
|
|
|
cstring = "RELEASE";
|
|
|
|
break;
|
|
|
|
case KM_PRESS:
|
|
|
|
cstring = "PRESS";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cstring = "UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
item= PyUnicode_FromString(cstring);
|
|
|
|
PyDict_SetItemString(dict, "val", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
/* x, y (mouse) */
|
|
|
|
item= PyLong_FromLong(event->x);
|
|
|
|
PyDict_SetItemString(dict, "x", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
item= PyLong_FromLong(event->y);
|
|
|
|
PyDict_SetItemString(dict, "y", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
item= PyLong_FromLong(event->prevx);
|
|
|
|
PyDict_SetItemString(dict, "prevx", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
item= PyLong_FromLong(event->prevy);
|
|
|
|
PyDict_SetItemString(dict, "prevy", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
/* ascii */
|
|
|
|
ascii[0]= event->ascii;
|
|
|
|
ascii[1]= '\0';
|
|
|
|
item= PyUnicode_FromString(ascii);
|
|
|
|
PyDict_SetItemString(dict, "ascii", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
/* modifier keys */
|
|
|
|
item= PyLong_FromLong(event->shift);
|
|
|
|
PyDict_SetItemString(dict, "shift", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
item= PyLong_FromLong(event->ctrl);
|
|
|
|
PyDict_SetItemString(dict, "ctrl", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
item= PyLong_FromLong(event->alt);
|
|
|
|
PyDict_SetItemString(dict, "alt", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
item= PyLong_FromLong(event->oskey);
|
|
|
|
PyDict_SetItemString(dict, "oskey", item); Py_DECREF(item);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* modifier */
|
|
|
|
#if 0
|
|
|
|
item= PyTuple_New(0);
|
|
|
|
if(event->keymodifier & KM_SHIFT) {
|
|
|
|
_PyTuple_Resize(&item, size+1);
|
|
|
|
PyTuple_SET_ITEM(item, size, _PyUnicode_AsString("SHIFT"));
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
if(event->keymodifier & KM_CTRL) {
|
|
|
|
_PyTuple_Resize(&item, size+1);
|
|
|
|
PyTuple_SET_ITEM(item, size, _PyUnicode_AsString("CTRL"));
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
if(event->keymodifier & KM_ALT) {
|
|
|
|
_PyTuple_Resize(&item, size+1);
|
|
|
|
PyTuple_SET_ITEM(item, size, _PyUnicode_AsString("ALT"));
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
if(event->keymodifier & KM_OSKEY) {
|
|
|
|
_PyTuple_Resize(&item, size+1);
|
|
|
|
PyTuple_SET_ITEM(item, size, _PyUnicode_AsString("OSKEY"));
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
PyDict_SetItemString(dict, "keymodifier", item); Py_DECREF(item);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
2009-01-02 07:54:38 +00:00
|
|
|
/* TODO - a whole traceback would be ideal */
|
|
|
|
static void pyop_error_report(ReportList *reports)
|
|
|
|
{
|
|
|
|
PyObject *exception, *v, *tb;
|
|
|
|
PyErr_Fetch(&exception, &v, &tb);
|
|
|
|
if (exception == NULL)
|
|
|
|
return;
|
|
|
|
/* Now we know v != NULL too */
|
|
|
|
BKE_report(reports, RPT_ERROR, _PyUnicode_AsString(v));
|
|
|
|
|
|
|
|
PyErr_Print();
|
|
|
|
}
|
|
|
|
|
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-04-11 16:17:39 +00:00
|
|
|
extern void BPY_update_modules( void ); //XXX temp solution
|
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2009-04-01 12:43:07 +00:00
|
|
|
PyObject *py_class = op->type->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-04-01 12:43:07 +00:00
|
|
|
|
|
|
|
PyGILState_STATE gilstate = PyGILState_Ensure();
|
2009-04-11 16:17:39 +00:00
|
|
|
|
|
|
|
BPY_update_modules(); // XXX - the RNA pointers can change so update before running, would like a nicer solutuon for this.
|
2009-04-01 12:43:07 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
args = PyTuple_New(1);
|
2009-04-01 12:43:07 +00:00
|
|
|
PyTuple_SET_ITEM(args, 0, PyObject_GetAttrString(py_class, "__rna__")); // need to use an rna instance as the first arg
|
|
|
|
py_class_instance = PyObject_Call(py_class, args, NULL);
|
2009-03-16 15:54:43 +00:00
|
|
|
Py_DECREF(args);
|
|
|
|
|
|
|
|
if (py_class_instance) { /* Initializing the class worked, now run its invoke function */
|
|
|
|
|
|
|
|
|
|
|
|
/* Assign instance attributes from operator properties */
|
|
|
|
{
|
|
|
|
PropertyRNA *prop, *iterprop;
|
|
|
|
CollectionPropertyIterator iter;
|
|
|
|
const char *arg_name;
|
|
|
|
|
2009-04-19 13:37:59 +00:00
|
|
|
iterprop= RNA_struct_iterator_property(op->ptr->type);
|
2009-03-16 15:54:43 +00:00
|
|
|
RNA_property_collection_begin(op->ptr, iterprop, &iter);
|
|
|
|
|
|
|
|
for(; iter.valid; RNA_property_collection_next(&iter)) {
|
|
|
|
prop= iter.ptr.data;
|
2009-04-19 13:37:59 +00:00
|
|
|
arg_name= RNA_property_identifier(prop);
|
2009-03-16 15:54:43 +00:00
|
|
|
|
|
|
|
if (strcmp(arg_name, "rna_type")==0) continue;
|
|
|
|
|
|
|
|
item = pyrna_prop_to_py(op->ptr, prop);
|
|
|
|
PyObject_SetAttrString(py_class_instance, arg_name, item);
|
|
|
|
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-03-16 15:54:43 +00:00
|
|
|
RNA_property_collection_end(&iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mode==PYOP_INVOKE) {
|
2009-04-01 12:43:07 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, "invoke");
|
2009-03-16 15:54:43 +00:00
|
|
|
args = PyTuple_New(2);
|
|
|
|
PyTuple_SET_ITEM(args, 1, pyop_dict_from_event(event));
|
|
|
|
}
|
|
|
|
else if (mode==PYOP_EXEC) {
|
2009-04-01 12:43:07 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, "exec");
|
2009-03-16 15:54:43 +00:00
|
|
|
args = PyTuple_New(1);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
//XXX Todo - wrap context in a useful way, None for now.
|
|
|
|
PyTuple_SET_ITEM(args, 1, Py_None);
|
|
|
|
}
|
|
|
|
PyTuple_SET_ITEM(args, 0, py_class_instance);
|
|
|
|
|
|
|
|
ret = PyObject_Call(item, args, NULL);
|
|
|
|
|
|
|
|
Py_DECREF(args);
|
|
|
|
Py_DECREF(item);
|
|
|
|
}
|
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
if (ret == NULL) { /* covers py_class_instance failing too */
|
2009-01-02 07:54:38 +00:00
|
|
|
pyop_error_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) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Python poll function return value ");
|
|
|
|
pyop_error_report(op->reports);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret_flag= ret==Py_True ? 1:0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (BPY_flag_from_seq(pyop_ret_flags, ret, &ret_flag) == -1) {
|
2008-12-28 08:41:49 +00:00
|
|
|
/* the returned value could not be converted into a flag */
|
2009-01-02 07:54:38 +00:00
|
|
|
pyop_error_report(op->reports);
|
2009-03-16 15:54:43 +00:00
|
|
|
|
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-04-01 12:43:07 +00:00
|
|
|
PyGILState_Release(gilstate);
|
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
return ret_flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int PYTHON_OT_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
|
|
|
return PYTHON_OT_generic(PYOP_INVOKE, C, op, event);
|
|
|
|
}
|
2008-12-28 08:41:49 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
static int PYTHON_OT_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
return PYTHON_OT_generic(PYOP_EXEC, C, op, NULL);
|
|
|
|
}
|
2008-12-28 08:41:49 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
static int PYTHON_OT_poll(bContext *C)
|
|
|
|
{
|
|
|
|
// XXX TODO - no way to get the operator type (and therefor class) from the poll function.
|
|
|
|
//return PYTHON_OT_generic(PYOP_POLL, C, NULL, NULL);
|
|
|
|
return 1;
|
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-03-17 22:27:15 +00:00
|
|
|
PyObject *props, *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-04-01 12:43:07 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME);
|
|
|
|
Py_DECREF(item);
|
|
|
|
ot->idname= _PyUnicode_AsString(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) {
|
|
|
|
Py_DECREF(item);
|
|
|
|
ot->name= _PyUnicode_AsString(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ot->name= ot->idname;
|
|
|
|
PyErr_Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
item= PyObject_GetAttrString(py_class, PYOP_ATTR_DESCRIPTION);
|
|
|
|
Py_DECREF(item);
|
|
|
|
ot->description= (item && PyUnicode_Check(item)) ? _PyUnicode_AsString(item):"";
|
|
|
|
|
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;
|
2009-03-16 15:54:43 +00:00
|
|
|
if (PyObject_HasAttrString(py_class, "exec"))
|
|
|
|
ot->exec= PYTHON_OT_exec;
|
|
|
|
if (PyObject_HasAttrString(py_class, "poll"))
|
|
|
|
ot->poll= PYTHON_OT_poll;
|
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-03-18 22:22:58 +00:00
|
|
|
props= PyObject_GetAttrString(py_class, PYOP_ATTR_PROP);
|
2009-03-16 15:54:43 +00:00
|
|
|
|
2009-03-18 22:22:58 +00:00
|
|
|
if (props) {
|
2009-03-16 15:54:43 +00:00
|
|
|
PyObject *dummy_args = PyTuple_New(0);
|
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
|
|
|
int i;
|
2009-03-16 15:54:43 +00:00
|
|
|
|
2009-03-18 22:22:58 +00:00
|
|
|
Py_DECREF(props);
|
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
for(i=0; i<PyList_Size(props); i++) {
|
|
|
|
PyObject *py_func_ptr, *py_kw, *py_srna_cobject, *py_ret;
|
2009-03-17 22:27:15 +00:00
|
|
|
item = PyList_GET_ITEM(props, i);
|
2009-03-16 15:54:43 +00:00
|
|
|
|
|
|
|
if (PyArg_ParseTuple(item, "O!O!", &PyCObject_Type, &py_func_ptr, &PyDict_Type, &py_kw)) {
|
|
|
|
|
|
|
|
PyObject *(*pyfunc)(PyObject *, PyObject *, PyObject *);
|
|
|
|
pyfunc = PyCObject_AsVoidPtr(py_func_ptr);
|
|
|
|
py_srna_cobject = PyCObject_FromVoidPtr(ot->srna, NULL);
|
|
|
|
|
|
|
|
py_ret = pyfunc(py_srna_cobject, dummy_args, py_kw);
|
|
|
|
if (py_ret) {
|
|
|
|
Py_DECREF(py_ret);
|
|
|
|
} else {
|
|
|
|
PyErr_Print();
|
|
|
|
PyErr_Clear();
|
|
|
|
}
|
|
|
|
Py_DECREF(py_srna_cobject);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* cant return NULL from here */ // XXX a bit ugly
|
|
|
|
PyErr_Print();
|
|
|
|
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
|
|
|
|
|
|
|
// expect a tuple with a CObject and a dict
|
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
|
|
|
Py_DECREF(dummy_args);
|
|
|
|
} else {
|
|
|
|
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-03-16 15:54:43 +00:00
|
|
|
|
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
char *idname= NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
static struct BPY_class_attr_check pyop_class_attr_values[]= {
|
|
|
|
{PYOP_ATTR_IDNAME, 's', 0, 0},
|
|
|
|
{PYOP_ATTR_UINAME, 's', 0, BPY_CLASS_ATTR_OPTIONAL},
|
|
|
|
{PYOP_ATTR_PROP, 'l', 0, BPY_CLASS_ATTR_OPTIONAL},
|
|
|
|
{PYOP_ATTR_DESCRIPTION, 's', 0, BPY_CLASS_ATTR_NONE_OK},
|
|
|
|
{"exec", 'f', 1, BPY_CLASS_ATTR_OPTIONAL},
|
|
|
|
{"invoke", 'f', 2, BPY_CLASS_ATTR_OPTIONAL},
|
|
|
|
{"poll", 'f', 2, BPY_CLASS_ATTR_OPTIONAL},
|
|
|
|
{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-04-01 12:43:07 +00:00
|
|
|
base_class = PyObject_GetAttrStringArgs(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), 2, "types", "Operator");
|
|
|
|
Py_DECREF(base_class);
|
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-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-16 15:54:43 +00:00
|
|
|
Py_DECREF(item);
|
2009-03-18 22:22:58 +00:00
|
|
|
idname = _PyUnicode_AsString(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
|
|
|
if (WM_operatortype_find(idname)) {
|
2009-03-18 22:22:58 +00:00
|
|
|
PyErr_Format( PyExc_AttributeError, "Operator alredy exists with this name \"%s\"", 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-03-16 15:54:43 +00:00
|
|
|
|
|
|
|
/* If we have properties set, check its a list of dicts */
|
2009-04-01 12:43:07 +00:00
|
|
|
item= PyObject_GetAttrString(py_class, PYOP_ATTR_PROP);
|
2009-03-16 15:54:43 +00:00
|
|
|
if (item) {
|
2009-03-18 22:22:58 +00:00
|
|
|
Py_DECREF(item);
|
2009-03-16 15:54:43 +00:00
|
|
|
for(i=0; i<PyList_Size(item); i++) {
|
|
|
|
PyObject *py_args = PyList_GET_ITEM(item, i);
|
|
|
|
PyObject *py_func_ptr, *py_kw; /* place holders */
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(py_args, "O!O!", &PyCObject_Type, &py_func_ptr, &PyDict_Type, &py_kw)) {
|
|
|
|
PyErr_Format(PyExc_ValueError, "Cant register operator class - %s.properties must contain values from FloatProperty", idname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyErr_Clear();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
if (!(ot= WM_operatortype_find(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;
|
|
|
|
}
|
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
|
|
|
|
|