Revision: 18054
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18054
Author:   campbellbarton
Date:     2008-12-25 15:17:54 +0100 (Thu, 25 Dec 2008)

Log Message:
-----------
* 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. 

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/space_script/SConscript
    
branches/blender2.5/blender/source/blender/editors/space_script/script_intern.h
    
branches/blender2.5/blender/source/blender/editors/space_script/space_script.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_ops.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c

Added Paths:
-----------
    
branches/blender2.5/blender/source/blender/editors/space_script/script_edit.c
    branches/blender2.5/blender/source/blender/editors/space_script/script_ops.c

Modified: 
branches/blender2.5/blender/source/blender/editors/space_script/SConscript
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_script/SConscript  
2008-12-25 11:09:25 UTC (rev 18053)
+++ branches/blender2.5/blender/source/blender/editors/space_script/SConscript  
2008-12-25 14:17:54 UTC (rev 18054)
@@ -5,5 +5,8 @@
 
 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] )

Added: 
branches/blender2.5/blender/source/blender/editors/space_script/script_edit.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_script/script_edit.c   
                            (rev 0)
+++ 
branches/blender2.5/blender/source/blender/editors/space_script/script_edit.c   
    2008-12-25 14:17:54 UTC (rev 18054)
@@ -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);
+}

Modified: 
branches/blender2.5/blender/source/blender/editors/space_script/script_intern.h
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_script/script_intern.h 
    2008-12-25 11:09:25 UTC (rev 18053)
+++ 
branches/blender2.5/blender/source/blender/editors/space_script/script_intern.h 
    2008-12-25 14:17:54 UTC (rev 18054)
@@ -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 */
 

Added: 
branches/blender2.5/blender/source/blender/editors/space_script/script_ops.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_script/script_ops.c    
                            (rev 0)
+++ 
branches/blender2.5/blender/source/blender/editors/space_script/script_ops.c    
    2008-12-25 14:17:54 UTC (rev 18054)
@@ -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");
+}
+

Modified: 
branches/blender2.5/blender/source/blender/editors/space_script/space_script.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_script/space_script.c  
    2008-12-25 11:09:25 UTC (rev 18053)
+++ 
branches/blender2.5/blender/source/blender/editors/space_script/space_script.c  
    2008-12-25 14:17:54 UTC (rev 18054)
@@ -159,16 +159,6 @@
        /* 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)
 {

Modified: 
branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_ops.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_ops.c    
    2008-12-25 11:09:25 UTC (rev 18053)
+++ 
branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_ops.c    
    2008-12-25 14:17:54 UTC (rev 18054)
@@ -113,5 +113,8 @@
        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");
+
 }
 

Modified: 
branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c     
2008-12-25 11:09:25 UTC (rev 18053)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c     
2008-12-25 14:17:54 UTC (rev 18054)
@@ -796,6 +796,16 @@
                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)

Modified: 
branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c    
2008-12-25 11:09:25 UTC (rev 18053)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c    
2008-12-25 14:17:54 UTC (rev 18054)
@@ -72,9 +72,9 @@
        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();
        

Modified: 
branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c     
2008-12-25 11:09:25 UTC (rev 18053)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c     
2008-12-25 14:17:54 UTC (rev 18054)
@@ -93,6 +93,7 @@
        wmOperatorType *ot;
 
        int error_val = 0;
+       int totkw;
        const char *arg_name= NULL;
        PyObject *item;
        
@@ -118,6 +119,7 @@
        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 @@
                        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;
+

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to