diff options
author | Willian Padovani Germano <wpgermano@gmail.com> | 2003-09-03 08:13:08 +0400 |
---|---|---|
committer | Willian Padovani Germano <wpgermano@gmail.com> | 2003-09-03 08:13:08 +0400 |
commit | a09e5a7f2f3ae81f504106eeb62373bb99b39b51 (patch) | |
tree | 838de24f316bcf1a5a1d15d057338ef8cf2d7108 /source/blender/python/api2_2x/Registry.c | |
parent | 65746ab10a1031e4a1275c21051bce0064be5219 (diff) |
Exppython:
- Window: added .GetCursorPos()
- Lamp: updated for NoDiffuse and NoSpecular modes
- Registry: new module to handle persistent data
- vector: made it correctly print only 3 values when vec->size==3:
Fixes nmvert coords printed with a 4th 0.0 coordinate
- Text: fixed crash on startup (Python 2.3, linux):
added definition of the Text pyobject earlier, in Types.c
Diffstat (limited to 'source/blender/python/api2_2x/Registry.c')
-rw-r--r-- | source/blender/python/api2_2x/Registry.c | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/source/blender/python/api2_2x/Registry.c b/source/blender/python/api2_2x/Registry.c new file mode 100644 index 00000000000..1fc517c219f --- /dev/null +++ b/source/blender/python/api2_2x/Registry.c @@ -0,0 +1,148 @@ +/* + * + * ***** 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 */ +/*****************************************************************************/ +PyObject *M_Registry_Keys (PyObject *self) +{ + PyObject *pydict = NULL; + + if (!bpy_registryDict) + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "No Registry dictionary found!"); + + pydict = PyDict_Keys (bpy_registryDict); + + if (!pydict) + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "Registry_Keys: couldn't get keys"); + + return pydict; +} + +/*****************************************************************************/ +/* Function: M_Registry_GetKey */ +/* Python equivalent: Blender.Registry.GetKey */ +/*****************************************************************************/ +static PyObject *M_Registry_GetKey (PyObject *self, PyObject *args) +{ + PyObject *pyentry = NULL; + PyObject *pydict = NULL; + + if (!bpy_registryDict) + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "No Registry dictionary found!"); + + if (!PyArg_ParseTuple (args, "O!", &PyString_Type, &pyentry)) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected a string"); + + pydict = PyDict_GetItem (bpy_registryDict, pyentry); /* borrowed ... */ + + if (!pydict) +/* return EXPP_ReturnPyObjError (PyExc_KeyError, + "no such key in the Registry"); */ + pydict = Py_None; /* better to return None than an error */ + + Py_INCREF (pydict); /* ... so we incref it */ + /* should we copy the dict instead? */ + return pydict; +} + +/*****************************************************************************/ +/* Function: M_Registry_SetKey */ +/* Python equivalent: Blender.Registry.SetKey */ +/*****************************************************************************/ +static PyObject *M_Registry_SetKey (PyObject *self, PyObject *args) +{ + PyObject *pystr = NULL; + PyObject *pydict = NULL; + + if (!bpy_registryDict) + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "No Registry dictionary found!"); + + if (!PyArg_ParseTuple (args, "O!O!", + &PyString_Type, &pystr, &PyDict_Type, &pydict)) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected a string and a dictionary"); + + printf("dict size: %d", sizeof(*pydict)); /* debug XXX */ + + if (PyDict_SetItem (bpy_registryDict, pystr, pydict)) /* 0 on success */ + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "Registry_SetKey: couldn't update the Registry dict"); + + Py_INCREF(Py_None); + return Py_None; +} + +/*****************************************************************************/ +/* Function: M_Registry_RemoveKey */ +/* Python equivalent: Blender.Registry.RemoveKey */ +/*****************************************************************************/ +static PyObject *M_Registry_RemoveKey (PyObject *self, PyObject *args) +{ + PyObject *pystr = NULL; + + if (!bpy_registryDict) + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "No Registry dictionary found!"); + + if (!PyArg_ParseTuple (args, "O!", &PyString_Type, &pystr)) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected a string"); + + if (PyDict_DelItem (bpy_registryDict, pystr)) /* returns 0 on success */ + return EXPP_ReturnPyObjError (PyExc_KeyError, + "no such key in the Registry"); + + Py_INCREF (Py_None); + return Py_None; +} + +/*****************************************************************************/ +/* Function: Registry_Init */ +/*****************************************************************************/ +PyObject *Registry_Init (void) +{ + PyObject *submodule; + + submodule = Py_InitModule3("Blender.Registry", M_Registry_methods, + M_Registry_doc); + + return submodule; +} + |