2003-09-03 04:13:08 +00:00
|
|
|
/*
|
2004-09-18 18:47:03 +00:00
|
|
|
* $Id$
|
2003-09-03 04:13:08 +00:00
|
|
|
*
|
|
|
|
|
* ***** 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): Willian P. Germano
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Registry.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: M_Registry_Keys */
|
|
|
|
|
/* Python equivalent: Blender.Registry.Keys */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *M_Registry_Keys( PyObject * self )
|
2003-09-03 04:13:08 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *pydict = NULL;
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !bpy_registryDict )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"No Registry dictionary found!" );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
pydict = PyDict_Keys( bpy_registryDict );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !pydict )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"Registry_Keys: couldn't get keys" );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return pydict;
|
2003-09-03 04:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: M_Registry_GetKey */
|
|
|
|
|
/* Python equivalent: Blender.Registry.GetKey */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Registry_GetKey( PyObject * self, PyObject * args )
|
2003-09-03 04:13:08 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *pyentry = NULL;
|
|
|
|
|
PyObject *pydict = NULL;
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !bpy_registryDict )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"No Registry dictionary found!" );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "O!", &PyString_Type, &pyentry ) )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
|
|
|
|
"expected a string" );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
pydict = PyDict_GetItem( bpy_registryDict, pyentry ); /* borrowed ... */
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !pydict )
|
2003-09-03 04:13:08 +00:00
|
|
|
/* return EXPP_ReturnPyObjError (PyExc_KeyError,
|
|
|
|
|
"no such key in the Registry"); */
|
2004-09-25 20:30:40 +00:00
|
|
|
pydict = Py_None; /* better to return None than an error */
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( pydict ); /* ... so we incref it */
|
|
|
|
|
/* should we copy the dict instead? */
|
|
|
|
|
return pydict;
|
2003-09-03 04:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: M_Registry_SetKey */
|
|
|
|
|
/* Python equivalent: Blender.Registry.SetKey */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Registry_SetKey( PyObject * self, PyObject * args )
|
2003-09-03 04:13:08 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *pystr = NULL;
|
|
|
|
|
PyObject *pydict = NULL;
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !bpy_registryDict )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"No Registry dictionary found!" );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "O!O!",
|
|
|
|
|
&PyString_Type, &pystr, &PyDict_Type,
|
|
|
|
|
&pydict ) )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
|
|
|
|
"expected a string and a dictionary" );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( PyDict_SetItem( bpy_registryDict, pystr, pydict ) ) /* 0 on success */
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"Registry_SetKey: couldn't update the Registry dict" );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
|
|
|
|
return Py_None;
|
2003-09-03 04:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: M_Registry_RemoveKey */
|
|
|
|
|
/* Python equivalent: Blender.Registry.RemoveKey */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Registry_RemoveKey( PyObject * self, PyObject * args )
|
2003-09-03 04:13:08 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *pystr = NULL;
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !bpy_registryDict )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"No Registry dictionary found!" );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "O!", &PyString_Type, &pystr ) )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
|
|
|
|
"expected a string" );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( PyDict_DelItem( bpy_registryDict, pystr ) ) /* returns 0 on success */
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_KeyError,
|
|
|
|
|
"no such key in the Registry" );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2003-09-03 04:13:08 +00:00
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: Registry_Init */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Registry_Init( void )
|
2003-09-03 04:13:08 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *submodule;
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
submodule = Py_InitModule3( "Blender.Registry", M_Registry_methods,
|
|
|
|
|
M_Registry_doc );
|
2003-09-03 04:13:08 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return submodule;
|
2003-09-03 04:13:08 +00:00
|
|
|
}
|