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>2008-12-25 17:17:54 +0300
committerCampbell Barton <ideasman42@gmail.com>2008-12-25 17:17:54 +0300
commitde9437e57ab34b7ef3e1f8777e7ac1fa09efa785 (patch)
tree7b7f19a7aacf64b7143d10a7221f8c6692eb6420 /source/blender/python
parentd7e8becefe6772ae635fa77ef4e483bed92a85a5 (diff)
* temporary PKey in the script and 3D view runs "./test.py" (for testing PyOperators that need to run in the user interface context atm)
* added ED_SCRIPT_OT_run_pyfile that takes a filename argument. * RNA_property_string_set didn't add a value to ID props if the prop wasnt there (like ints, floats and bools do) * bpy_operator.c - raise an error when unknown keyword args are passed to any operator . Examples of bpy operator api... bpyoperator.ED_VIEW3D_OT_viewhome(center=1) bpyoperator.ED_SCR_OT_frame_offset(delta=10) bpyoperator.ED_VIEW3D_OT_make_parent(type='OBJECT') At the moment there is no way to stop the operators .invoke() function from running so ED_VIEW3D_OT_make_parent still opens the menu even though it doesn't need to.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_interface.c4
-rw-r--r--source/blender/python/intern/bpy_operator.c31
2 files changed, 25 insertions, 10 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 7c54c728a05..2662890f3c8 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -72,9 +72,9 @@ void BPY_run_python_script( bContext *C, const char *fn )
PyObject *py_dict, *py_result;
char pystring[512];
PyGILState_STATE gilstate;
-
+
/* TODO - look into a better way to run a file */
- sprintf(pystring, "exec(open(r'%s').read())", fn);
+ sprintf(pystring, "exec(open(r'%s').read())", fn);
BPY_start_python();
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index d6bae190dd2..b2cda269751 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -93,6 +93,7 @@ static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObje
wmOperatorType *ot;
int error_val = 0;
+ int totkw;
const char *arg_name= NULL;
PyObject *item;
@@ -118,6 +119,7 @@ static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObje
iterprop= RNA_struct_iterator_property(&ptr);
RNA_property_collection_begin(&ptr, iterprop, &iter);
+ totkw = kw ? PyDict_Size(kw):0;
for(; iter.valid; RNA_property_collection_next(&iter)) {
prop= iter.ptr.data;
@@ -144,26 +146,39 @@ static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObje
error_val= 1;
break;
}
+
+ totkw--;
}
RNA_property_collection_end(&iter);
- if (error_val) {
- if (properties) {
- IDP_FreeProperty(properties);
- MEM_freeN(properties);
+ if (error_val==0 && totkw > 0) { /* some keywords were given that were not used :/ */
+ PyObject *key, *value;
+ Py_ssize_t pos = 0;
+
+ while (PyDict_Next(kw, &pos, &key, &value)) {
+ arg_name= _PyUnicode_AsString(key);
+ if (RNA_struct_find_property(&ptr, arg_name) == NULL) break;
+ arg_name= NULL;
}
- return NULL;
+ PyErr_Format( PyExc_AttributeError, "argument \"%s\" unrecognized", arg_name ? arg_name : "<UNKNOWN>");
+ error_val = 1;
+ }
+
+ if (error_val==0) {
+ WM_operator_name_call(self->C, self->name, WM_OP_DEFAULT, properties);
}
-
-
- WM_operator_name_call(self->C, self->name, WM_OP_DEFAULT, properties);
if (properties) {
IDP_FreeProperty(properties);
MEM_freeN(properties);
}
+
+ if (error_val) {
+ return NULL;
+ }
+
Py_RETURN_NONE;
}