diff options
author | Willian Padovani Germano <wpgermano@gmail.com> | 2004-10-20 09:51:24 +0400 |
---|---|---|
committer | Willian Padovani Germano <wpgermano@gmail.com> | 2004-10-20 09:51:24 +0400 |
commit | fa9135385a38c9289a2dfa2320c20b68d782c1e4 (patch) | |
tree | f011e964789f9d9c37f18dfc72de661a525ecf3c /source | |
parent | f2f004af2df9733761cf9d4888e883a8c5f0d3e9 (diff) |
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/BPY_extern.h | 4 | ||||
-rw-r--r-- | source/blender/python/BPY_interface.c | 45 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Image.c | 13 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 22 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Sound.c | 86 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Window.c | 48 | ||||
-rw-r--r-- | source/blender/python/api2_2x/World.c | 22 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/API_intro.py | 6 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/BGL.py | 3 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Image.py | 29 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Object.py | 19 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Sound.py | 112 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Theme.py | 188 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Window.py | 17 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/World.py | 8 | ||||
-rw-r--r-- | source/blender/python/api2_2x/windowTheme.c | 8 | ||||
-rw-r--r-- | source/blender/src/space.c | 2 | ||||
-rw-r--r-- | source/creator/creator.c | 4 |
18 files changed, 535 insertions, 101 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index 54d9c0e1aef..45a95b39a00 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -46,7 +46,7 @@ struct _object; // forward declaration for PyObject ! extern "C" { #endif - void BPY_start_python( void ); + void BPY_start_python( int argc, char **argv ); void BPY_end_python( void ); void BPY_post_start_python( void ); int BPY_Err_getLinenumber( void ); @@ -75,7 +75,7 @@ extern "C" { void BPY_clear_script( struct Script *script ); void BPY_free_finished_script( struct Script *script ); - void init_syspath( void ); + void init_syspath( int first_time ); void syspath_append( char *dir ); char *bpy_gethome( void ); diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 6ce4b969d8a..ee318ddaca7 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -26,7 +26,7 @@ * This is a new part of Blender. * * Contributor(s): Michel Selten, Willian P. Germano, Stephen Swaney, - * Chris Keith + * Chris Keith, Chris Want * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ @@ -114,14 +114,26 @@ PyObject *blender_import( PyObject * self, PyObject * args ); * api variations. * Notes: Currently only the api for 2.2x will be initialised. ****************************************************************************/ -void BPY_start_python( void ) +void BPY_start_python( int argc, char **argv ) { - bpy_registryDict = PyDict_New( ); /* check comment at start of this file */ + static int argc_copy = 0; + static char **argv_copy = NULL; + int first_time = argc; + + /* we keep a copy of the values of argc and argv so that the game engine + * can call BPY_start_python(0, NULL) whenever a game ends, without having + * to know argc and argv there (in source/blender/src/space.c) */ + + if( first_time ) { + argc_copy = argc; + argv_copy = argv; + } + + bpy_registryDict = PyDict_New( );/* check comment at start of this file */ if( !bpy_registryDict ) printf( "Error: Couldn't create the Registry Python Dictionary!" ); -/* TODO: Shouldn't "blender" be replaced by PACKAGE ?? (config.h) */ Py_SetProgramName( "blender" ); /* @@ -130,16 +142,19 @@ void BPY_start_python( void ) * rest of our init msgs. */ - printf( "Checking for Python install...\n" ); - fflush( stdout ); + if( first_time ) { /* so it only prints msg on first_time */ + printf( "Checking for Python install...\n" ); + fflush( stdout ); + } Py_Initialize( ); + PySys_SetArgv( argc_copy, argv_copy ); init_ourImport( ); initBlenderApi2_2x( ); - init_syspath( ); + init_syspath( first_time ); /* not first_time: some msgs are suppressed */ return; } @@ -187,7 +202,7 @@ void syspath_append( char *dirname ) Py_DECREF( mod_sys ); } -void init_syspath( void ) +void init_syspath( int first_time ) { PyObject *path; PyObject *mod, *d; @@ -238,7 +253,7 @@ void init_syspath( void ) int size = 0; int index; - printf( "Installed Python found!\n" ); + if( first_time ) printf( "Installed Python found!\n" ); /* get the value of 'sitedirs' from the module */ @@ -260,15 +275,16 @@ void init_syspath( void ) Py_DECREF( mod ); } else { /* import 'site' failed */ PyErr_Clear( ); - printf( "No installed Python found.\n" ); - printf( "Only built-in modules are available. Some scripts may not run.\n" ); - printf( "Continuing happily.\n" ); + if( first_time ) { + printf( "No installed Python found.\n" ); + printf( "Only built-in modules are available. Some scripts may not run.\n" ); + printf( "Continuing happily.\n" ); + } } /* * initialize the sys module * set sys.executable to the Blender exe - * set argv[0] to the Blender exe */ mod = PyImport_ImportModule( "sys" ); /* new ref */ @@ -277,9 +293,6 @@ void init_syspath( void ) d = PyModule_GetDict( mod ); /* borrowed ref */ PyDict_SetItemString( d, "executable", Py_BuildValue( "s", bprogname ) ); - /* in the future this can be extended to have more argv's if needed: */ - PyDict_SetItemString( d, "argv", - Py_BuildValue( "[s]", bprogname ) ); Py_DECREF( mod ); } } diff --git a/source/blender/python/api2_2x/Image.c b/source/blender/python/api2_2x/Image.c index 02a2a47b8ba..ce70db0cf75 100644 --- a/source/blender/python/api2_2x/Image.c +++ b/source/blender/python/api2_2x/Image.c @@ -34,6 +34,7 @@ #include "BLI_winstuff.h" #endif /* WIN32 */ +#include <BDR_drawmesh.h> /* free_realtime_image */ #include <BKE_main.h> #include <BKE_global.h> #include <BKE_library.h> @@ -250,6 +251,7 @@ static PyObject *Image_setXRep( BPy_Image * self, PyObject * args ); static PyObject *Image_setYRep( BPy_Image * self, PyObject * args ); static PyObject *Image_reload( BPy_Image * self ); /* by Campbell */ static PyObject *Image_glLoad( BPy_Image * self ); +static PyObject *Image_glFree( BPy_Image * self ); /*****************************************************************************/ /* Python BPy_Image methods table: */ @@ -275,6 +277,9 @@ static PyMethodDef BPy_Image_methods[] = { {"glLoad", ( PyCFunction ) Image_glLoad, METH_NOARGS, "() - Load the image data in OpenGL texture memory.\n\ The bindcode (int) is returned."}, + {"glFree", ( PyCFunction ) Image_glFree, METH_NOARGS, + "() - Free the image data from OpenGL texture memory only,\n\ + see also image.glLoad()."}, {"setName", ( PyCFunction ) Image_setName, METH_VARARGS, "(str) - Change Image object name"}, {"setXRep", ( PyCFunction ) Image_setXRep, METH_VARARGS, @@ -482,6 +487,14 @@ static PyObject *Image_reload( BPy_Image * self ) return Py_None; } +static PyObject *Image_glFree( BPy_Image * self ) +{ + Image *img = self->image; + + free_realtime_image( img ); + return EXPP_incr_ret( Py_None ); +} + static PyObject *Image_glLoad( BPy_Image * self ) { Image *img = self->image; diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index bdb3ad33a51..6311f2be933 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -196,9 +196,14 @@ hierarchy (faster)"}, "(i = 0) - Returns list of materials assigned to the object.\n\ if i is nonzero, empty slots are not ignored: they are returned as None's."}, {"getMatrix", ( PyCFunction ) Object_getMatrix, METH_VARARGS, - "(str = 'localspace') - Returns the object matrix.\n\ -(str = 'localspace') - the wanted matrix: worldspace, localspace (default)\n\ -or oldlocal (not updated, it was the only choice before Blender 2.34)."}, + "(str = 'worldspace') - Returns the object matrix.\n\ +(str = 'localspace') - the wanted matrix: worldspace (default), localspace\n\ +or old_worldspace.\n\ +\n\ +'old_worldspace' was the only behavior before Blender 2.34. With it the\n\ +matrix is not updated for changes made by the script itself\n\ +(like obj.LocX = 10) until a redraw happens, either called by the script or\n\ +automatic when the script finishes."}, {"getName", ( PyCFunction ) Object_getName, METH_NOARGS, "Returns the name of the object"}, {"getParent", ( PyCFunction ) Object_getParent, METH_NOARGS, @@ -952,7 +957,7 @@ static PyObject *Object_getMaterials( BPy_Object * self, PyObject * args ) static PyObject *Object_getMatrix( BPy_Object * self, PyObject * args ) { PyObject *matrix; - char *space = "localspace"; /* default to local */ + char *space = "worldspace"; /* default to local */ if( !PyArg_ParseTuple( args, "|s", &space ) ) { return ( EXPP_ReturnPyObjError( PyExc_AttributeError, @@ -970,13 +975,14 @@ static PyObject *Object_getMatrix( BPy_Object * self, PyObject * args ) } else if( BLI_streq( space, "localspace" ) ) { /* Localspace matrix */ object_to_mat4( self->object, *( ( MatrixObject * ) matrix )->matrix ); - } else if( BLI_streq( space, "oldlocal" ) ) { /* old behavior, prior to 2.34 */ + /* old behavior, prior to 2.34, check this method's doc string: */ + } else if( BLI_streq( space, "old_worldspace" ) ) { Mat4CpyMat4( *( ( MatrixObject * ) matrix )->matrix, self->object->obmat ); } else { return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, - "wrong parameter, expected nothing or either 'localspace' (default),\n\ -'worldspace' or 'oldlocal'" ) ); + "wrong parameter, expected nothing or either 'worldspace' (default),\n\ +'localspace' or 'old_worldspace'" ) ); } return matrix; } @@ -2199,7 +2205,7 @@ static PyObject *Object_getAttr( BPy_Object * obj, char *name ) } if( StringEqual( name, "mat" ) || StringEqual( name, "matrix" ) ) return ( Object_getMatrix - ( obj, Py_BuildValue( "(s)", "localspace" ) ) ); + ( obj, Py_BuildValue( "(s)", "worldspace" ) ) ); if( StringEqual( name, "matrixWorld" ) ) return ( Object_getMatrix ( obj, Py_BuildValue( "(s)", "worldspace" ) ) ); diff --git a/source/blender/python/api2_2x/Sound.c b/source/blender/python/api2_2x/Sound.c index ca5b24c8a3d..eb8b5094b58 100644 --- a/source/blender/python/api2_2x/Sound.c +++ b/source/blender/python/api2_2x/Sound.c @@ -48,11 +48,16 @@ /* Python BPy_Sound defaults: */ /*****************************************************************************/ +#define EXPP_SND_volume_MIN 0.0 +#define EXPP_SND_volume_MAX 1.0 +#define EXPP_SND_pitch_MIN -12.0 +#define EXPP_SND_pitch_MAX 12.0 +#define EXPP_SND_attenuation_MIN 0.0 +#define EXPP_SND_attenuation_MAX 5.0 + /*****************************************************************************/ /* Python API function prototypes for the Sound module. */ /*****************************************************************************/ -static PyObject *M_Sound_New( PyObject * self, PyObject * args, - PyObject * keywords ); static PyObject *M_Sound_Get( PyObject * self, PyObject * args ); static PyObject *M_Sound_Load( PyObject * self, PyObject * args ); @@ -63,26 +68,20 @@ static PyObject *M_Sound_Load( PyObject * self, PyObject * args ); /************************************************************************/ static char M_Sound_doc[] = "The Blender Sound module\n\n"; -static char M_Sound_New_doc[] = - "() - return a new Sound object -- unimplemented"; - static char M_Sound_Get_doc[] = "(name) - return the sound with the name 'name', \ returns None if not found.\n If 'name' is not specified, \ it returns a list of all sounds in the\ncurrent scene."; static char M_Sound_Load_doc[] = - "(filename, redraw = 0) - return sound from file filename as Sound Object,\n\ + "(filename) - return sound from file filename as a Sound Object,\n\ returns None if not found."; /*****************************************************************************/ /* Python method structure definition for Blender.Sound module: */ /*****************************************************************************/ struct PyMethodDef M_Sound_methods[] = { - {"New", ( PyCFunction ) M_Sound_New, METH_VARARGS | METH_KEYWORDS, - M_Sound_New_doc}, {"Get", M_Sound_Get, METH_VARARGS, M_Sound_Get_doc}, - {"get", M_Sound_Get, METH_VARARGS, M_Sound_Get_doc}, {"Load", M_Sound_Load, METH_VARARGS, M_Sound_Load_doc}, {NULL, NULL, 0, NULL} }; @@ -109,7 +108,8 @@ static PyObject *Sound_set ## funcname(BPy_Sound *self, PyObject *args) { \ if (!PyArg_ParseTuple(args, "f", &f)) \ return (EXPP_ReturnPyObjError (PyExc_TypeError, \ "expected float argument")); \ - self->sound->varname = f; \ + self->sound->varname = EXPP_ClampFloat(f,\ + EXPP_SND_##varname##_MIN, EXPP_SND_##varname##_MAX);\ Py_INCREF(Py_None); \ return Py_None; \ } @@ -127,14 +127,18 @@ static PyObject *Sound_set ## funcname(BPy_Sound *self, PyObject *args) { \ static PyObject *Sound_getName( BPy_Sound * self ); static PyObject *Sound_getFilename( BPy_Sound * self ); static PyObject *Sound_play( BPy_Sound * self ); -static PyObject *Sound_makeActive( BPy_Sound * self ); +static PyObject *Sound_setCurrent( BPy_Sound * self ); +//static PyObject *Sound_reload ( BPy_Sound * self ); SOUND_FLOAT_METHODS( Volume, volume ) - SOUND_FLOAT_METHODS( Panning, panning ) - SOUND_FLOAT_METHODS( Attenuation, attenuation ) - SOUND_FLOAT_METHODS( Pitch, pitch ) - SOUND_FLOAT_METHODS( MinGain, min_gain ) - SOUND_FLOAT_METHODS( MaxGain, max_gain ) - SOUND_FLOAT_METHODS( Distance, distance ) +SOUND_FLOAT_METHODS( Attenuation, attenuation ) +SOUND_FLOAT_METHODS( Pitch, pitch ) +/* these can't be set via interface, removed for now */ +/* +SOUND_FLOAT_METHODS( Panning, panning ) +SOUND_FLOAT_METHODS( MinGain, min_gain ) +SOUND_FLOAT_METHODS( MaxGain, max_gain ) +SOUND_FLOAT_METHODS( Distance, distance ) +*/ /*****************************************************************************/ /* Python BPy_Sound methods table: */ @@ -147,15 +151,21 @@ static PyMethodDef BPy_Sound_methods[] = { "() - Return Sound object filename"}, {"play", ( PyCFunction ) Sound_play, METH_NOARGS, "() - play this sound"}, - {"makeActive", ( PyCFunction ) Sound_makeActive, METH_NOARGS, + {"setCurrent", ( PyCFunction ) Sound_setCurrent, METH_NOARGS, "() - make this the active sound in the sound buttons win (also redraws)"}, + //{"reload", ( PyCFunction ) Sound_setCurrent, METH_NOARGS, + //"() - reload this Sound object's sample.\n\ +//This is only useful if the original sound file has changed."}, SOUND_FLOAT_METHOD_FUNCS( Volume ) - SOUND_FLOAT_METHOD_FUNCS( Panning ) - SOUND_FLOAT_METHOD_FUNCS( Attenuation ) - SOUND_FLOAT_METHOD_FUNCS( Pitch ) - SOUND_FLOAT_METHOD_FUNCS( MinGain ) - SOUND_FLOAT_METHOD_FUNCS( MaxGain ) - SOUND_FLOAT_METHOD_FUNCS( Distance ) {NULL, NULL, 0, NULL} + SOUND_FLOAT_METHOD_FUNCS( Attenuation ) + SOUND_FLOAT_METHOD_FUNCS( Pitch ) + /* + SOUND_FLOAT_METHOD_FUNCS( Panning ) + SOUND_FLOAT_METHOD_FUNCS( MinGain ) + SOUND_FLOAT_METHOD_FUNCS( MaxGain ) + SOUND_FLOAT_METHOD_FUNCS( Distance ) + */ + {NULL, NULL, 0, NULL} }; /*****************************************************************************/ @@ -185,19 +195,6 @@ PyTypeObject Sound_Type = { 0, /* tp_members */ }; -/*****************************************************************************/ -/* Function: M_Sound_New */ -/* Python equivalent: Blender.Sound.New */ -/*****************************************************************************/ -static PyObject *M_Sound_New( PyObject * self, PyObject * args, - PyObject * keywords ) -{ - printf( "In Sound_New() - unimplemented in 2.34\n" ); - - Py_INCREF( Py_None ); - return Py_None; -} - /* NOTE: these were copied and modified from image.h. To Be Done TBD: * macro-ize them, or C++ templates eventually? */ @@ -417,7 +414,7 @@ static PyObject *Sound_play( BPy_Sound * self ) return Py_None; } -static PyObject *Sound_makeActive( BPy_Sound * self ) +static PyObject *Sound_setCurrent( BPy_Sound * self ) { bSound *snd_ptr = self->sound; @@ -433,6 +430,19 @@ static PyObject *Sound_makeActive( BPy_Sound * self ) Py_INCREF( Py_None ); return Py_None; } +/* +static PyObject *Sound_reload( BPy_Sound * self) +{ + sound_free_sample(); + + if (sound->snd_sound) { + SND_RemoveSound(ghSoundScene, sound->snd_sound); + sound->snd_sound = NULL; + } + + return EXPP_incr_ret( Py_None ); +} +*/ /*****************************************************************************/ /* Function: Sound_getAttr */ diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c index 84b3a5974bb..067bfc8d33a 100644 --- a/source/blender/python/api2_2x/Window.c +++ b/source/blender/python/api2_2x/Window.c @@ -25,7 +25,7 @@ * * This is a new part of Blender. * - * Contributor(s): Willian P. Germano + * Contributor(s): Willian P. Germano, Tom Musgrove * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ @@ -47,6 +47,7 @@ #include <BIF_screen.h> #include <BIF_space.h> #include <BIF_drawtext.h> +#include <BIF_mywindow.h> /* L/M/R_MOUSE bitflags */ #include <BIF_spacetypes.h> #include <mydevice.h> #include <DNA_view3d_types.h> @@ -85,6 +86,7 @@ static PyObject *M_Window_SetViewQuat( PyObject * self, PyObject * args ); static PyObject *M_Window_GetViewOffset( PyObject * self ); static PyObject *M_Window_SetViewOffset( PyObject * self, PyObject * args ); static PyObject *M_Window_GetViewMatrix( PyObject * self ); +static PyObject *M_Window_GetPerspMatrix( PyObject * self ); static PyObject *M_Window_FileSelector( PyObject * self, PyObject * args ); static PyObject *M_Window_ImageSelector( PyObject * self, PyObject * args ); static PyObject *M_Window_EditMode( PyObject * self, PyObject * args ); @@ -164,6 +166,9 @@ static char M_Window_GetViewVector_doc[] = static char M_Window_GetViewMatrix_doc[] = "() - Get the current 3d view matrix."; +static char M_Window_GetPerspMatrix_doc[] = + "() - Get the current 3d Persp matrix."; + static char M_Window_EditMode_doc[] = "() - Get the current status -- 0: not in edit mode; 1: in edit mode.\n\ (status) - if 1: enter edit mode; if 0: leave edit mode.\n\ @@ -228,7 +233,7 @@ static char M_Window_SetMouseCoords_doc[] = (x,y) - ints ([x, y] also accepted): the new x, y coordinates."; static char M_Window_GetMouseButtons_doc[] = - "() - Get the current mouse button state (see Blender.Draw.LEFTMOUSE, etc)."; + "() - Get the current mouse button state (see Blender.Window.MButs dict)."; static char M_Window_GetKeyQualifiers_doc[] = "() - Get the current qualifier keys state.\n\ @@ -306,6 +311,8 @@ struct PyMethodDef M_Window_methods[] = { M_Window_SetViewOffset_doc}, {"GetViewMatrix", ( PyCFunction ) M_Window_GetViewMatrix, METH_NOARGS, M_Window_GetViewMatrix_doc}, + {"GetPerspMatrix", ( PyCFunction ) M_Window_GetPerspMatrix, METH_NOARGS, + M_Window_GetPerspMatrix_doc}, {"EditMode", ( PyCFunction ) M_Window_EditMode, METH_VARARGS, M_Window_EditMode_doc}, {"ViewLayer", ( PyCFunction ) M_Window_ViewLayer, METH_VARARGS, @@ -784,6 +791,30 @@ static PyObject *M_Window_GetViewMatrix( PyObject * self ) return viewmat; } +/*****************************************************************************/ +/* Function: M_Window_GetPerspMatrix */ +/* Python equivalent: Blender.Window.GetPerspMatrix */ +/*****************************************************************************/ +static PyObject *M_Window_GetPerspMatrix( PyObject * self ) +{ + PyObject *perspmat; + + if( !G.vd ) { + Py_INCREF( Py_None ); + return Py_None; + } + + perspmat = + ( PyObject * ) newMatrixObject( ( float * ) G.vd->persmat, 4, + 4 ); + + if( !perspmat ) + return EXPP_ReturnPyObjError( PyExc_MemoryError, + "GetPerspMatrix: couldn't create matrix pyobject" ); + + return perspmat; +} + static PyObject *M_Window_EditMode( PyObject * self, PyObject * args ) { short status = -1; @@ -1214,7 +1245,7 @@ static PyObject *M_Window_GetScreenInfo( PyObject * self, PyObject * args, /*****************************************************************************/ PyObject *Window_Init( void ) { - PyObject *submodule, *Types, *Qual, *dict; + PyObject *submodule, *Types, *Qual, *MButs, *dict; submodule = Py_InitModule3( "Blender.Window", M_Window_methods, @@ -1226,6 +1257,7 @@ PyObject *Window_Init( void ) Types = M_constant_New( ); Qual = M_constant_New( ); + MButs = M_constant_New( ); if( Types ) { BPy_constant *d = ( BPy_constant * ) Types; @@ -1264,5 +1296,15 @@ PyObject *Window_Init( void ) PyModule_AddObject( submodule, "Qual", Qual ); } + if( MButs ) { + BPy_constant *d = ( BPy_constant * ) MButs; + + constant_insert( d, "L", PyInt_FromLong( L_MOUSE ) ); + constant_insert( d, "M", PyInt_FromLong( M_MOUSE ) ); + constant_insert( d, "R", PyInt_FromLong( R_MOUSE ) ); + + PyModule_AddObject( submodule, "MButs", MButs ); + } + return submodule; } diff --git a/source/blender/python/api2_2x/World.c b/source/blender/python/api2_2x/World.c index 89af766c354..d35dbef5145 100644 --- a/source/blender/python/api2_2x/World.c +++ b/source/blender/python/api2_2x/World.c @@ -85,7 +85,7 @@ static PyObject *World_setMist( BPy_World * self, PyObject * args ); static PyObject *World_getScriptLinks( BPy_World * self, PyObject * args ); static PyObject *World_addScriptLink( BPy_World * self, PyObject * args ); static PyObject *World_clearScriptLinks( BPy_World * self ); -static PyObject *World_makeActive( BPy_World * self ); +static PyObject *World_setCurrent( BPy_World * self ); /*****************************************************************************/ @@ -94,7 +94,7 @@ static PyObject *World_makeActive( BPy_World * self ); static PyObject *M_World_New( PyObject * self, PyObject * args, PyObject * keywords ); static PyObject *M_World_Get( PyObject * self, PyObject * args ); -static PyObject *M_World_GetActive( PyObject * self ); +static PyObject *M_World_GetCurrent( PyObject * self ); /*****************************************************************************/ @@ -123,7 +123,7 @@ static char M_World_Get_doc[] = "(name) - return the world with the name 'name', \ returns None if not found.\n If 'name' is not specified, \ it returns a list of all worlds in the\ncurrent scene."; -static char M_World_GetActive_doc[] = "() - returns the current world, or \ +static char M_World_GetCurrent_doc[] = "() - returns the current world, or \ None if the Scene has no world"; @@ -135,8 +135,10 @@ struct PyMethodDef M_World_methods[] = { {"New", ( PyCFunction ) M_World_New, METH_VARARGS | METH_KEYWORDS, M_World_New_doc}, {"Get", M_World_Get, METH_VARARGS, M_World_Get_doc}, - {"GetActive", ( PyCFunction ) M_World_GetActive, METH_NOARGS, - M_World_GetActive_doc}, + {"GetActive", ( PyCFunction ) M_World_GetCurrent, METH_NOARGS, + M_World_GetCurrent_doc}, + {"GetCurrent", ( PyCFunction ) M_World_GetCurrent, METH_NOARGS, + M_World_GetCurrent_doc}, {"get", M_World_Get, METH_VARARGS, M_World_Get_doc}, {NULL, NULL, 0, NULL} }; @@ -200,8 +202,10 @@ static PyMethodDef BPy_World_methods[] = { {"clearScriptLinks", ( PyCFunction ) World_clearScriptLinks, METH_NOARGS, "() - Delete all scriptlinks from this world :)."}, - {"makeActive", ( PyCFunction ) World_makeActive, METH_NOARGS, + {"setCurrent", ( PyCFunction ) World_setCurrent, METH_NOARGS, "() - Makes this world the active world for the current scene."}, + {"makeActive", ( PyCFunction ) World_setCurrent, METH_NOARGS, + "please use setCurrent instead, this alias will be removed."}, {NULL, NULL, 0, NULL} }; @@ -357,7 +361,7 @@ static PyObject *M_World_Get( PyObject * self, PyObject * args ) -static PyObject *M_World_GetActive( PyObject * self ) +static PyObject *M_World_GetCurrent( PyObject * self ) { BPy_World *w = NULL; if( !G.scene->world ) { @@ -864,8 +868,8 @@ static PyObject *World_getScriptLinks( BPy_World * self, PyObject * args ) -/* world.makeActive */ -static PyObject *World_makeActive( BPy_World * self ) +/* world.setCurrent */ +static PyObject *World_setCurrent( BPy_World * self ) { World *world = self->world; /* If there is a world then it now has one less user */ diff --git a/source/blender/python/api2_2x/doc/API_intro.py b/source/blender/python/api2_2x/doc/API_intro.py index 94f583211fc..8f684c79144 100644 --- a/source/blender/python/api2_2x/doc/API_intro.py +++ b/source/blender/python/api2_2x/doc/API_intro.py @@ -34,11 +34,13 @@ The Blender Python API Reference - L{Scene} (*) - L{Radio} - L{Render} + - L{Sound} (new) - L{Text} - L{Texture} - L{Types} - - L{Window} - - L{World} + - L{Window} (*) + - L{Theme} (new) + - L{World} (*) - L{sys<Sys>} (*) - marks updated. diff --git a/source/blender/python/api2_2x/doc/BGL.py b/source/blender/python/api2_2x/doc/BGL.py index cbb8b455b19..6c20e4ec7b4 100644 --- a/source/blender/python/api2_2x/doc/BGL.py +++ b/source/blender/python/api2_2x/doc/BGL.py @@ -74,6 +74,9 @@ Example:: # Draw.Register(show_win, ev, None) # start the main loop +@note: you can use the L{Image} module and L{Image.Image} bpy object to load + and set textures. See L{Image.Image.glLoad} and L{Image.Image.glFree}, + for example. @see: U{www.opengl.org} @see: U{nehe.gamedev.net} """ diff --git a/source/blender/python/api2_2x/doc/Image.py b/source/blender/python/api2_2x/doc/Image.py index f09a5fbcc69..df4b5c6a65c 100644 --- a/source/blender/python/api2_2x/doc/Image.py +++ b/source/blender/python/api2_2x/doc/Image.py @@ -6,7 +6,7 @@ The Blender.Image submodule. Image ===== -B{New}: L{Image.reload}, L{Image.getBindCode}. +B{New}: L{Image.glLoad}, L{Image.glFree}. This module provides access to B{Image} objects in Blender. @@ -110,8 +110,8 @@ class Image: def getBindCode(): """ - Get the Image's bindcode. This is for texture loading using BGL calls, - see for example L{BGL.glBindTexture}. + Get the Image's bindcode. This is for texture loading using BGL calls. + See, for example, L{BGL.glBindTexture} and L{glLoad}. @rtype: int """ @@ -125,6 +125,29 @@ class Image: @returns: None """ + def glLoad(): + """ + Load this image's data into OpenGL texture memory, if it is not already + loaded (image.bindcode is 0 if it is not loaded yet). + @note: Usually you don't need to call this method. It is only necessary + if you want to draw textured objects in the Scripts window and the + image's bind code is zero at that moment, otherwise Blender itself can + take care of binding / unbinding textures. Calling this method for an + image with nonzero bind code simply returns the image's bind code value + (see L{getBindCode}). + @rtype: int + @returns: the texture's bind code. + """ + + def glFree(): + """ + Delete this image's data from OpenGL texture memory, only (the image itself + is not removed from Blender's memory). Internally, glDeleteTextures (see + L{BGL.glDeleteTextures}) is used, but this method also updates Blender's + Image object so that its bind code is set to 0. See also L{Image.glLoad}, + L{Image.getBindCode}. + """ + def setName(name): """ Set the name of this Image object. diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py index 07c674b9dbe..c2d1db093ca 100644 --- a/source/blender/python/api2_2x/doc/Object.py +++ b/source/blender/python/api2_2x/doc/Object.py @@ -3,7 +3,8 @@ """ The Blender.Object submodule -B{New}: 'oldlocal' parameter in L{Object.Object.getMatrix}. +B{New}: 'old_worldspace' parameter in L{Object.Object.getMatrix}, which now +defaults to 'worldspace'. Object ====== @@ -146,7 +147,7 @@ class Object: @cvar data: The data of the object. (Read-only) @cvar ipo: The ipo data associated with the object. (Read-only) @cvar mat: The matrix of the object relative to its parent. (Read-only) - @cvar matrix: The matrix of the object relative to its parent. (Read-only) + @cvar matrix: The matrix of the object in world space. (Read-only) @cvar matrixLocal: The matrix of the object relative to its parent. (Read-only) @cvar matrixWorld: The matrix of the object in world space. (Read-only) @cvar colbits: The Material usage mask. A set bit #n means: the Material @@ -287,17 +288,17 @@ class Object: @return: list of Material Objects assigned to the object. """ - def getMatrix(space = 'localspace'): + def getMatrix(space = 'worldspace'): """ Returns the object matrix. @type space: string @param space: The desired matrix: - - localspace (default): relative to the object's parent; - - worldspace: absolute, taking vertex parents, tracking and ipo's into - account; - - oldlocal: old behavior, prior to Blender 2.34, where eventual changes - made by the script itself were not taken into account until the - script finished executing. + - worldspace (default): absolute, taking vertex parents, tracking and + ipo's into account; + - localspace: relative to the object's parent; + - old_worldspace: old behavior, prior to Blender 2.34, where eventual + changes made by the script itself were not taken into account until + a redraw happened, either called by the script or upon its exit. Returns the object matrix. @rtype: Py_Matrix @return: a python 4x4 matrix object diff --git a/source/blender/python/api2_2x/doc/Sound.py b/source/blender/python/api2_2x/doc/Sound.py new file mode 100644 index 00000000000..6cc72f471cf --- /dev/null +++ b/source/blender/python/api2_2x/doc/Sound.py @@ -0,0 +1,112 @@ +# Blender.Sound module and the Sound PyType object + +""" +The Blender.Sound submodule. + +Sound +===== + +This module provides access to B{Sound} objects in Blender. + +Example:: + import Blender + from Blender import Sound + # + sound = Sound.Load("/path/to/my/sound.wav") # load a sound file + print "Sound from", sound.getFilename(), + print "loaded to obj", sound.getName()) + print "All Sounds available now:", Sound.Get() +""" + +def Load (filename): + """ + Load the sound called 'filename' into a Sound object. + @type filename: string + @param filename: The full path to the sound file. + @rtype: Blender Sound + @return: A Blender Sound object with the data from I{filename}. + """ + +def Get (name = None): + """ + Get the Sound object(s) from Blender. + @type name: string + @param name: The name of the Sound object. + @rtype: Blender Sound or a list of Blender Sounds + @return: It depends on the I{name} parameter: + - (name): The Sound object called I{name}, None if not found; + - (): A list with all Sound objects in the current scene. + """ + + +class Sound: + """ + The Sound object + ================ + This object gives access to Sounds in Blender. + @cvar name: The name of this Sound object. + @cvar filename: The filename (path) to the sound file loaded into this Sound + object. + """ + + def getName(): + """ + Get the name of this Sound object. + @rtype: string + """ + + def getFilename(): + """ + Get the filename of the sound file loaded into this Sound object. + @rtype: string + """ + + def play(): + """ + Play this sound. + """ + + def setCurrent(): + """ + Make this the active sound in the sound buttons window (also redraws). + """ + + def getVolume(): + """ + Get this sound's volume. + rtype: float + """ + + def setVolume(f): + """ + Set this sound's volume. + @type f: float + @param f: the new volume value in the range [0.0, 1.0]. + """ + + def getAttenuation(): + """ + Get this sound's attenuation value. + rtype: float + """ + + def setAttenuation(f): + """ + Set this sound's attenuation. + @type f: float + @param f: the new attenuation value in the range [0.0, 5.0]. + """ + + def getPitch(): + """ + Get this sound's pitch value. + rtype: float + """ + + def setPitch(f): + """ + Set this sound's pitch. + @type f: float + @param f: the new pitch value in the range [-12.0, 12.0]. + """ + diff --git a/source/blender/python/api2_2x/doc/Theme.py b/source/blender/python/api2_2x/doc/Theme.py new file mode 100644 index 00000000000..facfee068c2 --- /dev/null +++ b/source/blender/python/api2_2x/doc/Theme.py @@ -0,0 +1,188 @@ +# Blender.Window.Theme submodule and the Theme PyType object + +""" +The Blender.Window.Theme submodule. + +Theme +===== + +This module provides access to B{Theme} objects in Blender. + +Example:: + # this is a simplified version of the save_theme.py script + # shipped with Blender: + import Blender + from Blender.Window import Theme, FileSelector + + theme = Theme.Get()[0] # get current theme + + def write_theme(filename): + "Write the current theme as a bpython script" + + f = file(filename, "w") + + f.write("import Blender") + f.write("from Blender.Window import Theme") + f.write("theme = Theme.New('%s')" % theme.name) + + for tsp in theme.get(): # write each theme space + command = "\\n%s = theme.get('%s')" % (tsp, tsp) + f.write(command + "\\n") + exec(command) + exec("vars = dir(%s)" % tsp) + vars.remove('theme') + + for var in vars: # write each variable from each theme space + v = "%s.%s" % (tsp, var) + exec("value = %s" % v) + f.write("%s = %s\\n" % (v, value)) + + f.write('\\nBlender.Redraw(-1)') # redraw to update the screen + f.close() + + FileSelector(write_theme, "Save Current Theme", default_fname) +""" + +def New (name = "New Theme", theme = '<default>'): + """ + Create a new Theme object. + @type name: string + @param name: The name of the new theme. + @type theme: Blender Theme + @param theme: a base theme to copy all data from. It defaults to the current + one. + @rtype: Blender Theme + @return: A new Blender Theme object. + """ + +def Get (name = None): + """ + Get the Theme object(s) from Blender. + @type name: string + @param name: The name of the Theme object. + @rtype: Blender Theme or a list of Blender Themes + @return: It depends on the I{name} parameter: + - (name): The Theme object called I{name}, None if not found; + - (): A list with all Theme objects currently in Blender. + """ + + +class Theme: + """ + The Theme object + ================ + This object gives access to Themes in Blender. Each Theme object is + composed of one UI (Use Interface) theme and many Space themes + (3d view, Text Editor, Buttons window, etc). + @cvar name: The name of this Theme object. + """ + + def getName(): + """ + Get the name of this Theme object. + @rtype: string + @return: the name of this Theme object. + """ + + def setName(s): + """ + Rename this theme. + @type s: string + @param s: the new name. + """ + + def get(t = None): + """ + Get a space or the ui (sub)theme from this Theme. + @type t: string, int or None + @param t: the wanted sub-theme as either: + - int: -1 for UI or the types in L{Window.Types} for the others; + - string: use get() to know them (they are case insensitive); + - nothing: as written above, get() returns a list of names. + @rtype: Blender ThemeSpace or ThemeUI or list of sub-theme types as strings. + @return: It depends on the given parameter: + - (): a list with all available types, as strings; + - (type): the chosen sub-theme. + """ + + class ThemeUI: + """ + The User Interface sub-theme + ============================ + This can be accessed with theme.get(t), where t can be 'ui' or -1. + The available variables follow the internal (C coded) ThemeUI struct in + Blender. Most of them represent rgba (red, green, blue, alpha) colors, + with each component in the range [0, 255]. There is more than one way to + access them. + + Examples:: + print outline.R + outline.r = 180 # it's case insensitive + outline[0] = 94 # 0 for red, 1 for green, ... + outline = [200, 200, 200, 255] # setting all components at once + @type theme: string + @cvar theme: the parent Theme for this object. + @cvar outline: theme rgba var. + @cvar neutral: theme rgba var. + @cvar action: theme rgba var. + @cvar setting: theme rgba var. + @cvar setting1: theme rgba var. + @cvar setting2: theme rgba var. + @cvar num: theme rgba var. + @cvar textfield: theme rgba var. + @cvar popup: theme rgba var. + @cvar text: theme rgba var. + @cvar text_hi: theme rgba var. + @cvar menu_back: theme rgba var. + @cvar menu_item: theme rgba var. + @cvar menu_hilite: theme rgba var. + @cvar menu_text: theme rgba var. + @cvar menu_text_hi: theme rgba var. + @type drawType: int + @cvar drawType: the draw type (minimal, rounded, etc) in the range [1, 4]. + """ + + class ThemeSpace: + """ + The Space sub-themes + ==================== + There is a sub-theme for each space in Blender (except for the Scripts + window, but it will be added soon). Please read the information about + L{Theme.ThemeUI}, since it is also relevant here. In Blender, + all theme spaces share the same C structure. For this reason, all of + them here share the same variables, event though some spaces only use + a few of them. This lower-level access is acceptable because generally + users will prefer to use the interface to change single theme options + and only use scripting to save or restore themes. But anyway, checking + the Themes tab in the User Preferences space in Blender and using the + bundled "Save current theme" script (or its simplified version written + on the top of this page) can help you finding out any specific info you + may need. + @type theme: string + @cvar theme: the parent Theme for this object. + @cvar back: theme rgba var. + @cvar text: theme rgba var. + @cvar text_hi: theme rgba var. + @cvar header: theme rgba var. + @cvar panel: theme rgba var. + @cvar shade1: theme rgba var. + @cvar shade2: theme rgba var. + @cvar hilite: theme rgba var. + @cvar grid: theme rgba var. + @cvar wire: theme rgba var. + @cvar select: theme rgba var. + @cvar active: theme rgba var. + @cvar transform: theme rgba var. + @cvar vertex: theme rgba var. + @cvar vertex_select: theme rgba var. + @cvar edge: theme rgba var. + @cvar edge_select: theme rgba var. + @cvar edge_seam: theme rgba var. + @cvar edge_facesel: theme rgba var. + @cvar face: theme rgba var. + @cvar face_select: theme rgba var. + @cvar normal: theme rgba var. + @type vertex_size: int + @cvar vertex_size: size of the vertices dots on screen in the range [1, 10]. + """ + diff --git a/source/blender/python/api2_2x/doc/Window.py b/source/blender/python/api2_2x/doc/Window.py index 9cc17a26a2e..60f1396dbce 100644 --- a/source/blender/python/api2_2x/doc/Window.py +++ b/source/blender/python/api2_2x/doc/Window.py @@ -8,7 +8,7 @@ Window This module provides access to B{Window} functions in Blender. -B{New}: many new functions related to screens and events. +B{New}: L{GetPerspMatrix}. Example: -------- @@ -81,6 +81,12 @@ DrawProgressBar:: - LSHIFT - RSHIFT - SHIFT + +@type MButs: readonly dictionary +@var MButs: Mouse buttons. + - L: left mouse button + - M: middle mouse button + - R: right mouse button """ def Redraw (spacetype = '<Types.VIEW3D>'): @@ -201,6 +207,13 @@ def GetViewMatrix (): @return: the current matrix. """ +def GetPerspMatrix (): + """ + Get the current 3d perspective matrix. + @rtype: 4x4 float matrix + @return: the current matrix. + """ + def EditMode(enable = -1, undo_msg = 'From script'): """ Get and optionally set the current edit mode status: in or out. @@ -358,7 +371,7 @@ def SetMouseCoords (coords): def GetMouseButtons (): """ - Get the current mouse button state (compare with events from L{Draw}). + Get the current mouse button state (see / compare against L{MButs}). @rtype: int @return: an or'ed flag with the currently pressed buttons. """ diff --git a/source/blender/python/api2_2x/doc/World.py b/source/blender/python/api2_2x/doc/World.py index a8d10ce7073..cd2edd922eb 100644 --- a/source/blender/python/api2_2x/doc/World.py +++ b/source/blender/python/api2_2x/doc/World.py @@ -3,7 +3,7 @@ """ The Blender.World submodule -B{New}: scriptLink methods: L{World.getScriptLinks}, ... +B{New}: L{GetCurrent}, L{World.setCurrent}. INTRODUCTION ============ @@ -44,7 +44,7 @@ def New (name): @type name: string @param name: World's name (optionnal). @rtype: Blender World - @return: The created World. If the "name" paraeter has not been provided, it will be automatically be set by blender. + @return: The created World. If the "name" parameter has not been provided, it will be automatically be set by blender. """ def Get (name): @@ -59,7 +59,7 @@ def Get (name): """ -def GetActive (): +def GetCurrent (): """ Get the active world of the scene. @rtype: Blender World or None @@ -315,7 +315,7 @@ class World: @param event: "FrameChanged" or "Redraw". """ - def makeActive (): + def setCurrent (): """ Make this world active in the current scene. @rtype: PyNone diff --git a/source/blender/python/api2_2x/windowTheme.c b/source/blender/python/api2_2x/windowTheme.c index 3bd7ac1a1c7..0cb3c08cb10 100644 --- a/source/blender/python/api2_2x/windowTheme.c +++ b/source/blender/python/api2_2x/windowTheme.c @@ -67,8 +67,12 @@ static PyObject *M_Theme_Get( PyObject * self, PyObject * args ); static char M_Theme_doc[] = "The Blender Theme module\n\n\ This module provides access to UI Theme data in Blender"; -static char M_Theme_New_doc[] = "Theme.New (name = 'New Theme'):\n\ - Return a new Theme Data object with the given type and name."; +static char M_Theme_New_doc[] = "Theme.New (name = 'New Theme',\ +theme = <default>):\n\ + Return a new Theme Data object.\n\ +(name) - string: the Theme's name, it defaults to 'New Theme';\n\ +(theme) - bpy Theme: a base Theme to copy all data from, it defaults to the\n\ +current one."; static char M_Theme_Get_doc[] = "Theme.Get (name = None):\n\ Return the theme data with the given 'name', None if not found, or\n\ diff --git a/source/blender/src/space.c b/source/blender/src/space.c index c53649c0f37..58027003a9c 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -473,7 +473,7 @@ void start_game(void) /* Restart BPY - unload the game engine modules. */ BPY_end_python(); - BPY_start_python(); + BPY_start_python(0, NULL); /* argc, argv stored there already */ BPY_post_start_python(); /* userpref path and menus init */ restore_all_scene_cfra(scene_cfra_store); diff --git a/source/creator/creator.c b/source/creator/creator.c index baf18468b12..51340b49a5c 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -440,7 +440,7 @@ int main(int argc, char **argv) } } - BPY_start_python(); + BPY_start_python(argc, argv); /** * NOTE: sound_init_audio() *must be* after start_python, @@ -452,7 +452,7 @@ int main(int argc, char **argv) } else { - BPY_start_python(); + BPY_start_python(argc, argv); // (ton) Commented out. I have no idea whats thisfor... will mail around! // SYS_WriteCommandLineInt(syshandle,"noaudio",1); |