Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-07-16 11:11:46 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-07-16 11:11:46 +0400
commit88e3e8c1c939ee25f9d86fcfb1d55c0ab415373e (patch)
tree35d757c9eb1cfe1dba541cf31f256247b05b4fa2 /source/blender/python/intern/bpy_operator_wrap.c
parent513dcf7b46eee6ffbb47f6046c4840730e173180 (diff)
- use outliner colors (with subtle stripes) for report so you can see divisions between operators with wrapping.
- added class option for PyOperators __register__ so you can set if py operators are logged in the console. - PyOperators was refcounting in a more readable but incorrect way. in some cases would be possible to crash so better not drop the reference before using the value. - console zoom operator was registering which meant zooming in to see some text would push it away :)
Diffstat (limited to 'source/blender/python/intern/bpy_operator_wrap.c')
-rw-r--r--source/blender/python/intern/bpy_operator_wrap.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c
index f8567414717..33d276ba5b3 100644
--- a/source/blender/python/intern/bpy_operator_wrap.c
+++ b/source/blender/python/intern/bpy_operator_wrap.c
@@ -46,6 +46,7 @@
#define PYOP_ATTR_UINAME "__label__"
#define PYOP_ATTR_IDNAME "__name__" /* use pythons class name */
#define PYOP_ATTR_DESCRIPTION "__doc__" /* use pythons docstring */
+#define PYOP_ATTR_REGISTER "__register__" /* True/False. if this python operator should be registered */
static struct BPY_flag_def pyop_ret_flags[] = {
{"RUNNING_MODAL", OPERATOR_RUNNING_MODAL},
@@ -210,8 +211,8 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve
/* get class name */
item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME);
- Py_DECREF(item);
strcpy(class_name, _PyUnicode_AsString(item));
+ Py_DECREF(item);
fprintf(stderr, "%s's %s returned %s\n", class_name, mode == PYOP_EXEC ? "execute" : "invoke", flag_str);
}
@@ -246,14 +247,14 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
/* identifiers */
item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME);
- Py_DECREF(item);
ot->idname= _PyUnicode_AsString(item);
+ Py_DECREF(item);
item= PyObject_GetAttrString(py_class, PYOP_ATTR_UINAME);
if (item) {
- Py_DECREF(item);
ot->name= _PyUnicode_AsString(item);
+ Py_DECREF(item);
}
else {
ot->name= ot->idname;
@@ -261,8 +262,8 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
}
item= PyObject_GetAttrString(py_class, PYOP_ATTR_DESCRIPTION);
- Py_DECREF(item);
ot->description= (item && PyUnicode_Check(item)) ? _PyUnicode_AsString(item):"";
+ Py_DECREF(item);
/* api callbacks, detailed checks dont on adding */
if (PyObject_HasAttrString(py_class, "invoke"))
@@ -274,13 +275,22 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
ot->pyop_data= userdata;
+ /* flags */
+ item= PyObject_GetAttrString(py_class, PYOP_ATTR_REGISTER);
+ if (item) {
+ ot->flag= PyObject_IsTrue(item)!=0 ? OPTYPE_REGISTER:0;
+ Py_DECREF(item);
+ }
+ else {
+ ot->flag= OPTYPE_REGISTER; /* unspesified, leave on for now to help debug */
+ PyErr_Clear();
+ }
+
props= PyObject_GetAttrString(py_class, PYOP_ATTR_PROP);
if (props) {
PyObject *dummy_args = PyTuple_New(0);
int i;
-
- Py_DECREF(props);
for(i=0; i<PyList_Size(props); i++) {
PyObject *py_func_ptr, *py_kw, *py_srna_cobject, *py_ret;
@@ -310,6 +320,7 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
// expect a tuple with a CObject and a dict
}
Py_DECREF(dummy_args);
+ Py_DECREF(props);
} else {
PyErr_Clear();
}
@@ -340,16 +351,16 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
// in python would be...
//PyObject *optype = PyObject_GetAttrString(PyObject_GetAttrString(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), "types"), "Operator");
base_class = PyObject_GetAttrStringArgs(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), 2, "types", "Operator");
- Py_DECREF(base_class);
if(BPY_class_validate("Operator", py_class, base_class, pyop_class_attr_values, NULL) < 0) {
return NULL; /* BPY_class_validate sets the error */
}
+ Py_DECREF(base_class);
/* class name is used for operator ID - this can be changed later if we want */
item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME);
- Py_DECREF(item);
idname = _PyUnicode_AsString(item);
+ Py_DECREF(item);
/* remove if it already exists */
if ((ot=WM_operatortype_exists(idname))) {
@@ -362,7 +373,6 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
/* If we have properties set, check its a list of dicts */
item= PyObject_GetAttrString(py_class, PYOP_ATTR_PROP);
if (item) {
- Py_DECREF(item);
for(i=0; i<PyList_Size(item); i++) {
PyObject *py_args = PyList_GET_ITEM(item, i);
PyObject *py_func_ptr, *py_kw; /* place holders */
@@ -372,6 +382,7 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
return NULL;
}
}
+ Py_DECREF(item);
}
else {
PyErr_Clear();