ok, apparently didn't commit this either. apparently includes a merge with trunk/2.5 at r24811 I thought I'd committed but did not, yeek.
This commit is contained in:
@@ -72,74 +72,73 @@ extern "C" {
|
||||
|
||||
This is necassary to avoid blender buttons storing invalid pointers to freed
|
||||
python data.*/
|
||||
void BPy_Set_DrawButtonsList(void *list);
|
||||
void BPy_Free_DrawButtonsList(void);
|
||||
|
||||
// void BPy_Set_DrawButtonsList(void *list);
|
||||
// void BPy_Free_DrawButtonsList(void);
|
||||
//
|
||||
void BPY_pyconstraint_eval(struct bPythonConstraint *con, struct bConstraintOb *cob, struct ListBase *targets);
|
||||
void BPY_pyconstraint_settings(void *arg1, void *arg2);
|
||||
// void BPY_pyconstraint_settings(void *arg1, void *arg2);
|
||||
void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTarget *ct);
|
||||
void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con);
|
||||
int BPY_is_pyconstraint(struct Text *text);
|
||||
void BPY_free_pyconstraint_links(struct Text *text);
|
||||
|
||||
// void BPY_free_pyconstraint_links(struct Text *text);
|
||||
//
|
||||
void BPY_start_python( int argc, char **argv );
|
||||
void BPY_end_python( void );
|
||||
void BPY_post_start_python( void );
|
||||
void init_syspath( int first_time );
|
||||
void syspath_append( char *dir );
|
||||
void BPY_rebuild_syspath( void );
|
||||
int BPY_path_update( void );
|
||||
|
||||
int BPY_Err_getLinenumber( void );
|
||||
const char *BPY_Err_getFilename( void );
|
||||
|
||||
int BPY_txt_do_python_Text( struct Text *text );
|
||||
int BPY_menu_do_python( short menutype, int event );
|
||||
int BPY_menu_do_shortcut( short menutype, unsigned short key, unsigned short modifiers );
|
||||
int BPY_menu_invoke( struct BPyMenu *pym, short menutype );
|
||||
// void init_syspath( int first_time );
|
||||
// void syspath_append( char *dir );
|
||||
// void BPY_rebuild_syspath( void );
|
||||
// int BPY_path_update( void );
|
||||
//
|
||||
// int BPY_Err_getLinenumber( void );
|
||||
// const char *BPY_Err_getFilename( void );
|
||||
//
|
||||
// int BPY_txt_do_python_Text( struct Text *text );
|
||||
// int BPY_menu_do_python( short menutype, int event );
|
||||
// int BPY_menu_do_shortcut( short menutype, unsigned short key, unsigned short modifiers );
|
||||
// int BPY_menu_invoke( struct BPyMenu *pym, short menutype );
|
||||
|
||||
/* 2.5 UI Scripts */
|
||||
int BPY_run_python_script( struct bContext *C, const char *filename, struct Text *text, struct ReportList *reports ); // 2.5 working
|
||||
int BPY_run_script_space_draw(const struct bContext *C, struct SpaceScript * sc); // 2.5 working
|
||||
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
|
||||
|
||||
//
|
||||
int BPY_context_get(struct bContext *C, const char *member, struct bContextDataResult *result);
|
||||
|
||||
int BPY_run_script(struct Script *script);
|
||||
//
|
||||
// int BPY_run_script(struct Script *script);
|
||||
void BPY_free_compiled_text( struct Text *text );
|
||||
|
||||
int BPY_has_onload_script( void );
|
||||
|
||||
int BPY_is_spacehandler(struct Text *text, char spacetype);
|
||||
int BPY_del_spacehandler(struct Text *text, struct ScrArea *sa);
|
||||
int BPY_add_spacehandler(struct Text *txt, struct ScrArea *sa,char spacetype);
|
||||
int BPY_has_spacehandler(struct Text *text, struct ScrArea *sa);
|
||||
void BPY_screen_free_spacehandlers(struct bScreen *sc);
|
||||
int BPY_do_spacehandlers(struct ScrArea *sa, unsigned short event,
|
||||
short eventValue, unsigned short space_event);
|
||||
|
||||
void BPY_pydriver_update(void);
|
||||
//
|
||||
// int BPY_has_onload_script( void );
|
||||
//
|
||||
// int BPY_is_spacehandler(struct Text *text, char spacetype);
|
||||
// int BPY_del_spacehandler(struct Text *text, struct ScrArea *sa);
|
||||
// int BPY_add_spacehandler(struct Text *txt, struct ScrArea *sa,char spacetype);
|
||||
// int BPY_has_spacehandler(struct Text *text, struct ScrArea *sa);
|
||||
// void BPY_screen_free_spacehandlers(struct bScreen *sc);
|
||||
// int BPY_do_spacehandlers(struct ScrArea *sa, unsigned short event,
|
||||
// short eventValue, unsigned short space_event);
|
||||
//
|
||||
// void BPY_pydriver_update(void);
|
||||
float BPY_pydriver_eval(struct ChannelDriver *driver);
|
||||
|
||||
//
|
||||
int BPY_button_eval(struct bContext *C, char *expr, double *value);
|
||||
|
||||
/* format importer hook */
|
||||
int BPY_call_importloader( char *name );
|
||||
|
||||
void BPY_spacescript_do_pywin_draw( struct SpaceScript *sc );
|
||||
void BPY_spacescript_do_pywin_event( struct SpaceScript *sc,
|
||||
unsigned short event, short val, char ascii );
|
||||
void BPY_clear_script( struct Script *script );
|
||||
void BPY_free_finished_script( struct Script *script );
|
||||
void BPY_scripts_clear_pyobjects( void );
|
||||
|
||||
void error_pyscript( void );
|
||||
void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
|
||||
|
||||
//
|
||||
// void BPY_spacescript_do_pywin_draw( struct SpaceScript *sc );
|
||||
// void BPY_spacescript_do_pywin_event( struct SpaceScript *sc,
|
||||
// unsigned short event, short val, char ascii );
|
||||
// void BPY_clear_script( struct Script *script );
|
||||
// void BPY_free_finished_script( struct Script *script );
|
||||
// void BPY_scripts_clear_pyobjects( void );
|
||||
//
|
||||
// void error_pyscript( void );
|
||||
// void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
|
||||
void BPY_set_context(struct bContext *C);
|
||||
/* void BPY_Err_Handle(struct Text *text); */
|
||||
/* int BPY_spacetext_is_pywin(struct SpaceText *st); */
|
||||
void BPY_load_user_modules(struct bContext *C);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -45,7 +45,7 @@
|
||||
#include "BLI_math.h"
|
||||
|
||||
#define SWAP_FLOAT(a,b,tmp) tmp=a; a=b; b=tmp
|
||||
#define eul 0.000001
|
||||
#define eps 0.000001
|
||||
|
||||
/*-- forward declarations -- */
|
||||
static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq );
|
||||
@@ -252,18 +252,18 @@ static PyObject *M_Geometry_LineIntersect2D( PyObject * self, PyObject * args )
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
/* Make sure the hoz/vert line comes first. */
|
||||
if (fabs(b1x - b2x) < eul || fabs(b1y - b2y) < eul) {
|
||||
if (fabs(b1x - b2x) < eps || fabs(b1y - b2y) < eps) {
|
||||
SWAP_FLOAT(a1x, b1x, xi); /*abuse xi*/
|
||||
SWAP_FLOAT(a1y, b1y, xi);
|
||||
SWAP_FLOAT(a2x, b2x, xi);
|
||||
SWAP_FLOAT(a2y, b2y, xi);
|
||||
}
|
||||
|
||||
if (fabs(a1x-a2x) < eul) { /* verticle line */
|
||||
if (fabs(b1x-b2x) < eul){ /*verticle second line */
|
||||
if (fabs(a1x-a2x) < eps) { /* verticle line */
|
||||
if (fabs(b1x-b2x) < eps){ /*verticle second line */
|
||||
Py_RETURN_NONE; /* 2 verticle lines dont intersect. */
|
||||
}
|
||||
else if (fabs(b1y-b2y) < eul) {
|
||||
else if (fabs(b1y-b2y) < eps) {
|
||||
/*X of vert, Y of hoz. no calculation needed */
|
||||
newvec[0]= a1x;
|
||||
newvec[1]= b1y;
|
||||
@@ -280,8 +280,8 @@ static PyObject *M_Geometry_LineIntersect2D( PyObject * self, PyObject * args )
|
||||
newvec[0]= a1x;
|
||||
newvec[1]= yi;
|
||||
return newVectorObject(newvec, 2, Py_NEW, NULL);
|
||||
} else if (fabs(a2y-a1y) < eul) { /* hoz line1 */
|
||||
if (fabs(b2y-b1y) < eul) { /*hoz line2*/
|
||||
} else if (fabs(a2y-a1y) < eps) { /* hoz line1 */
|
||||
if (fabs(b2y-b1y) < eps) { /*hoz line2*/
|
||||
Py_RETURN_NONE; /*2 hoz lines dont intersect*/
|
||||
}
|
||||
|
||||
|
||||
1026
source/blender/python/generic/IDProp.c
Normal file
1026
source/blender/python/generic/IDProp.c
Normal file
File diff suppressed because it is too large
Load Diff
64
source/blender/python/generic/IDProp.h
Normal file
64
source/blender/python/generic/IDProp.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* $Id: IDProp.h
|
||||
*
|
||||
* ***** 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.
|
||||
*
|
||||
* Contributor(s): Joseph Eagar, Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
struct ID;
|
||||
struct IDProperty;
|
||||
struct BPy_IDGroup_Iter;
|
||||
|
||||
typedef struct BPy_IDProperty {
|
||||
PyObject_VAR_HEAD
|
||||
struct ID *id;
|
||||
struct IDProperty *prop, *parent;
|
||||
PyObject *data_wrap;
|
||||
} BPy_IDProperty;
|
||||
|
||||
typedef struct BPy_IDArray {
|
||||
PyObject_VAR_HEAD
|
||||
struct ID *id;
|
||||
struct IDProperty *prop;
|
||||
} BPy_IDArray;
|
||||
|
||||
typedef struct BPy_IDGroup_Iter {
|
||||
PyObject_VAR_HEAD
|
||||
BPy_IDProperty *group;
|
||||
struct IDProperty *cur;
|
||||
int mode;
|
||||
} BPy_IDGroup_Iter;
|
||||
|
||||
PyObject *BPy_Wrap_IDProperty(struct ID *id, struct IDProperty *prop, struct IDProperty *parent);
|
||||
PyObject *BPy_Wrap_GetKeys(IDProperty *prop);
|
||||
PyObject *BPy_Wrap_GetValues(ID *id, IDProperty *prop);
|
||||
PyObject *BPy_Wrap_GetItems(ID *id, IDProperty *prop);
|
||||
int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val);
|
||||
|
||||
|
||||
PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop );
|
||||
char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObject *ob);
|
||||
|
||||
void IDProp_Init_Types(void);
|
||||
|
||||
#define IDPROP_ITER_KEYS 0
|
||||
#define IDPROP_ITER_ITEMS 1
|
||||
@@ -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( );
|
||||
|
||||
@@ -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[];
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
#include "BKE_text.h"
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_main.h"
|
||||
|
||||
#include "BPY_extern.h"
|
||||
|
||||
@@ -74,6 +75,7 @@
|
||||
#include "../generic/Mathutils.h"
|
||||
#include "../generic/Geometry.h"
|
||||
#include "../generic/BGL.h"
|
||||
#include "../generic/IDProp.h"
|
||||
|
||||
|
||||
/* for internal use, when starting and ending python scripts */
|
||||
@@ -176,7 +178,7 @@ static BPy_StructRNA *bpy_context_module= NULL; /* for fast access */
|
||||
static void bpy_init_modules( void )
|
||||
{
|
||||
PyObject *mod;
|
||||
|
||||
|
||||
/* Needs to be first since this dir is needed for future modules */
|
||||
char *modpath= BLI_gethome_folder("scripts/modules", BLI_GETHOME_ALL);
|
||||
if(modpath) {
|
||||
@@ -186,10 +188,17 @@ static void bpy_init_modules( void )
|
||||
Py_DECREF(py_modpath);
|
||||
}
|
||||
|
||||
mod = PyModule_New("bpy");
|
||||
/* stand alone utility modules not related to blender directly */
|
||||
Geometry_Init();
|
||||
Mathutils_Init();
|
||||
BGL_Init();
|
||||
IDProp_Init_Types();
|
||||
|
||||
|
||||
mod = PyModule_New("_bpy");
|
||||
|
||||
/* add the module so we can import it */
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), "bpy", mod);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), "_bpy", mod);
|
||||
Py_DECREF(mod);
|
||||
|
||||
/* run first, initializes rna types */
|
||||
@@ -201,7 +210,7 @@ static void bpy_init_modules( void )
|
||||
bpy_import_test("bpy_types");
|
||||
/* PyModule_AddObject( mod, "doc", BPY_rna_doc() ); */
|
||||
PyModule_AddObject( mod, "props", BPY_rna_props() );
|
||||
PyModule_AddObject( mod, "__ops__", BPY_operator_module() ); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
|
||||
PyModule_AddObject( mod, "ops", BPY_operator_module() ); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
|
||||
PyModule_AddObject( mod, "ui", BPY_ui_module() ); // XXX very experimental, consider this a test, especially PyCObject is not meant to be permanent
|
||||
|
||||
|
||||
@@ -214,16 +223,8 @@ static void bpy_init_modules( void )
|
||||
PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module);
|
||||
}
|
||||
|
||||
/* stand alone utility modules not related to blender directly */
|
||||
Geometry_Init();
|
||||
Mathutils_Init();
|
||||
BGL_Init();
|
||||
|
||||
/* add our own modules dir */
|
||||
{
|
||||
bpy_import_test("bpy_ops"); /* adds its self to bpy.ops */
|
||||
bpy_import_test("bpy_utils"); /* adds its self to bpy.sys */
|
||||
}
|
||||
/* add our own modules dir, this is a python package */
|
||||
bpy_import_test("bpy");
|
||||
}
|
||||
|
||||
void BPY_update_modules( void )
|
||||
@@ -242,34 +243,24 @@ void BPY_update_modules( void )
|
||||
/*****************************************************************************
|
||||
* Description: This function creates a new Python dictionary object.
|
||||
*****************************************************************************/
|
||||
static PyObject *CreateGlobalDictionary( bContext *C )
|
||||
static PyObject *CreateGlobalDictionary( bContext *C, const char *filename )
|
||||
{
|
||||
PyObject *mod;
|
||||
PyObject *item;
|
||||
PyObject *dict = PyDict_New( );
|
||||
PyObject *item = PyUnicode_FromString( "__main__" );
|
||||
PyDict_SetItemString( dict, "__builtins__", PyEval_GetBuiltins( ) );
|
||||
|
||||
item = PyUnicode_FromString( "__main__" );
|
||||
PyDict_SetItemString( dict, "__name__", item );
|
||||
Py_DECREF(item);
|
||||
|
||||
// XXX - put somewhere more logical
|
||||
{
|
||||
PyMethodDef *ml;
|
||||
static PyMethodDef bpy_prop_meths[] = {
|
||||
{"FloatProperty", (PyCFunction)BPy_FloatProperty, METH_VARARGS|METH_KEYWORDS, ""},
|
||||
{"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, ""},
|
||||
{"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, ""},
|
||||
{"StringProperty", (PyCFunction)BPy_StringProperty, METH_VARARGS|METH_KEYWORDS, ""},
|
||||
{"EnumProperty", (PyCFunction)BPy_EnumProperty, METH_VARARGS|METH_KEYWORDS, ""},
|
||||
{"PointerProperty", (PyCFunction)BPy_PointerProperty, METH_VARARGS|METH_KEYWORDS, ""},
|
||||
{"CollectionProperty", (PyCFunction)BPy_CollectionProperty, METH_VARARGS|METH_KEYWORDS, ""},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
for(ml = bpy_prop_meths; ml->ml_name; ml++) {
|
||||
PyDict_SetItemString( dict, ml->ml_name, PyCFunction_New(ml, NULL));
|
||||
}
|
||||
/* __file__ only for nice UI'ness */
|
||||
if(filename) {
|
||||
PyObject *item = PyUnicode_FromString( filename );
|
||||
PyDict_SetItemString( dict, "__file__", item );
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
|
||||
/* add bpy to global namespace */
|
||||
mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
|
||||
PyDict_SetItemString( dict, "bpy", mod );
|
||||
@@ -303,6 +294,13 @@ void BPY_start_python_path(void)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BPY_set_context(bContext *C)
|
||||
{
|
||||
BPy_SetContext(C);
|
||||
}
|
||||
|
||||
/* call BPY_set_context first */
|
||||
void BPY_start_python( int argc, char **argv )
|
||||
{
|
||||
PyThreadState *py_tstate = NULL;
|
||||
@@ -341,11 +339,6 @@ void BPY_start_python( int argc, char **argv )
|
||||
PyObject *d = PyEval_GetBuiltins( );
|
||||
PyDict_SetItemString(d, "reload", item=PyCFunction_New(bpy_reload_meth, NULL)); Py_DECREF(item);
|
||||
PyDict_SetItemString(d, "__import__", item=PyCFunction_New(bpy_import_meth, NULL)); Py_DECREF(item);
|
||||
|
||||
/* a bit nasty but this prevents help() and input() from locking blender
|
||||
* Ideally we could have some way for the console to replace sys.stdin but
|
||||
* python would lock blender while waiting for a return value, not easy :| */
|
||||
PySys_SetObject("stdin", Py_None);
|
||||
}
|
||||
|
||||
pyrna_alloc_types();
|
||||
@@ -400,7 +393,7 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
py_dict = CreateGlobalDictionary(C);
|
||||
py_dict = CreateGlobalDictionary(C, text?text->id.name+2:fn);
|
||||
|
||||
if (text) {
|
||||
|
||||
@@ -420,24 +413,32 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
|
||||
py_result = PyEval_EvalCode( text->compiled, py_dict, py_dict );
|
||||
|
||||
} else {
|
||||
#if 0
|
||||
char *pystring;
|
||||
pystring= malloc(strlen(fn) + 32);
|
||||
pystring[0]= '\0';
|
||||
sprintf(pystring, "exec(open(r'%s').read())", fn);
|
||||
py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict );
|
||||
free(pystring);
|
||||
#else
|
||||
FILE *fp= fopen(fn, "r");
|
||||
if(fp) {
|
||||
#ifdef _WIN32
|
||||
/* Previously we used PyRun_File to run directly the code on a FILE
|
||||
* object, but as written in the Python/C API Ref Manual, chapter 2,
|
||||
* 'FILE structs for different C libraries can be different and
|
||||
* incompatible'.
|
||||
* So now we load the script file data to a buffer */
|
||||
char *pystring;
|
||||
|
||||
fclose(fp);
|
||||
|
||||
pystring= malloc(strlen(fn) + 32);
|
||||
pystring[0]= '\0';
|
||||
sprintf(pystring, "exec(open(r'%s').read())", fn);
|
||||
py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict );
|
||||
free(pystring);
|
||||
#else
|
||||
py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);
|
||||
fclose(fp);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_SystemError, "Python file \"%s\" could not be opened: %s", fn, strerror(errno));
|
||||
py_result= NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!py_result) {
|
||||
@@ -595,117 +596,6 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
|
||||
#include "PIL_time.h"
|
||||
#endif
|
||||
|
||||
/* for use by BPY_run_ui_scripts only */
|
||||
static int bpy_import_module(char *modname, int reload)
|
||||
{
|
||||
PyObject *mod= PyImport_ImportModuleLevel(modname, NULL, NULL, NULL, 0);
|
||||
if (mod) {
|
||||
if (reload) {
|
||||
PyObject *mod_orig= mod;
|
||||
mod= PyImport_ReloadModule(mod);
|
||||
Py_DECREF(mod_orig);
|
||||
}
|
||||
}
|
||||
|
||||
if(mod) {
|
||||
Py_DECREF(mod); /* could be NULL from reloading */
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX this is temporary, need a proper script registration system for 2.5 */
|
||||
void BPY_run_ui_scripts(bContext *C, int reload)
|
||||
{
|
||||
#ifdef TIME_REGISTRATION
|
||||
double time = PIL_check_seconds_timer();
|
||||
#endif
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
char *file_extension;
|
||||
char *dirname;
|
||||
char path[FILE_MAX];
|
||||
char *dirs[] = {"scripts/ui", "scripts/op", "scripts/io", NULL};
|
||||
int path_flags[] = {BLI_GETHOME_LOCAL|BLI_GETHOME_SYSTEM, BLI_GETHOME_USER}; /* SYSTEM / NON-SYSTEM */
|
||||
int a, err, flag_iter;
|
||||
|
||||
PyGILState_STATE gilstate;
|
||||
PyObject *sys_path;
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
sys_path= PySys_GetObject("path"); /* borrow */
|
||||
PyList_Insert(sys_path, 0, Py_None); /* place holder, resizes the list */
|
||||
|
||||
/* Scan system scripts first, then local/user */
|
||||
for(flag_iter=0; flag_iter < sizeof(path_flags)/sizeof(int); flag_iter++) {
|
||||
|
||||
for(a=0; dirs[a]; a++) {
|
||||
dirname= BLI_gethome_folder(dirs[a], path_flags[flag_iter]);
|
||||
|
||||
if(!dirname)
|
||||
continue;
|
||||
|
||||
dir = opendir(dirname);
|
||||
|
||||
if(!dir)
|
||||
continue;
|
||||
|
||||
/* set the first dir in the sys.path for fast importing of modules */
|
||||
PyList_SetItem(sys_path, 0, PyUnicode_FromString(dirname)); /* steals the ref */
|
||||
|
||||
while((de = readdir(dir)) != NULL) {
|
||||
/* We could stat the file but easier just to let python
|
||||
* import it and complain if theres a problem */
|
||||
err = 0;
|
||||
|
||||
if (de->d_name[0] == '.') {
|
||||
/* do nothing, probably .svn */
|
||||
}
|
||||
else if ((file_extension = strstr(de->d_name, ".py"))) {
|
||||
/* normal py files? */
|
||||
if(file_extension && file_extension[3] == '\0') {
|
||||
de->d_name[(file_extension - de->d_name)] = '\0';
|
||||
err= bpy_import_module(de->d_name, reload);
|
||||
}
|
||||
}
|
||||
#ifndef __linux__
|
||||
else if( BLI_join_dirfile(path, dirname, de->d_name), S_ISDIR(BLI_exist(path))) {
|
||||
#else
|
||||
else if(de->d_type==DT_DIR) {
|
||||
BLI_join_dirfile(path, dirname, de->d_name);
|
||||
#endif
|
||||
/* support packages */
|
||||
BLI_join_dirfile(path, path, "__init__.py");
|
||||
|
||||
if(BLI_exists(path)) {
|
||||
err= bpy_import_module(de->d_name, reload);
|
||||
}
|
||||
}
|
||||
|
||||
if(err==-1) {
|
||||
BPy_errors_to_report(NULL);
|
||||
fprintf(stderr, "unable to import %s/%s\n", dirname, de->d_name);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
}
|
||||
|
||||
PyList_SetSlice(sys_path, 0, 1, NULL); /* remove the first item */
|
||||
|
||||
bpy_context_clear(C, &gilstate);
|
||||
|
||||
#ifdef TIME_REGISTRATION
|
||||
printf("script time %f\n", (PIL_check_seconds_timer()-time));
|
||||
#endif
|
||||
|
||||
/* reset the timer so as not to take loading into the stats */
|
||||
bpy_timer_count = 0;
|
||||
}
|
||||
|
||||
/* ****************************************** */
|
||||
/* Drivers - PyExpression Evaluation */
|
||||
|
||||
@@ -912,7 +802,7 @@ int BPY_button_eval(bContext *C, char *expr, double *value)
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
dict= CreateGlobalDictionary(C);
|
||||
dict= CreateGlobalDictionary(C, NULL);
|
||||
|
||||
/* import some modules: builtins,math*/
|
||||
PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins());
|
||||
@@ -968,7 +858,28 @@ int BPY_button_eval(bContext *C, char *expr, double *value)
|
||||
return error_ret;
|
||||
}
|
||||
|
||||
void BPY_load_user_modules(bContext *C)
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
Text *text;
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
for(text=CTX_data_main(C)->text.first; text; text= text->id.next) {
|
||||
if(text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name+2, ".py")) {
|
||||
PyObject *module= bpy_text_import(text);
|
||||
|
||||
if (module==NULL) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
else {
|
||||
Py_DECREF(module);
|
||||
}
|
||||
}
|
||||
}
|
||||
bpy_context_clear(C, &gilstate);
|
||||
}
|
||||
|
||||
int BPY_context_get(bContext *C, const char *member, bContextDataResult *result)
|
||||
{
|
||||
|
||||
@@ -57,13 +57,13 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
|
||||
// XXX Todo, work out a better solution for passing on context, could make a tuple from self and pack the name and Context into it...
|
||||
bContext *C = BPy_GetContext();
|
||||
|
||||
if (!PyArg_ParseTuple(args, "sO|O!i:bpy.__ops__.call", &opname, &context_dict, &PyDict_Type, &kw, &context))
|
||||
if (!PyArg_ParseTuple(args, "sO|O!i:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context))
|
||||
return NULL;
|
||||
|
||||
ot= WM_operatortype_find(opname, TRUE);
|
||||
|
||||
if (ot == NULL) {
|
||||
PyErr_Format( PyExc_SystemError, "bpy.__ops__.call: operator \"%s\"could not be found", opname);
|
||||
PyErr_Format( PyExc_SystemError, "_bpy.ops.call: operator \"%s\"could not be found", opname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
|
||||
Py_XINCREF(context_dict); /* so we done loose it */
|
||||
|
||||
if(WM_operator_poll((bContext*)C, ot) == FALSE) {
|
||||
PyErr_SetString( PyExc_SystemError, "bpy.__ops__.call: operator poll() function failed, context is incorrect");
|
||||
PyErr_SetString( PyExc_SystemError, "_bpy.ops.call: operator poll() function failed, context is incorrect");
|
||||
error_val= -1;
|
||||
}
|
||||
else {
|
||||
@@ -153,18 +153,18 @@ static PyObject *pyop_as_string( PyObject * self, PyObject * args)
|
||||
int all_args = 1;
|
||||
int error_val= 0;
|
||||
|
||||
char *buf;
|
||||
char *buf = NULL;
|
||||
PyObject *pybuf;
|
||||
|
||||
bContext *C = BPy_GetContext();
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|O!i:bpy.__ops__.as_string", &opname, &PyDict_Type, &kw, &all_args))
|
||||
if (!PyArg_ParseTuple(args, "s|O!i:_bpy.ops.as_string", &opname, &PyDict_Type, &kw, &all_args))
|
||||
return NULL;
|
||||
|
||||
ot= WM_operatortype_find(opname, TRUE);
|
||||
|
||||
if (ot == NULL) {
|
||||
PyErr_Format( PyExc_SystemError, "bpy.__ops__.as_string: operator \"%s\"could not be found", opname);
|
||||
PyErr_Format( PyExc_SystemError, "_bpy.ops.as_string: operator \"%s\"could not be found", opname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -217,12 +217,12 @@ static PyObject *pyop_getrna(PyObject *self, PyObject *value)
|
||||
BPy_StructRNA *pyrna= NULL;
|
||||
|
||||
if(opname==NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "bpy.__ops__.get_rna() expects a string argument");
|
||||
PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_rna() expects a string argument");
|
||||
return NULL;
|
||||
}
|
||||
ot= WM_operatortype_find(opname, TRUE);
|
||||
if(ot==NULL) {
|
||||
PyErr_Format(PyExc_KeyError, "bpy.__ops__.get_rna(\"%s\") not found", opname);
|
||||
PyErr_Format(PyExc_KeyError, "_bpy.ops.get_rna(\"%s\") not found", opname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -245,8 +245,8 @@ PyObject *BPY_operator_module( void )
|
||||
static PyMethodDef pyop_add_meth = {"add", (PyCFunction) PYOP_wrap_add, METH_O, NULL};
|
||||
static PyMethodDef pyop_remove_meth = {"remove", (PyCFunction) PYOP_wrap_remove, METH_O, NULL};
|
||||
|
||||
PyObject *submodule = PyModule_New("bpy.__ops__");
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), "bpy.__ops__", submodule);
|
||||
PyObject *submodule = PyModule_New("_bpy.ops");
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), "_bpy.ops", submodule);
|
||||
|
||||
PyModule_AddObject( submodule, "call", PyCFunction_New(&pyop_call_meth, NULL) );
|
||||
PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) );
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
#define PYOP_ATTR_UINAME "bl_label"
|
||||
#define PYOP_ATTR_IDNAME "bl_idname" /* the name given by python */
|
||||
#define PYOP_ATTR_IDNAME_BL "_bl_idname" /* our own name converted into blender syntax, users wont see this */
|
||||
#define PYOP_ATTR_DESCRIPTION "__doc__" /* use pythons docstring */
|
||||
#define PYOP_ATTR_DESCRIPTION "__doc__" /* use pythons docstring */
|
||||
#define PYOP_ATTR_REGISTER "bl_register" /* True/False. if this python operator should be registered */
|
||||
#define PYOP_ATTR_UNDO "bl_undo" /* True/False. if this python operator should be undone */
|
||||
|
||||
@@ -106,30 +106,12 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
|
||||
Py_DECREF(args);
|
||||
|
||||
if (py_class_instance) { /* Initializing the class worked, now run its invoke function */
|
||||
PyObject *class_dict= PyObject_GetAttrString(py_class_instance, "__dict__");
|
||||
|
||||
/* Assign instance attributes from operator properties */
|
||||
if(op) {
|
||||
const char *arg_name;
|
||||
|
||||
RNA_STRUCT_BEGIN(op->ptr, prop) {
|
||||
arg_name= RNA_property_identifier(prop);
|
||||
|
||||
if (strcmp(arg_name, "rna_type")==0) continue;
|
||||
|
||||
item = pyrna_prop_to_py(op->ptr, prop);
|
||||
PyDict_SetItemString(class_dict, arg_name, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
RNA_STRUCT_END;
|
||||
}
|
||||
|
||||
RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context);
|
||||
|
||||
|
||||
if (mode==PYOP_INVOKE) {
|
||||
item= PyObject_GetAttrString(py_class, "invoke");
|
||||
args = PyTuple_New(3);
|
||||
|
||||
|
||||
RNA_pointer_create(NULL, &RNA_Event, event, &ptr_event);
|
||||
|
||||
// PyTuple_SET_ITEM "steals" object reference, it is
|
||||
@@ -149,12 +131,11 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
|
||||
PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
|
||||
}
|
||||
PyTuple_SET_ITEM(args, 0, py_class_instance);
|
||||
|
||||
|
||||
ret = PyObject_Call(item, args, NULL);
|
||||
|
||||
|
||||
Py_DECREF(args);
|
||||
Py_DECREF(item);
|
||||
Py_DECREF(class_dict);
|
||||
}
|
||||
else {
|
||||
PyErr_Print();
|
||||
@@ -308,11 +289,18 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
||||
*/
|
||||
item= ((PyTypeObject*)py_class)->tp_dict;
|
||||
if(item) {
|
||||
/* only call this so pyrna_deferred_register_props gives a useful error
|
||||
* WM_operatortype_append_ptr will call RNA_def_struct_identifier
|
||||
* later */
|
||||
RNA_def_struct_identifier(ot->srna, ot->idname);
|
||||
|
||||
if(pyrna_deferred_register_props(ot->srna, item)!=0) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
/* failed to register operator props */
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
@@ -341,7 +329,11 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
|
||||
|
||||
// in python would be...
|
||||
//PyObject *optype = PyObject_GetAttrString(PyObject_GetAttrString(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), "types"), "Operator");
|
||||
base_class = PyObject_GetAttrStringArgs(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), 2, "types", "Operator");
|
||||
|
||||
//PyObject bpy_mod= PyDict_GetItemString(PyEval_GetGlobals(), "bpy");
|
||||
PyObject *bpy_mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
|
||||
base_class = PyObject_GetAttrStringArgs(bpy_mod, 2, "types", "Operator");
|
||||
Py_DECREF(bpy_mod);
|
||||
|
||||
if(BPY_class_validate("Operator", py_class, base_class, pyop_class_attr_values, NULL) < 0) {
|
||||
return NULL; /* BPY_class_validate sets the error */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -39,11 +39,9 @@ extern PyTypeObject pyrna_prop_Type;
|
||||
#define BPy_PropertyRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_prop_Type)
|
||||
|
||||
typedef struct {
|
||||
void * _a;
|
||||
void * _b;
|
||||
PyTypeObject *py_type;
|
||||
} BPy_StructFakeType;
|
||||
|
||||
PyObject_HEAD /* required python macro */
|
||||
PointerRNA ptr;
|
||||
} BPy_DummyPointerRNA;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
|
||||
@@ -48,7 +48,7 @@ static struct PyMethodDef ui_methods[] = {
|
||||
|
||||
static struct PyModuleDef ui_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"bpy.ui",
|
||||
"_bpy.ui",
|
||||
"",
|
||||
-1,/* multiple "initialization" just copies the module dict. */
|
||||
ui_methods,
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
*/
|
||||
|
||||
/* python, will come back */
|
||||
void BPY_post_start_python() {}
|
||||
//void BPY_run_python_script() {}
|
||||
//void BPY_start_python() {}
|
||||
void BPY_call_importloader() {}
|
||||
|
||||
Reference in New Issue
Block a user