diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-07-19 17:32:02 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-07-19 17:32:02 +0400 |
commit | d9a7e5144f816bfa15687e5bd9d55e95f69c0269 (patch) | |
tree | ce6119020f1c1b4ae19b7dba1aac3f832ff46083 /source/blender/python/intern/bpy_operator_wrap.c | |
parent | 8efdb04817b53562b9d8092a5d973981f78703c9 (diff) |
Python operators
- simplified C operator API bpy.__ops__ since its wrapped by python now.
- needs the class to have an __idname__ rather then __name__ (like menus, headers)
- convert python names "console.exec" into blender names "CONSOLE_OT_exec" when registering (store the blender name as class.__idname_bl__, users scripters wont notice)
- bpy.props.props ???, removed
Diffstat (limited to 'source/blender/python/intern/bpy_operator_wrap.c')
-rw-r--r-- | source/blender/python/intern/bpy_operator_wrap.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index 9f4137a15c0..02d721739e7 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -44,7 +44,8 @@ #define PYOP_ATTR_PROP "__props__" #define PYOP_ATTR_UINAME "__label__" -#define PYOP_ATTR_IDNAME "__name__" /* use pythons class name */ +#define PYOP_ATTR_IDNAME "__idname__" /* the name given by python */ +#define PYOP_ATTR_IDNAME_BL "__idname_bl__" /* our own name converted into blender syntax, users wont see this */ #define PYOP_ATTR_DESCRIPTION "__doc__" /* use pythons docstring */ #define PYOP_ATTR_REGISTER "__register__" /* True/False. if this python operator should be registered */ @@ -249,10 +250,9 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata) PyObject *props, *item; /* identifiers */ - item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME); + item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME_BL); ot->idname= _PyUnicode_AsString(item); Py_DECREF(item); - item= PyObject_GetAttrString(py_class, PYOP_ATTR_UINAME); if (item) { @@ -338,16 +338,17 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class) char *idname= NULL; + char idname_bl[OP_MAX_TYPENAME]; /* converted to blender syntax */ 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}, - {"execute", 'f', 2, BPY_CLASS_ATTR_OPTIONAL}, - {"invoke", 'f', 3, BPY_CLASS_ATTR_OPTIONAL}, - {"poll", 'f', 2, BPY_CLASS_ATTR_OPTIONAL}, + {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_PROP, 'l', -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}, {NULL, 0, 0, 0} }; @@ -363,7 +364,18 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class) /* class name is used for operator ID - this can be changed later if we want */ item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME); idname = _PyUnicode_AsString(item); + + + /* 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); Py_DECREF(item); + /* end annoying conversion! */ + /* remove if it already exists */ if ((ot=WM_operatortype_exists(idname))) { |