PyAPI.
moved bpy into bpy.data and bpy will be eventually replace the root level 'Blender' module. currently we have bpy.library bpy.config and bpy.data
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
#include "api2_2x/Draw.h"
|
||||
#include "api2_2x/Object.h"
|
||||
#include "api2_2x/Registry.h"
|
||||
#include "api2_2x/BPyModule.h" /* for the "bpy" default module */
|
||||
#include "api2_2x/bpy.h" /* for the new "bpy" module */
|
||||
|
||||
/* for scriptlinks */
|
||||
#include "DNA_lamp_types.h"
|
||||
@@ -81,7 +81,7 @@
|
||||
* choose to preserve after they are executed, so user changes can be
|
||||
* restored next time the script is used. Check the Blender.Registry module.
|
||||
*/
|
||||
//#include "api2_2x/Registry.h"
|
||||
/*#include "api2_2x/Registry.h" */
|
||||
|
||||
/* for pydrivers (ipo drivers defined by one-line Python expressions) */
|
||||
PyObject *bpy_pydriver_Dict = NULL;
|
||||
@@ -118,7 +118,7 @@ int setup_armature_weakrefs()
|
||||
|
||||
static struct _inittab BPy_Inittab_Modules[] = {
|
||||
{"Blender", M_Blender_Init},
|
||||
{"bpy", M_BPy_Init},
|
||||
{"bpy", m_bpy_init},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
85
source/blender/python/api2_2x/bpy.c
Normal file
85
source/blender/python/api2_2x/bpy.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* $Id$
|
||||
* ***** BEGIN GPL/BL DUAL 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. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten, Willian P. Germano, Joseph Gilbert,
|
||||
* Campbell Barton
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* for open, close in Blender_Load */
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_main.h"
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
#include "bpy.h"
|
||||
#include "bpy_data.h"
|
||||
#include "bpy_config.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global variables */
|
||||
/*****************************************************************************/
|
||||
PyObject *g_bpydict;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: initBlender */
|
||||
/*****************************************************************************/
|
||||
|
||||
void m_bpy_init(void)
|
||||
{
|
||||
PyObject *module;
|
||||
PyObject *dict;
|
||||
|
||||
/* G.scene should only aver be NULL if blender is executed in
|
||||
background mode, not loading a blend file and executing a python script eg.
|
||||
blender -P somescript.py -b
|
||||
The if below solves the segfaults that happen when python runs and
|
||||
G.scene is NULL */
|
||||
if(G.background && G.main->scene.first==NULL) {
|
||||
Scene *sce= add_scene("1");
|
||||
/*set_scene(sce);*/ /* causes a crash */
|
||||
G.scene= sce;
|
||||
}
|
||||
|
||||
module = Py_InitModule3("bpy", NULL, "The main bpy module");
|
||||
|
||||
types_InitAll(); /* set all our pytypes to &PyType_Type */
|
||||
|
||||
dict = PyModule_GetDict(module);
|
||||
g_bpydict = dict;
|
||||
|
||||
PyModule_AddObject( module, "config", Config_CreatePyObject() );
|
||||
PyDict_SetItemString( dict, "data", Data_Init());
|
||||
PyDict_SetItemString( dict, "libraries", Library_Init( ) );
|
||||
|
||||
}
|
||||
41
source/blender/python/api2_2x/bpy.h
Normal file
41
source/blender/python/api2_2x/bpy.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL/BL DUAL 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. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten, Willian P. Germano
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_BPYMOD_H
|
||||
#define EXPP_BPYMOD_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
extern PyObject *g_bpydict;
|
||||
void m_bpy_init( void );
|
||||
|
||||
#endif /* EXPP_BPYMOD_H */
|
||||
@@ -32,8 +32,8 @@
|
||||
|
||||
/* python types */
|
||||
#include "DNA_userdef_types.h"
|
||||
#include "gen_utils.h"
|
||||
#include "Config.h"
|
||||
#include "../api2_2x/gen_utils.h"
|
||||
#include "bpy_config.h"
|
||||
|
||||
enum conf_consts {
|
||||
/*string*/
|
||||
@@ -30,8 +30,8 @@
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_CONFIG_H
|
||||
#define EXPP_CONFIG_H
|
||||
#ifndef EXPP_BPY_CONFIG_H
|
||||
#define EXPP_BPY_CONFIG_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
@@ -49,4 +49,4 @@ typedef struct {
|
||||
PyObject *Config_CreatePyObject();
|
||||
|
||||
|
||||
#endif /* EXPP_CONFIG_H */
|
||||
#endif /* EXPP_BPY_CONFIG_H */
|
||||
@@ -30,7 +30,7 @@
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "BPyModule.h"
|
||||
#include "bpy_data.h"
|
||||
|
||||
#include "MEM_guardedalloc.h" /* for MEM_callocN */
|
||||
#include "DNA_space_types.h" /* SPACE_VIEW3D, SPACE_SEQ */
|
||||
@@ -88,7 +88,6 @@
|
||||
#include "Camera.h"
|
||||
#include "Armature.h"
|
||||
#include "Lamp.h"
|
||||
/*#include " CurNurb.h" do we need this ? */
|
||||
#include "Curve.h"
|
||||
#include "NMesh.h"
|
||||
#include "Mesh.h"
|
||||
@@ -107,7 +106,7 @@
|
||||
#include "Scene.h"
|
||||
#include "Library.h"
|
||||
|
||||
#include "Config.h" /* config pydata */
|
||||
#include "bpy_config.h" /* config pydata */
|
||||
|
||||
/* used only for texts.active */
|
||||
#include "BIF_screen.h"
|
||||
@@ -796,7 +795,7 @@ PyTypeObject LibBlockSeq_Type = {
|
||||
|
||||
static char M_BPy_Init_doc[] = "The bpy module";
|
||||
|
||||
void M_BPy_Init( void )
|
||||
PyObject * Data_Init( void )
|
||||
{
|
||||
PyObject *module;
|
||||
PyObject *dict;
|
||||
@@ -806,32 +805,28 @@ void M_BPy_Init( void )
|
||||
PyType_Ready( &Config_Type );
|
||||
|
||||
/*submodule = Py_InitModule3( "Blender.Main", NULL, M_Main_doc );*/
|
||||
module = Py_InitModule3( "bpy", NULL, M_BPy_Init_doc );
|
||||
module = Py_InitModule3( "bpy.data", NULL, "The bpy.data submodule" );
|
||||
dict = PyModule_GetDict( module );
|
||||
|
||||
PyDict_SetItemString( dict, "libraries", Library_Init( ) );
|
||||
|
||||
/* Python Data Types */
|
||||
PyModule_AddObject( module, "scenes", LibBlockSeq_CreatePyObject(NULL, ID_SCE) );
|
||||
PyModule_AddObject( module, "objects", LibBlockSeq_CreatePyObject(NULL, ID_OB) );
|
||||
PyModule_AddObject( module, "meshes", LibBlockSeq_CreatePyObject(NULL, ID_ME) );
|
||||
PyModule_AddObject( module, "curves", LibBlockSeq_CreatePyObject(NULL, ID_CU) );
|
||||
PyModule_AddObject( module, "metaballs", LibBlockSeq_CreatePyObject(NULL, ID_MB) );
|
||||
PyModule_AddObject( module, "materials", LibBlockSeq_CreatePyObject(NULL, ID_MA) );
|
||||
PyModule_AddObject( module, "textures", LibBlockSeq_CreatePyObject(NULL, ID_TE) );
|
||||
PyModule_AddObject( module, "images", LibBlockSeq_CreatePyObject(NULL, ID_IM) );
|
||||
PyModule_AddObject( module, "lattices", LibBlockSeq_CreatePyObject(NULL, ID_LT) );
|
||||
PyModule_AddObject( module, "lamps", LibBlockSeq_CreatePyObject(NULL, ID_LA) );
|
||||
PyModule_AddObject( module, "cameras", LibBlockSeq_CreatePyObject(NULL, ID_CA) );
|
||||
PyModule_AddObject( module, "ipos", LibBlockSeq_CreatePyObject(NULL, ID_IP) );
|
||||
PyModule_AddObject( module, "worlds", LibBlockSeq_CreatePyObject(NULL, ID_WO) );
|
||||
PyModule_AddObject( module, "fonts", LibBlockSeq_CreatePyObject(NULL, ID_VF) );
|
||||
PyModule_AddObject( module, "texts", LibBlockSeq_CreatePyObject(NULL, ID_TXT) );
|
||||
PyModule_AddObject( module, "sounds", LibBlockSeq_CreatePyObject(NULL, ID_SO) );
|
||||
PyModule_AddObject( module, "groups", LibBlockSeq_CreatePyObject(NULL, ID_GR) );
|
||||
PyModule_AddObject( module, "armatures", LibBlockSeq_CreatePyObject(NULL, ID_AR) );
|
||||
PyModule_AddObject( module, "actions", LibBlockSeq_CreatePyObject(NULL, ID_AC) );
|
||||
|
||||
/* Other Types */
|
||||
PyModule_AddObject( module, "config", Config_CreatePyObject() );
|
||||
PyModule_AddObject( module, "scenes", LibBlockSeq_CreatePyObject(NULL, ID_SCE) );
|
||||
PyModule_AddObject( module, "objects", LibBlockSeq_CreatePyObject(NULL, ID_OB) );
|
||||
PyModule_AddObject( module, "meshes", LibBlockSeq_CreatePyObject(NULL, ID_ME) );
|
||||
PyModule_AddObject( module, "curves", LibBlockSeq_CreatePyObject(NULL, ID_CU) );
|
||||
PyModule_AddObject( module, "metaballs",LibBlockSeq_CreatePyObject(NULL, ID_MB) );
|
||||
PyModule_AddObject( module, "materials",LibBlockSeq_CreatePyObject(NULL, ID_MA) );
|
||||
PyModule_AddObject( module, "textures", LibBlockSeq_CreatePyObject(NULL, ID_TE) );
|
||||
PyModule_AddObject( module, "images", LibBlockSeq_CreatePyObject(NULL, ID_IM) );
|
||||
PyModule_AddObject( module, "lattices", LibBlockSeq_CreatePyObject(NULL, ID_LT) );
|
||||
PyModule_AddObject( module, "lamps", LibBlockSeq_CreatePyObject(NULL, ID_LA) );
|
||||
PyModule_AddObject( module, "cameras", LibBlockSeq_CreatePyObject(NULL, ID_CA) );
|
||||
PyModule_AddObject( module, "ipos", LibBlockSeq_CreatePyObject(NULL, ID_IP) );
|
||||
PyModule_AddObject( module, "worlds", LibBlockSeq_CreatePyObject(NULL, ID_WO) );
|
||||
PyModule_AddObject( module, "fonts", LibBlockSeq_CreatePyObject(NULL, ID_VF) );
|
||||
PyModule_AddObject( module, "texts", LibBlockSeq_CreatePyObject(NULL, ID_TXT) );
|
||||
PyModule_AddObject( module, "sounds", LibBlockSeq_CreatePyObject(NULL, ID_SO) );
|
||||
PyModule_AddObject( module, "groups", LibBlockSeq_CreatePyObject(NULL, ID_GR) );
|
||||
PyModule_AddObject( module, "armatures",LibBlockSeq_CreatePyObject(NULL, ID_AR) );
|
||||
PyModule_AddObject( module, "actions", LibBlockSeq_CreatePyObject(NULL, ID_AC) );
|
||||
return module;
|
||||
}
|
||||
@@ -29,8 +29,8 @@
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_BPYMODULE_H
|
||||
#define EXPP_BPYMODULE_H
|
||||
#ifndef EXPP_BPYDATA_H
|
||||
#define EXPP_BPYDATA_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_listBase.h"
|
||||
@@ -50,6 +50,6 @@ typedef struct {
|
||||
} BPy_LibBlockSeq;
|
||||
|
||||
|
||||
void M_BPy_Init( void );
|
||||
PyObject * Data_Init( void );
|
||||
|
||||
#endif /* EXPP_MAIN_H */
|
||||
#endif /* EXPP_BPYDATA_H */
|
||||
Reference in New Issue
Block a user