diff options
author | Willian Padovani Germano <wpgermano@gmail.com> | 2006-05-01 02:10:39 +0400 |
---|---|---|
committer | Willian Padovani Germano <wpgermano@gmail.com> | 2006-05-01 02:10:39 +0400 |
commit | 066a2b2ed2194ea72ae90f006f2f2be76014c7ca (patch) | |
tree | 43ceaf8036e4be60572b930580ac92058a089643 /source/blender | |
parent | 89dab4397d9eb2b9970ba28edeaf95c578dcaab4 (diff) |
Small update for pydrivers: force reloading the pydrivers.py Blender
text module when user edits the input text box of any pydriver
(Transform Properties panel, Ipo window).
It's enough to click in and out of a single pydriver's text input box
for the module reloading and also re-evaluation of all pydrivers
available. Maybe this "refreshing" should also be available from a
menu, let's see.
Note for Python fans:
Definitions and redefinitions in a reloaded module are properly handled
in Python, but previously defined data in the module doesn't disappear.
So if you define a function "f" inside a module, import it, then change
the function's name to "g" and reload the module, both "f" and "g" will
be available. This is considered a feature, check reload's documentation:
http://docs.python.org/lib/built-in-funcs.html#l2h-59
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_bad_level_calls.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/bad_level_call_stubs/stubs.c | 1 | ||||
-rw-r--r-- | source/blender/python/BPY_extern.h | 1 | ||||
-rw-r--r-- | source/blender/python/BPY_interface.c | 16 | ||||
-rw-r--r-- | source/blender/src/drawipo.c | 5 |
5 files changed, 25 insertions, 4 deletions
diff --git a/source/blender/blenkernel/BKE_bad_level_calls.h b/source/blender/blenkernel/BKE_bad_level_calls.h index 10248fad220..9e1870ac36f 100644 --- a/source/blender/blenkernel/BKE_bad_level_calls.h +++ b/source/blender/blenkernel/BKE_bad_level_calls.h @@ -67,10 +67,10 @@ void BPY_do_pyscript (struct ID *id, short int event); void BPY_clear_script (struct Script *script); void BPY_free_compiled_text (struct Text *text); void BPY_free_screen_spacehandlers (struct bScreen *sc); -/* ipo.c: */ -float BPY_pydriver_eval(struct IpoDriver *driver); -/* depsgraph.c: */ +/* pydrivers */ struct Object **BPY_pydriver_get_objects(struct IpoDriver *driver); +float BPY_pydriver_eval(struct IpoDriver *driver); +void BPY_pydriver_update(void); /* writefile.c */ struct Oops; diff --git a/source/blender/blenkernel/bad_level_call_stubs/stubs.c b/source/blender/blenkernel/bad_level_call_stubs/stubs.c index 3e858aca631..e4a259c208e 100644 --- a/source/blender/blenkernel/bad_level_call_stubs/stubs.c +++ b/source/blender/blenkernel/bad_level_call_stubs/stubs.c @@ -109,6 +109,7 @@ void BPY_do_pyscript(ID *id, short int event){} void BPY_clear_script(Script *script){} void BPY_free_compiled_text(struct Text *text){} void BPY_free_screen_spacehandlers (struct bScreen *sc){} +void BPY_pydriver_update(void){} float BPY_pydriver_eval(struct IpoDriver *driver) { return 0; diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index cc187ea3a0d..b2c6287f9b3 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -81,6 +81,7 @@ extern "C" { int BPY_do_spacehandlers(struct ScrArea *sa, unsigned short event, unsigned short space_event); + void BPY_pydriver_update(void); float BPY_pydriver_eval(struct IpoDriver *driver); struct Object **BPY_pydriver_get_objects(struct IpoDriver *driver); diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 6a79e673345..80c4df81bd4 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -1021,6 +1021,7 @@ static float pydriver_error(IpoDriver *driver) { bpy_pydriver_freeList(); if (bpy_pydriver_Dict) { /* free the global dict used by pydrivers */ + PyDict_Clear(bpy_pydriver_Dict); Py_DECREF(bpy_pydriver_Dict); bpy_pydriver_Dict = NULL; } @@ -1034,6 +1035,21 @@ static float pydriver_error(IpoDriver *driver) { return 0.0f; } +/* Update function, it gets rid of pydrivers global dictionary, forcing + * BPY_pydriver_eval to recreate it. This function is used to force + * reloading the Blender text module "pydrivers.py", if available, so + * updates in it reach pydriver evaluation. */ +void BPY_pydriver_update(void) +{ + if (bpy_pydriver_Dict) { /* free the global dict used by pydrivers */ + PyDict_Clear(bpy_pydriver_Dict); + Py_DECREF(bpy_pydriver_Dict); + bpy_pydriver_Dict = NULL; + } + + return; +} + /* for depsgraph.c, runs py expr once to collect all refs. made * to objects (self refs. to the object that owns the py driver * are not allowed). */ diff --git a/source/blender/src/drawipo.c b/source/blender/src/drawipo.c index ffbc8a67f9d..8c3cd7c1a53 100644 --- a/source/blender/src/drawipo.c +++ b/source/blender/src/drawipo.c @@ -1759,7 +1759,10 @@ void do_ipobuts(unsigned short event) if(ei) { if(ei->icu->driver) { if (ei->icu->driver->type == IPO_DRIVER_TYPE_PYTHON) { - /* eval user's expression once for validity */ + /* first del pydriver's global dict, just in case + * an available pydrivers.py module needs to be reloaded */ + BPY_pydriver_update(); + /* eval user's expression once for validity; update DAG */ BPY_pydriver_eval(ei->icu->driver); DAG_scene_sort(G.scene); } |