2010-01-31 23:41:46 +00:00
/**
2010-03-21 01:14:04 +00:00
* $ Id $
2010-01-31 23:41:46 +00:00
*
* * * * * * 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 ,
2010-02-12 13:34:04 +00:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2010-01-31 23:41:46 +00:00
*
* Contributor ( s ) : Campbell Barton
*
* * * * * * END GPL LICENSE BLOCK * * * * *
*/
# include "bpy_app.h"
2010-03-14 17:18:36 +00:00
# include "BLI_path_util.h"
2010-01-31 23:41:46 +00:00
# include "BKE_blender.h"
# include "BKE_global.h"
# include "structseq.h"
# ifdef BUILD_DATE
2010-03-14 17:18:36 +00:00
extern char build_date [ ] ;
extern char build_time [ ] ;
extern char build_rev [ ] ;
extern char build_platform [ ] ;
extern char build_type [ ] ;
2010-01-31 23:41:46 +00:00
# endif
static PyTypeObject BlenderAppType ;
static PyStructSequence_Field app_info_fields [ ] = {
{ " version " , " The Blender version as a tuple of 3 numbers. eg. (2, 50, 11) " } ,
2010-02-11 02:03:18 +00:00
{ " version_string " , " The Blender version formatted as a string " } ,
{ " binary_path " , " The location of blenders executable, useful for utilities that spawn new instances " } ,
2010-05-18 15:57:51 +00:00
{ " background " , " Boolean, True when blender is running without a user interface (started with -b) " } ,
2010-01-31 23:41:46 +00:00
/* buildinfo */
2010-02-11 02:03:18 +00:00
{ " build_date " , " The date this blender instance was built " } ,
{ " build_time " , " The time this blender instance was built " } ,
{ " build_revision " , " The subversion revision this blender instance was built with " } ,
{ " build_platform " , " The platform this blender instance was built for " } ,
2010-01-31 23:41:46 +00:00
{ " build_type " , " The type of build (Release, Debug) " } ,
{ 0 }
} ;
static PyStructSequence_Desc app_info_desc = {
" bpy.app " , /* name */
" This module contains application values that remain unchanged during runtime. " , /* doc */
app_info_fields , /* fields */
2010-05-18 15:57:51 +00:00
( sizeof ( app_info_fields ) / sizeof ( PyStructSequence_Field ) ) - 1
2010-01-31 23:41:46 +00:00
} ;
static PyObject * make_app_info ( void )
{
extern char bprogname [ ] ; /* argv[0] from creator.c */
PyObject * app_info ;
int pos = 0 ;
app_info = PyStructSequence_New ( & BlenderAppType ) ;
if ( app_info = = NULL ) {
return NULL ;
}
# define SetIntItem(flag) \
PyStructSequence_SET_ITEM ( app_info , pos + + , PyLong_FromLong ( flag ) )
2010-02-12 21:45:47 +00:00
# define SetStrItem(str) \
PyStructSequence_SET_ITEM ( app_info , pos + + , PyUnicode_FromString ( str ) )
2010-01-31 23:41:46 +00:00
# define SetObjItem(obj) \
PyStructSequence_SET_ITEM ( app_info , pos + + , obj )
SetObjItem ( Py_BuildValue ( " (iii) " , BLENDER_VERSION / 100 , BLENDER_VERSION % 100 , BLENDER_SUBVERSION ) ) ;
SetObjItem ( PyUnicode_FromFormat ( " %d.%02d (sub %d) " , BLENDER_VERSION / 100 , BLENDER_VERSION % 100 , BLENDER_SUBVERSION ) ) ;
SetStrItem ( bprogname ) ;
2010-05-18 15:57:51 +00:00
SetObjItem ( PyBool_FromLong ( G . background ) ) ;
2010-01-31 23:41:46 +00:00
/* build info */
2010-02-28 22:48:50 +00:00
# ifdef BUILD_DATE
2010-03-14 17:18:36 +00:00
SetStrItem ( build_date ) ;
SetStrItem ( build_time ) ;
SetStrItem ( build_rev ) ;
SetStrItem ( build_platform ) ;
SetStrItem ( build_type ) ;
2010-02-28 22:48:50 +00:00
# else
2010-10-13 00:08:24 +00:00
SetStrItem ( " Unknown " ) ;
SetStrItem ( " Unknown " ) ;
SetStrItem ( " Unknown " ) ;
SetStrItem ( " Unknown " ) ;
SetStrItem ( " Unknown " ) ;
2010-02-28 22:48:50 +00:00
# endif
2010-01-31 23:41:46 +00:00
# undef SetIntItem
# undef SetStrItem
# undef SetObjItem
if ( PyErr_Occurred ( ) ) {
Py_CLEAR ( app_info ) ;
return NULL ;
}
return app_info ;
}
2010-10-12 23:47:43 +00:00
/* a few getsets because it makes sense for them to be in bpy.app even though
* they are not static */
static PyObject * bpy_app_debug_get ( PyObject * self , void * closure )
{
( void ) ( self ) ;
( void ) ( closure ) ;
return PyBool_FromLong ( G . f & G_DEBUG ) ;
}
static int bpy_app_debug_set ( PyObject * self , PyObject * value , void * closure )
{
int param = PyObject_IsTrue ( value ) ;
( void ) ( self ) ;
( void ) ( closure ) ;
if ( param < 0 ) {
PyErr_SetString ( PyExc_TypeError , " bpy.app.debug can only be True/False " ) ;
return - 1 ;
}
if ( param ) G . f | = G_DEBUG ;
else G . f & = ~ G_DEBUG ;
return 0 ;
}
static PyObject * bpy_app_tempdir_get ( PyObject * self , void * closure )
{
extern char btempdir [ ] ;
( void ) ( self ) ;
( void ) ( closure ) ;
return PyUnicode_FromString ( btempdir ) ;
}
PyGetSetDef bpy_app_debug_getset = { " debug " , bpy_app_debug_get , bpy_app_debug_set , " Boolean, set when blender is running in debug mode (started with -d) " , NULL } ;
PyGetSetDef bpy_app_tempdir_getset = { " tempdir " , bpy_app_tempdir_get , NULL , " String, the temp directory used by blender (read-only) " , NULL } ;
static void py_struct_seq_getset_init ( void )
{
/* tricky dynamic members, not to py-spec! */
PyDict_SetItemString ( BlenderAppType . tp_dict , bpy_app_debug_getset . name , PyDescr_NewGetSet ( & BlenderAppType , & bpy_app_debug_getset ) ) ;
PyDict_SetItemString ( BlenderAppType . tp_dict , bpy_app_tempdir_getset . name , PyDescr_NewGetSet ( & BlenderAppType , & bpy_app_tempdir_getset ) ) ;
}
/* end dynamic bpy.app */
2010-01-31 23:41:46 +00:00
PyObject * BPY_app_struct ( void )
{
PyObject * ret ;
2010-10-12 23:47:43 +00:00
2010-01-31 23:41:46 +00:00
PyStructSequence_InitType ( & BlenderAppType , & app_info_desc ) ;
ret = make_app_info ( ) ;
/* prevent user from creating new instances */
BlenderAppType . tp_init = NULL ;
BlenderAppType . tp_new = NULL ;
2010-10-12 23:47:43 +00:00
/* kindof a hack ontop of PyStructSequence */
py_struct_seq_getset_init ( ) ;
2010-01-31 23:49:04 +00:00
return ret ;
2010-01-31 23:41:46 +00:00
}
2010-10-12 23:47:43 +00:00