diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-04-23 10:58:02 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-04-23 10:58:02 +0400 |
commit | 1ed95e0450d9d7e5a98141b209640ffd0283ab9d (patch) | |
tree | 0431979195c7cd2ce86dc9b28e3038311d7b3556 /source | |
parent | d00c3ef2d6339aa01ddbc56bacd20f1ef4473a27 (diff) |
F8Key reloads all python scripts and redraws for quick testing
F7 runs test.py also for testing
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_script/script_edit.c | 30 | ||||
-rw-r--r-- | source/blender/editors/space_script/script_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_script/script_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_ops.c | 3 | ||||
-rw-r--r-- | source/blender/python/BPY_extern.h | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 14 | ||||
-rw-r--r-- | source/creator/creator.c | 2 |
8 files changed, 48 insertions, 9 deletions
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index ce7022d8176..85d4d822c0d 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -2446,6 +2446,9 @@ void ED_keymap_screen(wmWindowManager *wm) WM_keymap_verify_item(keymap, "SCREEN_OT_repeat_last", F4KEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "SCREEN_OT_region_flip", F5KEY, KM_PRESS, 0, 0); WM_keymap_verify_item(keymap, "SCREEN_OT_redo_last", F6KEY, KM_PRESS, 0, 0); + + RNA_string_set(WM_keymap_add_item(keymap, "SCRIPT_OT_python_file_run", F7KEY, KM_PRESS, 0, 0)->ptr, "filename", "test.py"); + WM_keymap_verify_item(keymap, "SCRIPT_OT_python_run_ui_scripts", F8KEY, KM_PRESS, 0, 0); /* files */ WM_keymap_add_item(keymap, "FILE_OT_exec", RETKEY, KM_PRESS, 0, 0); diff --git a/source/blender/editors/space_script/script_edit.c b/source/blender/editors/space_script/script_edit.c index cc8764fd67d..797302a8652 100644 --- a/source/blender/editors/space_script/script_edit.c +++ b/source/blender/editors/space_script/script_edit.c @@ -86,3 +86,33 @@ void SCRIPT_OT_python_file_run(wmOperatorType *ot) RNA_def_string_file_path(ot->srna, "filename", "", 512, "Filename", ""); } +static int run_ui_scripts_exec(bContext *C, wmOperator *op) +{ +#ifndef DISABLE_PYTHON + BPY_run_ui_scripts(C, 1); /* reload */ +#endif + return OPERATOR_FINISHED; +} + +static int run_ui_scripts_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + int ret= run_ui_scripts_exec(C, op); + + if(ret==OPERATOR_FINISHED) + WM_event_add_notifier(C, NC_WINDOW, NULL); + + return ret; +} + + +void SCRIPT_OT_python_run_ui_scripts(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Reload Python Interface"; + ot->idname= "SCRIPT_OT_python_run_ui_scripts"; + + /* api callbacks */ + ot->exec= run_ui_scripts_exec; + ot->invoke= run_ui_scripts_invoke; + ot->poll= ED_operator_areaactive; +} diff --git a/source/blender/editors/space_script/script_intern.h b/source/blender/editors/space_script/script_intern.h index e39dd168e71..59858ee6289 100644 --- a/source/blender/editors/space_script/script_intern.h +++ b/source/blender/editors/space_script/script_intern.h @@ -40,6 +40,7 @@ void script_keymap(struct wmWindowManager *wm); /* script_edit.c */ void SCRIPT_OT_python_file_run(struct wmOperatorType *ot); +void SCRIPT_OT_python_run_ui_scripts(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 index 25aea4a8d65..aa35ba54b7f 100644 --- a/source/blender/editors/space_script/script_ops.c +++ b/source/blender/editors/space_script/script_ops.c @@ -60,6 +60,7 @@ void script_operatortypes(void) { WM_operatortype_append(SCRIPT_OT_python_file_run); + WM_operatortype_append(SCRIPT_OT_python_run_ui_scripts); } void script_keymap(wmWindowManager *wm) @@ -68,5 +69,6 @@ void script_keymap(wmWindowManager *wm) /* TODO - this is just while we have no way to load a text datablock */ RNA_string_set(WM_keymap_add_item(keymap, "SCRIPT_OT_python_file_run", PKEY, KM_PRESS, KM_CTRL|KM_SHIFT|KM_ALT, 0)->ptr, "filename", "test.py"); + WM_keymap_add_item(keymap, "SCRIPT_OT_python_run_ui_scripts", PKEY, KM_PRESS, KM_SHIFT, 0); } diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 8292670de8f..f4c8607d174 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -223,9 +223,6 @@ void view3d_keymap(wmWindowManager *wm) RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_paint_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH); RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_texture_paint_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH); - /* TODO - this is just while we have no way to load a text datablock */ - RNA_string_set(WM_keymap_add_item(keymap, "SCRIPT_OT_python_file_run", PKEY, KM_PRESS, KM_CTRL|KM_SHIFT|KM_ALT, 0)->ptr, "filename", "test.py"); - transform_keymap_for_space(wm, keymap, SPACE_VIEW3D); } diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index d8e4611d9df..ff3e89a6e25 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -99,7 +99,7 @@ extern "C" { /* 2.5 UI Scripts */ int BPY_run_python_script( struct bContext *C, const char *filename, struct Text *text ); // 2.5 working int BPY_run_script_space_draw(struct bContext *C, struct SpaceScript * sc); // 2.5 working - void BPY_run_ui_scripts(struct bContext *C); + void BPY_run_ui_scripts(struct bContext *C, int reload); // int BPY_run_script_space_listener(struct bContext *C, struct SpaceScript * sc, struct ARegion *ar, struct wmNotifier *wmn); // 2.5 working void BPY_update_modules( void ); // XXX - annoying, need this for pointers that get out of date diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index c2773e9e7d1..f37137aa42c 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -347,7 +347,7 @@ int BPY_run_python_script_space(const char *modulename, const char *func) #endif /* XXX this is temporary, need a proper script registration system for 2.5 */ -void BPY_run_ui_scripts(bContext *C) +void BPY_run_ui_scripts(bContext *C, int reload) { #ifdef TIME_REGISTRATION double time = PIL_check_seconds_timer(); @@ -396,13 +396,19 @@ void BPY_run_ui_scripts(bContext *C) mod= PyImport_ImportModuleLevel(path, NULL, NULL, NULL, 0); if (mod) { - Py_DECREF(mod); + if (reload) { + PyObject *mod_orig= mod; + mod= PyImport_ReloadModule(mod); + Py_DECREF(mod_orig); + } } - else { + + if(mod) { + Py_DECREF(mod); /* could be NULL from reloading */ + } else { PyErr_Print(); fprintf(stderr, "unable to import \"%s\" %s/%s\n", path, dirname, de->d_name); } - } } diff --git a/source/creator/creator.c b/source/creator/creator.c index 082f2395b3f..2ac65f7a08a 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -529,7 +529,7 @@ int main(int argc, char **argv) */ BPY_post_start_python(); - BPY_run_ui_scripts(C); + BPY_run_ui_scripts(C, 0); /* dont need to reload the first time */ #endif #ifdef WITH_QUICKTIME |