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
path: root/source
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
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')
-rw-r--r--source/blender/editors/space_script/SConscript3
-rw-r--r--source/blender/editors/space_script/script_edit.c89
-rw-r--r--source/blender/editors/space_script/script_intern.h6
-rw-r--r--source/blender/editors/space_script/script_ops.c72
-rw-r--r--source/blender/editors/space_script/space_script.c10
-rw-r--r--source/blender/editors/space_view3d/view3d_ops.c3
-rw-r--r--source/blender/makesrna/intern/rna_access.c10
-rw-r--r--source/blender/python/intern/bpy_interface.c4
-rw-r--r--source/blender/python/intern/bpy_operator.c31
9 files changed, 208 insertions, 20 deletions
diff --git a/source/blender/editors/space_script/SConscript b/source/blender/editors/space_script/SConscript
index 62af4de4caf..8bf0447a6a0 100644
--- a/source/blender/editors/space_script/SConscript
+++ b/source/blender/editors/space_script/SConscript
@@ -5,5 +5,8 @@ sources = env.Glob('*.c')
incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf'
incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include'
+incs += ' ../../makesrna'
+incs += ' ../../python'
+
env.BlenderLib ( 'bf_editors_space_script', sources, Split(incs), [], libtype=['core'], priority=[90] )
diff --git a/source/blender/editors/space_script/script_edit.c b/source/blender/editors/space_script/script_edit.c
new file mode 100644
index 00000000000..64220611d4f
--- /dev/null
+++ b/source/blender/editors/space_script/script_edit.c
@@ -0,0 +1,89 @@
+/**
+ * $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.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <string.h>
+#include <stdio.h>
+
+#include "DNA_space_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_screen.h"
+#include "BKE_utildefines.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "ED_screen.h"
+#include "ED_types.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "script_intern.h" // own include
+
+
+#include "BPY_extern.h" /* BPY_run_python_script */
+
+static int run_pyfile_exec(bContext *C, wmOperator *op)
+{
+ ScrArea *sa= CTX_wm_area(C);
+ ARegion *ar= CTX_wm_region(C);
+
+ char filename[512];
+ RNA_string_get(op->ptr, "filename", filename);
+
+ BPY_run_python_script(C, filename);
+
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_FINISHED;
+}
+
+void ED_SCRIPT_OT_run_pyfile(wmOperatorType *ot)
+{
+
+ /* identifiers */
+ ot->name= "Run python file";
+ ot->idname= "ED_SCRIPT_OT_run_pyfile";
+
+ /* api callbacks */
+ ot->exec= run_pyfile_exec;
+ ot->poll= ED_operator_areaactive;
+
+ RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
+}
diff --git a/source/blender/editors/space_script/script_intern.h b/source/blender/editors/space_script/script_intern.h
index ede9d8468cb..59996495666 100644
--- a/source/blender/editors/space_script/script_intern.h
+++ b/source/blender/editors/space_script/script_intern.h
@@ -34,6 +34,12 @@
/* script_header.c */
void script_header_buttons(const bContext *C, ARegion *ar);
+/* script_ops.c */
+void script_operatortypes(void);
+void script_keymap(struct wmWindowManager *wm);
+
+/* script_edit.c */
+void ED_SCRIPT_OT_run_pyfile(struct wmOperatorType *ot);
#endif /* ED_SCRIPT_INTERN_H */
diff --git a/source/blender/editors/space_script/script_ops.c b/source/blender/editors/space_script/script_ops.c
new file mode 100644
index 00000000000..f6e4fa73cae
--- /dev/null
+++ b/source/blender/editors/space_script/script_ops.c
@@ -0,0 +1,72 @@
+/**
+ * $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.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+#include <math.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_utildefines.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+
+#include "script_intern.h"
+
+
+/* ************************** registration **********************************/
+
+void script_operatortypes(void)
+{
+ WM_operatortype_append(ED_SCRIPT_OT_run_pyfile);
+}
+
+void script_keymap(wmWindowManager *wm)
+{
+ ListBase *keymap= WM_keymap_listbase(wm, "Script", SPACE_SCRIPT, 0);
+
+ /* TODO - this is just while we have no way to load a text datablock */
+ RNA_string_set(WM_keymap_add_item(keymap, "ED_SCRIPT_OT_run_pyfile", PKEY, KM_PRESS, 0, 0)->ptr, "filename", "test.py");
+}
+
diff --git a/source/blender/editors/space_script/space_script.c b/source/blender/editors/space_script/space_script.c
index d9fd4159fb1..52ef016497d 100644
--- a/source/blender/editors/space_script/space_script.c
+++ b/source/blender/editors/space_script/space_script.c
@@ -159,16 +159,6 @@ static void script_main_area_draw(const bContext *C, ARegion *ar)
/* scrollers? */
}
-void script_operatortypes(void)
-{
-
-}
-
-void script_keymap(struct wmWindowManager *wm)
-{
-
-}
-
/* add handlers, stuff you only do once or on area/region changes */
static void script_header_area_init(wmWindowManager *wm, ARegion *ar)
{
diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c
index 158bde600a0..d65d1186efb 100644
--- a/source/blender/editors/space_view3d/view3d_ops.c
+++ b/source/blender/editors/space_view3d/view3d_ops.c
@@ -113,5 +113,8 @@ void view3d_keymap(wmWindowManager *wm)
WM_keymap_add_item(keymap, "ED_VIEW3D_OT_clipping", BKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "ED_VIEW3D_OT_circle_select", CKEY, KM_PRESS, 0, 0);
+ /* TODO - this is just while we have no way to load a text datablock */
+ RNA_string_set(WM_keymap_add_item(keymap, "ED_SCRIPT_OT_run_pyfile", PKEY, KM_PRESS, 0, 0)->ptr, "filename", "test.py");
+
}
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 2c207539c2f..7c2788e8f9b 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -796,6 +796,16 @@ void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *val
IDP_AssignString(idprop, (char*)value);
else if(sprop->set)
sprop->set(ptr, value);
+ else if(!(prop->flag & PROP_NOT_EDITABLE)) {
+ IDPropertyTemplate val;
+ IDProperty *group;
+
+ val.str= value;
+
+ group= rna_idproperties_get(ptr->type, ptr->data, 1);
+ if(group)
+ IDP_AddToGroup(group, IDP_New(IDP_STRING, val, (char*)prop->identifier));
+ }
}
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
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;
}