From de9437e57ab34b7ef3e1f8777e7ac1fa09efa785 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 25 Dec 2008 14:17:54 +0000 Subject: * 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. --- source/blender/editors/space_script/SConscript | 3 + source/blender/editors/space_script/script_edit.c | 89 ++++++++++++++++++++++ .../blender/editors/space_script/script_intern.h | 6 ++ source/blender/editors/space_script/script_ops.c | 72 +++++++++++++++++ source/blender/editors/space_script/space_script.c | 10 --- 5 files changed, 170 insertions(+), 10 deletions(-) create mode 100644 source/blender/editors/space_script/script_edit.c create mode 100644 source/blender/editors/space_script/script_ops.c (limited to 'source/blender/editors/space_script') 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 +#include + +#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 +#include + +#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) { -- cgit v1.2.3