diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-11-20 18:01:09 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-11-20 18:01:09 +0300 |
commit | 854cc87a80ef8526416b931ef735bc6bacb6ede5 (patch) | |
tree | 23daca51096463b272c7669efb0cf06d26272935 /source/blender/python/generic | |
parent | 320cc0f12a186292078e174f2862a6539ac4d258 (diff) |
option to have scripts run on startup for per blendfile UI's
Diffstat (limited to 'source/blender/python/generic')
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.c | 45 | ||||
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.h | 5 |
2 files changed, 31 insertions, 19 deletions
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index 05c846b16f5..d3b8b19693f 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -54,12 +54,35 @@ void bpy_import_main_set(struct Main *maggie) bpy_import_main= maggie; } +PyObject *bpy_text_import( Text *text ) +{ + char *buf = NULL; + char modulename[24]; + int len; -PyObject *bpy_text_import( char *name, int *found ) + if( !text->compiled ) { + buf = txt_to_buf( text ); + text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input ); + MEM_freeN( buf ); + + if( PyErr_Occurred( ) ) { + PyErr_Print( ); + PyErr_Clear( ); + PySys_SetObject("last_traceback", NULL); + free_compiled_text( text ); + return NULL; + } + } + + len= strlen(text->id.name+2) - 3; + strncpy(modulename, text->id.name+2, len); + return PyImport_ExecCodeModule(modulename, text->compiled); +} + +PyObject *bpy_text_import_name( char *name, int *found ) { Text *text; char txtname[22]; /* 21+NULL */ - char *buf = NULL; int namelen = strlen( name ); //XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main; Main *maggie= bpy_import_main; @@ -86,21 +109,7 @@ PyObject *bpy_text_import( char *name, int *found ) else *found = 1; - if( !text->compiled ) { - buf = txt_to_buf( text ); - text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input ); - MEM_freeN( buf ); - - if( PyErr_Occurred( ) ) { - PyErr_Print( ); - PyErr_Clear( ); - PySys_SetObject("last_traceback", NULL); - free_compiled_text( text ); - return NULL; - } - } - - return PyImport_ExecCodeModule( name, text->compiled ); + return bpy_text_import(text); } @@ -195,7 +204,7 @@ static PyObject *blender_import( PyObject * self, PyObject * args, PyObject * k PyErr_Fetch( &exception, &err, &tb ); /* get the python error incase we cant import as blender text either */ /* importing from existing modules failed, see if we have this module as blender text */ - newmodule = bpy_text_import( name, &found ); + newmodule = bpy_text_import_name( name, &found ); if( newmodule ) {/* found module as blender text, ignore above exception */ PyErr_Clear( ); diff --git a/source/blender/python/generic/bpy_internal_import.h b/source/blender/python/generic/bpy_internal_import.h index 4e761fe8da0..0eee6361aab 100644 --- a/source/blender/python/generic/bpy_internal_import.h +++ b/source/blender/python/generic/bpy_internal_import.h @@ -44,7 +44,10 @@ #include "compile.h" /* for the PyCodeObject */ #include "eval.h" /* for PyEval_EvalCode */ -PyObject* bpy_text_import( char *name, int *found ); +struct Text; + +PyObject* bpy_text_import( struct Text *text ); +PyObject* bpy_text_import_name( char *name, int *found ); PyObject* bpy_text_reimport( PyObject *module, int *found ); /* void bpy_text_clear_modules( int clear_all );*/ /* Clear user modules */ extern PyMethodDef bpy_import_meth[]; |