2008-11-29 13:36:08 +00:00
|
|
|
/**
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* ***** 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,
|
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Campbell Barton
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
#ifndef BPY_RNA_H
|
|
|
|
|
#define BPY_RNA_H
|
|
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_types.h"
|
2008-12-29 03:24:13 +00:00
|
|
|
#include "BKE_idprop.h"
|
2008-11-29 13:36:08 +00:00
|
|
|
|
2008-12-01 16:59:18 +00:00
|
|
|
extern PyTypeObject pyrna_struct_Type;
|
|
|
|
|
extern PyTypeObject pyrna_prop_Type;
|
2009-04-09 13:20:48 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
#define BPy_StructRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_struct_Type))
|
|
|
|
|
#define BPy_StructRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_struct_Type)
|
|
|
|
|
#define BPy_PropertyRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_prop_Type))
|
|
|
|
|
#define BPy_PropertyRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_prop_Type)
|
2009-03-11 17:28:37 +00:00
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
void * _a;
|
|
|
|
|
void * _b;
|
|
|
|
|
PyTypeObject *py_type;
|
|
|
|
|
} BPy_StructFakeType;
|
|
|
|
|
|
|
|
|
|
|
2008-11-29 13:36:08 +00:00
|
|
|
typedef struct {
|
2009-01-29 09:38:52 +00:00
|
|
|
PyObject_HEAD /* required python macro */
|
2008-11-29 13:36:08 +00:00
|
|
|
PointerRNA ptr;
|
2009-01-08 15:29:09 +00:00
|
|
|
int freeptr; /* needed in some cases if ptr.data is created on the fly, free when deallocing */
|
2008-11-29 13:36:08 +00:00
|
|
|
} BPy_StructRNA;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2009-01-29 09:38:52 +00:00
|
|
|
PyObject_HEAD /* required python macro */
|
2008-11-29 13:36:08 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
} BPy_PropertyRNA;
|
|
|
|
|
|
2009-03-21 06:55:30 +00:00
|
|
|
/* cheap trick */
|
|
|
|
|
#define BPy_BaseTypeRNA BPy_PropertyRNA
|
|
|
|
|
|
2008-11-29 13:36:08 +00:00
|
|
|
PyObject *BPY_rna_module( void );
|
2009-03-13 07:50:07 +00:00
|
|
|
/*PyObject *BPY_rna_doc( void );*/
|
|
|
|
|
PyObject *BPY_rna_types( void );
|
2009-06-18 19:51:22 +00:00
|
|
|
PyObject *BPY_rna_props( void );
|
2008-11-29 13:36:08 +00:00
|
|
|
|
|
|
|
|
PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr );
|
|
|
|
|
PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop );
|
|
|
|
|
|
2008-12-25 10:48:36 +00:00
|
|
|
/* operators also need this to set args */
|
2009-04-16 13:21:18 +00:00
|
|
|
int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value);
|
PyRNA
- Support for python to convert a PyObject into a collection (uses a list of dicts - quite verbose :/)
- Operators can now take collection args when called from python.
- Support for printing operators that use collections (macro recording).
- Added RNA_pointer_as_string which prints all pointer prop values as a python dict.
Example that can run in the in test.py (F7 key)
bpy.ops.VIEW3D_OT_select_lasso(path=[{"loc":(0, 0), "time":0}, {"loc":(1000, 0), "time":0}, {"loc":(1000, 1000), "time":0}], type='SELECT')
for some reason lasso locations always print as 0,0. Need to look into why this is.
2009-06-05 12:48:58 +00:00
|
|
|
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefix);
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
|
2009-04-07 00:49:39 +00:00
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
/* functions for setting up new props - experemental */
|
|
|
|
|
PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw);
|
|
|
|
|
PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw);
|
|
|
|
|
PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw);
|
2009-06-18 19:51:22 +00:00
|
|
|
PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw);
|
2009-03-16 15:54:43 +00:00
|
|
|
|
2009-04-19 13:37:59 +00:00
|
|
|
/* function for registering types */
|
|
|
|
|
PyObject *pyrna_basetype_register(PyObject *self, PyObject *args);
|
|
|
|
|
PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *args);
|
2009-03-16 15:54:43 +00:00
|
|
|
|
2008-11-29 13:36:08 +00:00
|
|
|
#endif
|