[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25634] trunk/blender: remove python api cruft from custom operator registration

Campbell Barton ideasman42 at gmail.com
Wed Dec 30 23:51:44 CET 2009


Revision: 25634
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25634
Author:   campbellbarton
Date:     2009-12-30 23:51:44 +0100 (Wed, 30 Dec 2009)

Log Message:
-----------
remove python api cruft from custom operator registration

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy/ops.py
    trunk/blender/source/blender/python/intern/bpy_operator.c
    trunk/blender/source/blender/python/intern/bpy_operator_wrap.c
    trunk/blender/source/blender/python/intern/bpy_operator_wrap.h
    trunk/blender/source/blender/python/intern/bpy_util.c
    trunk/blender/source/blender/python/intern/bpy_util.h

Modified: trunk/blender/release/scripts/modules/bpy/ops.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/ops.py	2009-12-30 22:35:22 UTC (rev 25633)
+++ trunk/blender/release/scripts/modules/bpy/ops.py	2009-12-30 22:51:44 UTC (rev 25634)
@@ -22,7 +22,6 @@
 from _bpy import ops as ops_module
 
 # op_add = ops_module.add
-op_remove = ops_module.remove
 op_dir = ops_module.dir
 op_call = ops_module.call
 op_as_string = ops_module.as_string
@@ -56,9 +55,6 @@
             raise AttributeError(module)
         return bpy_ops_submodule(module)
 
-    def remove(self, pyop):
-        op_remove(pyop)
-
     def __dir__(self):
 
         submodules = set()

Modified: trunk/blender/source/blender/python/intern/bpy_operator.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_operator.c	2009-12-30 22:35:22 UTC (rev 25633)
+++ trunk/blender/source/blender/python/intern/bpy_operator.c	2009-12-30 22:51:44 UTC (rev 25634)
@@ -244,10 +244,7 @@
 	static PyMethodDef pyop_as_string_meth ={"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL};
 	static PyMethodDef pyop_dir_meth =		{"dir", (PyCFunction) pyop_dir, METH_NOARGS, NULL};
 	static PyMethodDef pyop_getrna_meth =	{"get_rna", (PyCFunction) pyop_getrna, METH_O, NULL};
-//	static PyMethodDef pyop_add_meth =		{"add", (PyCFunction) PYOP_wrap_add, METH_O, NULL};
-//	static PyMethodDef pyop_add_macro_meth ={"add_macro", (PyCFunction) PYOP_wrap_add_macro, METH_O, NULL};
 	static PyMethodDef pyop_macro_def_meth ={"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL};
-	static PyMethodDef pyop_remove_meth =	{"remove", (PyCFunction) PYOP_wrap_remove, METH_O, NULL};
 
 	PyObject *submodule = PyModule_New("_bpy.ops");
 	PyDict_SetItemString(PySys_GetObject("modules"), "_bpy.ops", submodule);
@@ -256,10 +253,7 @@
 	PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) );
 	PyModule_AddObject( submodule, "dir",		PyCFunction_New(&pyop_dir_meth,		NULL) );
 	PyModule_AddObject( submodule, "get_rna",	PyCFunction_New(&pyop_getrna_meth,	NULL) );
-//	PyModule_AddObject( submodule, "add",		PyCFunction_New(&pyop_add_meth,		NULL) );
-//	PyModule_AddObject( submodule, "add_macro",	PyCFunction_New(&pyop_add_macro_meth,		NULL) );
 	PyModule_AddObject( submodule, "macro_define",PyCFunction_New(&pyop_macro_def_meth,		NULL) );
-	PyModule_AddObject( submodule, "remove",	PyCFunction_New(&pyop_remove_meth,	NULL) );
 
 	return submodule;
 }

Modified: trunk/blender/source/blender/python/intern/bpy_operator_wrap.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_operator_wrap.c	2009-12-30 22:35:22 UTC (rev 25633)
+++ trunk/blender/source/blender/python/intern/bpy_operator_wrap.c	2009-12-30 22:51:44 UTC (rev 25634)
@@ -42,226 +42,6 @@
 
 #include "../generic/bpy_internal_import.h" // our own imports
 
-#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 */
-
-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}
-};
-
-/* 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.
- * python class instance is stored in op->customdata so exec() can access
- */
-
-
-#define PYOP_EXEC 1
-#define PYOP_INVOKE 2
-#define PYOP_POLL 3
-#define PYOP_DRAW 4
-	
-extern void BPY_update_modules( void ); //XXX temp solution
-
-static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperator *op, wmEvent *event, uiLayout *layout)
-{
-	PyObject *py_class = ot->pyop_data;
-	PyObject *args;
-	PyObject *ret= NULL, *py_class_instance, *item= NULL;
-	int ret_flag= (mode==PYOP_POLL ? 0:OPERATOR_CANCELLED);
-	PointerRNA ptr_context;
-	PointerRNA ptr_operator;
-
-	PyGILState_STATE gilstate;
-
-	bpy_context_set(C, &gilstate);
-
-	args = PyTuple_New(1);
-
-	/* 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));
-
-	py_class_instance = PyObject_Call(py_class, args, NULL);
-	Py_DECREF(args);
-
-	if (py_class_instance==NULL) { /* Initializing the class worked, now run its invoke function */
-		PyErr_Print();
-		PyErr_Clear();
-	}
-	else {
-		RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context);
-
-		if (mode==PYOP_INVOKE) {
-			PointerRNA ptr_event;
-			item= PyObject_GetAttrString(py_class, "invoke");
-			args = PyTuple_New(3);
-
-			RNA_pointer_create(NULL, &RNA_Event, event, &ptr_event);
-
-			// 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));
-			PyTuple_SET_ITEM(args, 2, pyrna_struct_CreatePyObject(&ptr_event));
-		}
-		else if (mode==PYOP_EXEC) {
-			item= PyObject_GetAttrString(py_class, "execute");
-			args = PyTuple_New(2);
-
-			PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
-		}
-		else if (mode==PYOP_POLL) {
-			item= PyObject_GetAttrString(py_class, "poll");
-			args = PyTuple_New(2);
-			PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
-		}
-		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
-		}
-		PyTuple_SET_ITEM(args, 0, py_class_instance);
-
-		ret = PyObject_Call(item, args, NULL);
-
-		Py_DECREF(args);
-		Py_DECREF(item);
-	}
-
-	if (ret == NULL) { /* covers py_class_instance failing too */
-		if(op)
-			BPy_errors_to_report(op->reports);
-	}
-	else {
-		if (mode==PYOP_POLL) {
-			if (PyBool_Check(ret) == 0) {
-				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 */
-			}
-			else {
-				ret_flag= ret==Py_True ? 1:0;
-			}
-		} else if(mode==PYOP_DRAW) {
-			/* pass */
-		} else if (BPY_flag_from_seq(pyop_ret_flags, ret, &ret_flag) == -1) {
-			/* the returned value could not be converted into a flag */
-			PyErr_Format(PyExc_ValueError, "Python operator, error using return value from \"%s\"\n", ot->idname);
-			BPy_errors_to_report(op ? op->reports:NULL);
-			ret_flag = OPERATOR_CANCELLED;
-		}
-		/* 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,
-		 * it can be done with - pyrna_pydict_to_props(op->ptr, kw, "")
-		 */
-
-		Py_DECREF(ret);
-	}
-
-#if 0 /* only for testing */
-
-	/* 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));
-		Py_DECREF(item);
-
-		fprintf(stderr, "%s's %s returned %s\n", class_name, mode == PYOP_EXEC ? "execute" : "invoke", flag_str);
-	}
-#endif
-
-	bpy_context_clear(C, &gilstate);
-
-	return ret_flag;
-}
-
-static int PYTHON_OT_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-	return PYTHON_OT_generic(PYOP_INVOKE, C, op->type, op, event, NULL);
-}
-
-static int PYTHON_OT_execute(bContext *C, wmOperator *op)
-{
-	return PYTHON_OT_generic(PYOP_EXEC, C, op->type, op, NULL, NULL);
-}
-
-static int PYTHON_OT_poll(bContext *C, wmOperatorType *ot)
-{
-	return PYTHON_OT_generic(PYOP_POLL, C, ot, NULL, NULL, NULL);
-}
-
-static void PYTHON_OT_draw(bContext *C, wmOperator *op)
-{
-        PYTHON_OT_generic(PYOP_DRAW, C, op->type, op, NULL, op->layout);
-}
-
-
-
 void operator_wrapper(wmOperatorType *ot, void *userdata)
 {
 	/* take care not to overwrite anything set in
@@ -341,288 +121,6 @@
 	}
 }
 
-
-
-void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
-{
-	PyObject *py_class = (PyObject *)userdata;
-	PyObject *item;
-
-	/* identifiers */
-	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) {
-		ot->name= _PyUnicode_AsString(item);
-		Py_DECREF(item);
-	}
-	else {
-		ot->name= ot->idname;
-		PyErr_Clear();
-	}
-
-	item= PyObject_GetAttrString(py_class, PYOP_ATTR_DESCRIPTION);
-	ot->description= (item && PyUnicode_Check(item)) ? _PyUnicode_AsString(item):"undocumented python operator";
-	Py_XDECREF(item);
-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list