Merged changes in the trunk up to revision 27226 (Blender 2.5 alpha 2 release point).
This commit is contained in:
@@ -43,6 +43,9 @@ import bpy
|
||||
import rna_info
|
||||
reload(rna_info)
|
||||
|
||||
EXAMPLE_SET = set()
|
||||
EXAMPLE_SET_USED = set()
|
||||
|
||||
def range_str(val):
|
||||
if val < -10000000: return '-inf'
|
||||
if val > 10000000: return 'inf'
|
||||
@@ -51,6 +54,16 @@ def range_str(val):
|
||||
else:
|
||||
return str(val)
|
||||
|
||||
|
||||
def write_example_ref(ident, fw, example_id, ext=".py"):
|
||||
if example_id in EXAMPLE_SET:
|
||||
fw("%s.. literalinclude:: ../examples/%s%s\n\n" % (ident, example_id, ext))
|
||||
EXAMPLE_SET_USED.add(example_id)
|
||||
else:
|
||||
if bpy.app.debug:
|
||||
print("\tskipping example:", example_id)
|
||||
|
||||
|
||||
def write_indented_lines(ident, fn, text, strip=True):
|
||||
if text is None:
|
||||
return
|
||||
@@ -152,6 +165,8 @@ def pymodule2sphinx(BASEPATH, module_name, module, title):
|
||||
# Note, may contain sphinx syntax, dont mangle!
|
||||
fw(module.__doc__.strip())
|
||||
fw("\n\n")
|
||||
|
||||
write_example_ref("", fw, module_name)
|
||||
|
||||
# write members of the module
|
||||
# only tested with PyStructs which are not exactly modules
|
||||
@@ -188,6 +203,7 @@ def pymodule2sphinx(BASEPATH, module_name, module, title):
|
||||
if value.__doc__:
|
||||
write_indented_lines(" ", fw, value.__doc__, False)
|
||||
fw("\n")
|
||||
write_example_ref(" ", fw, module_name + "." + attribute)
|
||||
|
||||
for key in sorted(value.__dict__.keys()):
|
||||
if key.startswith("__"):
|
||||
@@ -197,6 +213,7 @@ def pymodule2sphinx(BASEPATH, module_name, module, title):
|
||||
if descr.__doc__:
|
||||
fw(" .. attribute:: %s\n\n" % key)
|
||||
write_indented_lines(" ", fw, descr.__doc__, False)
|
||||
write_example_ref(" ", fw, module_name + "." + attribute + "." + key)
|
||||
fw("\n")
|
||||
|
||||
for key in sorted(value.__dict__.keys()):
|
||||
@@ -206,6 +223,7 @@ def pymodule2sphinx(BASEPATH, module_name, module, title):
|
||||
if type(descr) == MethodDescriptorType: # GetSetDescriptorType, GetSetDescriptorType's are not documented yet
|
||||
if descr.__doc__:
|
||||
write_indented_lines(" ", fw, descr.__doc__, False)
|
||||
write_example_ref(" ", fw, module_name + "." + attribute + "." + key)
|
||||
fw("\n")
|
||||
|
||||
fw("\n\n")
|
||||
@@ -227,8 +245,8 @@ def rna2sphinx(BASEPATH):
|
||||
filepath = os.path.join(BASEPATH, "conf.py")
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
|
||||
|
||||
|
||||
version_string = bpy.app.version_string.split("(")[0]
|
||||
if bpy.app.build_revision != "Unknown":
|
||||
version_string = version_string + " r" + bpy.app.build_revision
|
||||
@@ -236,8 +254,10 @@ def rna2sphinx(BASEPATH):
|
||||
fw("project = 'Blender 3D'\n")
|
||||
# fw("master_doc = 'index'\n")
|
||||
fw("copyright = u'Blender Foundation'\n")
|
||||
fw("version = '%s'\n" % version_string)
|
||||
fw("release = '%s'\n" % version_string)
|
||||
fw("version = '%s - UNSTABLE API'\n" % version_string)
|
||||
fw("release = '%s - UNSTABLE API'\n" % version_string)
|
||||
# not helpful since the source us generated, adds to upload size.
|
||||
fw("html_copy_source = False\n")
|
||||
fw("\n")
|
||||
# needed for latex, pdf gen
|
||||
fw("latex_documents = [ ('contents', 'contents.tex', 'Blender Index', 'Blender Foundation', 'manual'), ]\n")
|
||||
@@ -257,6 +277,21 @@ def rna2sphinx(BASEPATH):
|
||||
fw("\n")
|
||||
fw("An introduction to blender and python can be found at <http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro>\n")
|
||||
fw("\n")
|
||||
fw(".. warning:: The Python API in Blender is **UNSTABLE**, It should only be used for testing, any script written now may break in future releases.\n")
|
||||
fw(" \n")
|
||||
fw(" The following areas are subject to change.\n")
|
||||
fw(" * operator names and arguments\n")
|
||||
fw(" * function calls with the data api (any function calls with values accessed from bpy.data), including functions for importing and exporting meshes\n")
|
||||
fw(" * class registration (Operator, Panels, Menus, Headers)\n")
|
||||
fw(" * modules: bpy.props, blf)\n")
|
||||
fw(" * members in the bpy.context have to be reviewed\n")
|
||||
fw(" * python defined modal operators, especially drawing callbacks are highly experemental\n")
|
||||
fw(" \n")
|
||||
fw(" These parts of the API are relatively stable and are unlikely to change significantly\n")
|
||||
fw(" * data API, access to attributes of blender data such as mesh verts, material color, timeline frames and scene objects\n")
|
||||
fw(" * user interface functions for defining buttons, creation of menus, headers, panels\n")
|
||||
fw(" * modules: bgl, Mathutils and Geometry\n")
|
||||
fw("\n")
|
||||
fw(".. toctree::\n")
|
||||
fw(" :maxdepth: 1\n\n")
|
||||
fw(" bpy.ops.rst\n\n")
|
||||
@@ -270,11 +305,10 @@ def rna2sphinx(BASEPATH):
|
||||
fw(" bpy.props.rst\n\n")
|
||||
|
||||
fw(" Mathutils.rst\n\n")
|
||||
|
||||
fw(" blf.rst\n\n")
|
||||
file.close()
|
||||
|
||||
|
||||
|
||||
# internal modules
|
||||
filepath = os.path.join(BASEPATH, "bpy.ops.rst")
|
||||
file = open(filepath, "w")
|
||||
@@ -313,7 +347,9 @@ def rna2sphinx(BASEPATH):
|
||||
pymodule2sphinx(BASEPATH, "Mathutils", module, "Math Types & Utilities (Mathutils)")
|
||||
del module
|
||||
|
||||
|
||||
import blf as module
|
||||
pymodule2sphinx(BASEPATH, "blf", module, "Blender Font Drawing (blf)")
|
||||
del module
|
||||
|
||||
if 0:
|
||||
filepath = os.path.join(BASEPATH, "bpy.rst")
|
||||
@@ -498,14 +534,27 @@ if __name__ == '__main__':
|
||||
|
||||
path_in = 'source/blender/python/doc/sphinx-in'
|
||||
path_out = 'source/blender/python/doc/sphinx-in'
|
||||
path_examples = 'source/blender/python/doc/examples'
|
||||
|
||||
shutil.rmtree(path_in, True)
|
||||
shutil.rmtree(path_out, True)
|
||||
|
||||
for f in os.listdir(path_examples):
|
||||
if f.endswith(".py"):
|
||||
EXAMPLE_SET.add(os.path.splitext(f)[0])
|
||||
|
||||
rna2sphinx(path_in)
|
||||
|
||||
# for fast module testing
|
||||
# os.system("rm source/blender/python/doc/sphinx-in/bpy.types.*.rst")
|
||||
# os.system("rm source/blender/python/doc/sphinx-in/bpy.ops.*.rst")
|
||||
|
||||
EXAMPLE_SET_UNUSED = EXAMPLE_SET - EXAMPLE_SET_USED
|
||||
if EXAMPLE_SET_UNUSED:
|
||||
print("\nUnused examples found in '%s'..." % path_examples)
|
||||
for f in EXAMPLE_SET_UNUSED:
|
||||
print(" %s.py" % f)
|
||||
print(" %d total\n" % len(EXAMPLE_SET_UNUSED))
|
||||
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
@@ -75,6 +75,29 @@ PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop )
|
||||
array->prop = prop;
|
||||
return (PyObject*) array;
|
||||
}
|
||||
case IDP_IDPARRAY: /* this could be better a internal type */
|
||||
{
|
||||
PyObject *seq = PyList_New(prop->len), *wrap;
|
||||
IDProperty *array= IDP_IDPArray(prop);
|
||||
int i;
|
||||
|
||||
if (!seq) {
|
||||
PyErr_Format( PyExc_RuntimeError, "BPy_IDGroup_MapDataToPy, IDP_IDPARRAY: PyList_New(%d) failed", prop->len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<prop->len; i++) {
|
||||
wrap= BPy_IDGroup_WrapData(id, array++);
|
||||
|
||||
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
|
||||
return NULL;
|
||||
|
||||
PyList_SET_ITEM(seq, i, wrap);
|
||||
}
|
||||
|
||||
return seq;
|
||||
}
|
||||
/* case IDP_IDPARRAY: TODO */
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
@@ -210,6 +233,46 @@ static PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
|
||||
}
|
||||
|
||||
/*returns NULL on success, error string on failure*/
|
||||
static int idp_sequence_type(PyObject *seq)
|
||||
{
|
||||
PyObject *item;
|
||||
int type= IDP_INT;
|
||||
|
||||
int i, len = PySequence_Length(seq);
|
||||
for (i=0; i < len; i++) {
|
||||
item = PySequence_GetItem(seq, i);
|
||||
if (PyFloat_Check(item)) {
|
||||
if(type == IDP_IDPARRAY) { /* mixed dict/int */
|
||||
Py_DECREF(item);
|
||||
return -1;
|
||||
}
|
||||
type= IDP_DOUBLE;
|
||||
}
|
||||
else if (PyLong_Check(item)) {
|
||||
if(type == IDP_IDPARRAY) { /* mixed dict/int */
|
||||
Py_DECREF(item);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (PyMapping_Check(item)) {
|
||||
if(i != 0 && (type != IDP_IDPARRAY)) { /* mixed dict/int */
|
||||
Py_DECREF(item);
|
||||
return -1;
|
||||
}
|
||||
type= IDP_IDPARRAY;
|
||||
}
|
||||
else {
|
||||
Py_XDECREF(item);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
/* note: group can be a pointer array or a group */
|
||||
char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObject *ob)
|
||||
{
|
||||
IDProperty *prop = NULL;
|
||||
@@ -231,29 +294,44 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje
|
||||
PyObject *item;
|
||||
int i;
|
||||
|
||||
if((val.array.type= idp_sequence_type(ob)) == -1)
|
||||
return "only floats, ints and dicts are allowed in ID property arrays";
|
||||
|
||||
/*validate sequence and derive type.
|
||||
we assume IDP_INT unless we hit a float
|
||||
number; then we assume it's */
|
||||
val.array.type = IDP_INT;
|
||||
val.array.len = PySequence_Length(ob);
|
||||
for (i=0; i<val.array.len; i++) {
|
||||
item = PySequence_GetItem(ob, i);
|
||||
if (PyFloat_Check(item)) val.array.type = IDP_DOUBLE;
|
||||
else if (!PyLong_Check(item)) {
|
||||
Py_XDECREF(item);
|
||||
return "only floats and ints are allowed in ID property arrays";
|
||||
}
|
||||
Py_XDECREF(item);
|
||||
}
|
||||
|
||||
prop = IDP_New(IDP_ARRAY, val, name);
|
||||
for (i=0; i<val.array.len; i++) {
|
||||
item = PySequence_GetItem(ob, i);
|
||||
if (val.array.type == IDP_INT) {
|
||||
((int*)prop->data.pointer)[i] = (int)PyLong_AsSsize_t(item);
|
||||
} else {
|
||||
val.array.len = PySequence_Length(ob);
|
||||
|
||||
switch(val.array.type) {
|
||||
case IDP_DOUBLE:
|
||||
prop = IDP_New(IDP_ARRAY, val, name);
|
||||
for (i=0; i<val.array.len; i++) {
|
||||
item = PySequence_GetItem(ob, i);
|
||||
((double*)prop->data.pointer)[i] = (float)PyFloat_AsDouble(item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
break;
|
||||
case IDP_INT:
|
||||
prop = IDP_New(IDP_ARRAY, val, name);
|
||||
for (i=0; i<val.array.len; i++) {
|
||||
item = PySequence_GetItem(ob, i);
|
||||
((int*)prop->data.pointer)[i] = (int)PyLong_AsSsize_t(item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
break;
|
||||
case IDP_IDPARRAY:
|
||||
prop= IDP_NewIDPArray(name);
|
||||
for (i=0; i<val.array.len; i++) {
|
||||
char *error;
|
||||
item = PySequence_GetItem(ob, i);
|
||||
error= BPy_IDProperty_Map_ValidateAndCreate("", prop, item);
|
||||
Py_DECREF(item);
|
||||
|
||||
if(error)
|
||||
return error;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (PyMapping_Check(ob)) {
|
||||
PyObject *keys, *vals, *key, *pval;
|
||||
@@ -294,7 +372,14 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje
|
||||
Py_XDECREF(vals);
|
||||
} else return "invalid property value";
|
||||
|
||||
IDP_ReplaceInGroup(group, prop);
|
||||
if(group->type==IDP_IDPARRAY) {
|
||||
IDP_AppendArray(group, prop);
|
||||
// IDP_FreeProperty(item); // IDP_AppendArray does a shallow copy (memcpy), only free memory
|
||||
MEM_freeN(prop);
|
||||
} else {
|
||||
IDP_ReplaceInGroup(group, prop);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -371,7 +456,7 @@ static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
|
||||
int i;
|
||||
|
||||
if (!seq) {
|
||||
PyErr_SetString( PyExc_RuntimeError, "PyList_New() failed" );
|
||||
PyErr_Format( PyExc_RuntimeError, "BPy_IDGroup_MapDataToPy, IDP_ARRAY: PyList_New(%d) failed", prop->len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -389,22 +474,37 @@ static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
case IDP_IDPARRAY:
|
||||
{
|
||||
PyObject *seq = PyList_New(prop->len), *wrap;
|
||||
IDProperty *array= IDP_IDPArray(prop);
|
||||
int i;
|
||||
|
||||
if (!seq) {
|
||||
PyErr_Format( PyExc_RuntimeError, "BPy_IDGroup_MapDataToPy, IDP_IDPARRAY: PyList_New(%d) failed", prop->len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<prop->len; i++) {
|
||||
wrap= BPy_IDGroup_MapDataToPy(array++);
|
||||
|
||||
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
|
||||
return NULL;
|
||||
|
||||
PyList_SET_ITEM(seq, i, wrap);
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
case IDP_GROUP:
|
||||
{
|
||||
PyObject *dict = PyDict_New(), *wrap;
|
||||
IDProperty *loop;
|
||||
|
||||
if (!dict) {
|
||||
PyErr_SetString( PyExc_RuntimeError, "PyDict_New() failed" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (loop=prop->data.group.first; loop; loop=loop->next) {
|
||||
wrap = BPy_IDGroup_MapDataToPy(loop);
|
||||
if (!wrap) {
|
||||
PyErr_SetString( PyExc_RuntimeError, "BPy_IDGroup_MapDataToPy() failed" );
|
||||
|
||||
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyDict_SetItemString(dict, loop->name, wrap);
|
||||
}
|
||||
@@ -412,7 +512,7 @@ static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_SetString( PyExc_RuntimeError, "eek!! a property exists with a bad type code!!!" );
|
||||
PyErr_Format(PyExc_RuntimeError, "eek!! '%s' property exists with a bad type code '%d' !!!", prop->name, prop->type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,9 +55,7 @@
|
||||
|
||||
//-------------------------DOC STRINGS ---------------------------
|
||||
static char M_Mathutils_doc[] =
|
||||
"This module provides access to matrices, eulers, quaternions and vectors.\n"
|
||||
"\n"
|
||||
".. literalinclude:: ../examples/mathutils.py\n";
|
||||
"This module provides access to matrices, eulers, quaternions and vectors.";
|
||||
|
||||
//-----------------------------METHODS----------------------------
|
||||
//-----------------quat_rotation (internal)-----------
|
||||
@@ -559,25 +557,24 @@ static PyObject *M_Mathutils_ShearMatrix(PyObject * self, PyObject * args)
|
||||
|
||||
/* Utility functions */
|
||||
|
||||
/*---------------------- EXPP_FloatsAreEqual -------------------------
|
||||
Floating point comparisons
|
||||
floatStep = number of representable floats allowable in between
|
||||
float A and float B to be considered equal. */
|
||||
int EXPP_FloatsAreEqual(float A, float B, int floatSteps)
|
||||
{
|
||||
int a, b, delta;
|
||||
assert(floatSteps > 0 && floatSteps < (4 * 1024 * 1024));
|
||||
a = *(int*)&A;
|
||||
if (a < 0)
|
||||
a = 0x80000000 - a;
|
||||
b = *(int*)&B;
|
||||
if (b < 0)
|
||||
b = 0x80000000 - b;
|
||||
delta = abs(a - b);
|
||||
if (delta <= floatSteps)
|
||||
return 1;
|
||||
return 0;
|
||||
// LomontRRDCompare4, Ever Faster Float Comparisons by Randy Dillon
|
||||
#define SIGNMASK(i) (-(int)(((unsigned int)(i))>>31))
|
||||
|
||||
int EXPP_FloatsAreEqual(float af, float bf, int maxDiff)
|
||||
{ // solid, fast routine across all platforms
|
||||
// with constant time behavior
|
||||
int ai = *(int *)(&af);
|
||||
int bi = *(int *)(&bf);
|
||||
int test = SIGNMASK(ai^bi);
|
||||
int diff, v1, v2;
|
||||
|
||||
assert((0 == test) || (0xFFFFFFFF == test));
|
||||
diff = (ai ^ (test & 0x7fffffff)) - bi;
|
||||
v1 = maxDiff + diff;
|
||||
v2 = maxDiff - diff;
|
||||
return (v1|v2) >= 0;
|
||||
}
|
||||
|
||||
/*---------------------- EXPP_VectorsAreEqual -------------------------
|
||||
Builds on EXPP_FloatsAreEqual to test vectors */
|
||||
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps)
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
* implementation. The BGL submodule "wraps" OpenGL functions and constants,
|
||||
* allowing script writers to make OpenGL calls in their Python scripts. */
|
||||
|
||||
#include "BGL.h" /*This must come first */
|
||||
#include "bgl.h" /*This must come first */
|
||||
#include <GL/glew.h>
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
@@ -1095,7 +1095,7 @@ static struct PyMethodDef BGL_methods[] = {
|
||||
|
||||
static struct PyModuleDef BGL_module_def = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"BGL", /* m_name */
|
||||
"bgl", /* m_name */
|
||||
0, /* m_doc */
|
||||
0, /* m_size */
|
||||
BGL_methods, /* m_methods */
|
||||
196
source/blender/python/generic/blf.c
Normal file
196
source/blender/python/generic/blf.c
Normal file
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* $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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
#include "blf.h"
|
||||
|
||||
#include "../../blenfont/BLF_api.h"
|
||||
|
||||
static char py_blf_position_doc[] =
|
||||
".. function:: position(x, y, z)\n"
|
||||
"\n"
|
||||
" Set the position for drawing text.";
|
||||
|
||||
static PyObject *py_blf_position(PyObject *self, PyObject *args)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "fff:BLF.position", &x, &y, &z))
|
||||
return NULL;
|
||||
|
||||
BLF_position(x, y, z);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static char py_blf_size_doc[] =
|
||||
".. function:: size(size, dpi)\n"
|
||||
"\n"
|
||||
" Set the size and dpi for drawing text.\n"
|
||||
"\n"
|
||||
" :arg size: Point size of the font.\n"
|
||||
" :type size: int\n"
|
||||
" :arg dpi: dots per inch value to use for drawing.\n"
|
||||
" :type dpi: int\n";
|
||||
|
||||
static PyObject *py_blf_size(PyObject *self, PyObject *args)
|
||||
{
|
||||
int size, dpi;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ii:BLF.size", &size, &dpi))
|
||||
return NULL;
|
||||
|
||||
BLF_size(size, dpi);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static char py_blf_aspect_doc[] =
|
||||
".. function:: aspect(aspect)\n"
|
||||
"\n"
|
||||
" Set the aspect for drawing text.\n"
|
||||
"\n"
|
||||
" :arg aspect: The aspect ratio for text drawing to use.\n"
|
||||
" :type aspect: float\n";
|
||||
|
||||
static PyObject *py_blf_aspect(PyObject *self, PyObject *args)
|
||||
{
|
||||
float aspect;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "f:BLF.aspect", &aspect))
|
||||
return NULL;
|
||||
|
||||
BLF_aspect(aspect);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static char py_blf_blur_doc[] =
|
||||
".. function:: blur(radius)\n"
|
||||
"\n"
|
||||
" Set the blur radius for drawing text.\n"
|
||||
"\n"
|
||||
" :arg radius: The radius for blurring text (in pixels).\n"
|
||||
" :type radius: int\n";
|
||||
|
||||
static PyObject *py_blf_blur(PyObject *self, PyObject *args)
|
||||
{
|
||||
int blur;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:BLF.blur", &blur))
|
||||
return NULL;
|
||||
|
||||
BLF_blur(blur);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static char py_blf_draw_doc[] =
|
||||
".. function:: draw(text)\n"
|
||||
"\n"
|
||||
" Draw text in the current context.\n"
|
||||
"\n"
|
||||
" :arg text: the text to draw.\n"
|
||||
" :type text: string\n";
|
||||
|
||||
static PyObject *py_blf_draw(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *text;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:BLF.draw", &text))
|
||||
return NULL;
|
||||
|
||||
BLF_draw(text);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static char py_blf_dimensions_doc[] =
|
||||
".. function:: dimensions(text)\n"
|
||||
"\n"
|
||||
" Return the width and hight of the text.\n"
|
||||
"\n"
|
||||
" :arg text: the text to draw.\n"
|
||||
" :type text: string\n"
|
||||
" :return: the width and height of the text.\n"
|
||||
" :rtype: tuple of 2 floats\n";
|
||||
|
||||
static PyObject *py_blf_dimensions(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *text;
|
||||
float r_width, r_height;
|
||||
PyObject *ret;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:BLF.dimensions", &text))
|
||||
return NULL;
|
||||
|
||||
BLF_width_and_height(text, &r_width, &r_height);
|
||||
|
||||
ret= PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(r_width));
|
||||
PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(r_height));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*----------------------------MODULE INIT-------------------------*/
|
||||
struct PyMethodDef BLF_methods[] = {
|
||||
{"position", (PyCFunction)py_blf_position, METH_VARARGS, py_blf_position_doc},
|
||||
{"size", (PyCFunction) py_blf_size, METH_VARARGS, py_blf_size_doc},
|
||||
{"aspect", (PyCFunction) py_blf_aspect, METH_VARARGS, py_blf_aspect_doc},
|
||||
{"blur", (PyCFunction) py_blf_blur, METH_VARARGS, py_blf_blur_doc},
|
||||
|
||||
{"draw", (PyCFunction) py_blf_draw, METH_VARARGS, py_blf_draw_doc},
|
||||
|
||||
{"dimensions", (PyCFunction) py_blf_dimensions, METH_VARARGS, py_blf_dimensions_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static char BLF_doc[] =
|
||||
"This module provides access to blenders text drawing functions.\n";
|
||||
|
||||
static struct PyModuleDef BLF_module_def = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"blf", /* m_name */
|
||||
BLF_doc, /* m_doc */
|
||||
0, /* m_size */
|
||||
BLF_methods, /* m_methods */
|
||||
0, /* m_reload */
|
||||
0, /* m_traverse */
|
||||
0, /* m_clear */
|
||||
0, /* m_free */
|
||||
};
|
||||
|
||||
PyObject *BLF_Init(void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
|
||||
submodule = PyModule_Create(&BLF_module_def);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), BLF_module_def.m_name, submodule);
|
||||
|
||||
return (submodule);
|
||||
}
|
||||
26
source/blender/python/generic/blf.h
Normal file
26
source/blender/python/generic/blf.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* $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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
|
||||
PyObject *BLF_Init(void);
|
||||
@@ -564,9 +564,7 @@ static struct PyMethodDef Euler_methods[] = {
|
||||
|
||||
//------------------PY_OBECT DEFINITION--------------------------
|
||||
static char euler_doc[] =
|
||||
"This object gives access to Eulers in Blender.\n"
|
||||
"\n"
|
||||
".. literalinclude:: ../examples/mathutils_euler.py\n";
|
||||
"This object gives access to Eulers in Blender.";
|
||||
|
||||
PyTypeObject euler_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
|
||||
@@ -1335,9 +1335,7 @@ static struct PyMethodDef Matrix_methods[] = {
|
||||
|
||||
/*------------------PY_OBECT DEFINITION--------------------------*/
|
||||
static char matrix_doc[] =
|
||||
"This object gives access to Matrices in Blender.\n"
|
||||
"\n"
|
||||
".. literalinclude:: ../examples/mathutils_matrix.py\n";
|
||||
"This object gives access to Matrices in Blender.";
|
||||
|
||||
PyTypeObject matrix_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
|
||||
@@ -844,9 +844,7 @@ static PyGetSetDef Quaternion_getseters[] = {
|
||||
|
||||
//------------------PY_OBECT DEFINITION--------------------------
|
||||
static char quaternion_doc[] =
|
||||
"This object gives access to Quaternions in Blender.\n"
|
||||
"\n"
|
||||
".. literalinclude:: ../examples/mathutils_quat.py\n";
|
||||
"This object gives access to Quaternions in Blender.";
|
||||
|
||||
PyTypeObject quaternion_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
|
||||
@@ -1252,12 +1252,7 @@ static PyObject* Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
result = EXPP_VectorsAreEqual(vecA->vec, vecB->vec, vecA->size, 1);
|
||||
break;
|
||||
case Py_NE:
|
||||
result = EXPP_VectorsAreEqual(vecA->vec, vecB->vec, vecA->size, 1);
|
||||
if (result == 0){
|
||||
result = 1;
|
||||
}else{
|
||||
result = 0;
|
||||
}
|
||||
result = !EXPP_VectorsAreEqual(vecA->vec, vecB->vec, vecA->size, 1);
|
||||
break;
|
||||
case Py_GT:
|
||||
lenA = vec_magnitude_nosqrt(vecA->vec, vecA->size);
|
||||
@@ -2129,9 +2124,7 @@ static struct PyMethodDef Vector_methods[] = {
|
||||
*/
|
||||
|
||||
static char vector_doc[] =
|
||||
"This object gives access to Vectors in Blender.\n"
|
||||
"\n"
|
||||
".. literalinclude:: ../examples/mathutils_vector.py\n";
|
||||
"This object gives access to Vectors in Blender.";
|
||||
|
||||
PyTypeObject vector_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
/* external util modules */
|
||||
#include "../generic/Mathutils.h"
|
||||
#include "../generic/Geometry.h"
|
||||
#include "../generic/BGL.h"
|
||||
#include "../generic/bgl.h"
|
||||
#include "../generic/blf.h"
|
||||
#include "../generic/IDProp.h"
|
||||
|
||||
#include "BPy_Freestyle.h"
|
||||
@@ -108,6 +109,7 @@ void BPy_init_modules( void )
|
||||
Geometry_Init();
|
||||
Mathutils_Init();
|
||||
BGL_Init();
|
||||
BLF_Init();
|
||||
IDProp_Init_Types();
|
||||
Freestyle_Init();
|
||||
|
||||
|
||||
@@ -32,17 +32,11 @@
|
||||
#include "structseq.h"
|
||||
|
||||
#ifdef BUILD_DATE
|
||||
extern char * build_date;
|
||||
extern char * build_time;
|
||||
extern char * build_rev;
|
||||
extern char * build_platform;
|
||||
extern char * build_type;
|
||||
#else
|
||||
static char * build_date = "Unknown";
|
||||
static char * build_time = "Unknown";
|
||||
static char * build_rev = "Unknown";
|
||||
static char * build_platform = "Unknown";
|
||||
static char * build_type = "Unknown";
|
||||
extern const char * build_date;
|
||||
extern const char * build_time;
|
||||
extern const char * build_rev;
|
||||
extern const char * build_platform;
|
||||
extern const char * build_type;
|
||||
#endif
|
||||
|
||||
static PyTypeObject BlenderAppType;
|
||||
@@ -111,11 +105,19 @@ static PyObject *make_app_info(void)
|
||||
SetObjItem(PyBool_FromLong(G.f & G_DEBUG));
|
||||
|
||||
/* build info */
|
||||
#ifdef BUILD_DATE
|
||||
SetStrItem(strip_quotes(buf, build_date));
|
||||
SetStrItem(strip_quotes(buf, build_time));
|
||||
SetStrItem(strip_quotes(buf, build_rev));
|
||||
SetStrItem(strip_quotes(buf, build_platform));
|
||||
SetStrItem(strip_quotes(buf, build_type));
|
||||
#else
|
||||
SetStrItem(strip_quotes(buf, "Unknown"));
|
||||
SetStrItem(strip_quotes(buf, "Unknown"));
|
||||
SetStrItem(strip_quotes(buf, "Unknown"));
|
||||
SetStrItem(strip_quotes(buf, "Unknown"));
|
||||
SetStrItem(strip_quotes(buf, "Unknown"));
|
||||
#endif
|
||||
|
||||
#undef SetIntItem
|
||||
#undef SetStrItem
|
||||
|
||||
@@ -2663,7 +2663,7 @@ static struct PyMethodDef pyrna_struct_methods[] = {
|
||||
|
||||
/* maybe this become and ID function */
|
||||
{"keyframe_insert", (PyCFunction)pyrna_struct_keyframe_insert, METH_VARARGS, NULL},
|
||||
// {"keyframe_delete", (PyCFunction)pyrna_struct_keyframe_delete, METH_VARARGS, NULL}, // WIP
|
||||
{"keyframe_delete", (PyCFunction)pyrna_struct_keyframe_delete, METH_VARARGS, NULL},
|
||||
{"driver_add", (PyCFunction)pyrna_struct_driver_add, METH_VARARGS, NULL},
|
||||
{"is_property_set", (PyCFunction)pyrna_struct_is_property_set, METH_VARARGS, NULL},
|
||||
{"is_property_hidden", (PyCFunction)pyrna_struct_is_property_hidden, METH_VARARGS, NULL},
|
||||
|
||||
@@ -32,12 +32,9 @@
|
||||
#include "BKE_context.h"
|
||||
#include "ED_space_api.h"
|
||||
|
||||
EnumPropertyItem region_draw_mode_items[] = {
|
||||
{REGION_DRAW_POST_VIEW, "POST_VIEW", 0, "Pose View", ""},
|
||||
{REGION_DRAW_POST_PIXEL, "POST_PIXEL", 0, "Post Pixel", ""},
|
||||
{REGION_DRAW_PRE_VIEW, "PRE_VIEW", 0, "Pre View", ""},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
/* use this to stop other capsules from being mis-used */
|
||||
#define RNA_CAPSULE_ID "RNA_HANDLE"
|
||||
#define RNA_CAPSULE_ID_INVALID "RNA_HANDLE_REMOVED"
|
||||
|
||||
void cb_region_draw(const bContext *C, ARegion *ar, void *customdata)
|
||||
{
|
||||
@@ -74,6 +71,12 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args)
|
||||
|
||||
if(RNA_struct_is_a(self->ptr.type, &RNA_Region)) {
|
||||
|
||||
static EnumPropertyItem region_draw_mode_items[] = {
|
||||
{REGION_DRAW_POST_VIEW, "POST_VIEW", 0, "Pose View", ""},
|
||||
{REGION_DRAW_POST_PIXEL, "POST_PIXEL", 0, "Post Pixel", ""},
|
||||
{REGION_DRAW_PRE_VIEW, "PRE_VIEW", 0, "Pre View", ""},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
if(pyrna_enum_value_from_id(region_draw_mode_items, cb_event_str, &cb_event, "bpy_struct.callback_add()") < 0)
|
||||
return NULL;
|
||||
|
||||
@@ -81,24 +84,28 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args)
|
||||
Py_INCREF(args);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "callbcak_add(): type does not suppport cllbacks");
|
||||
PyErr_SetString(PyExc_TypeError, "callback_add(): type does not suppport callbacks");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyCapsule_New((void *)handle, NULL, NULL);
|
||||
return PyCapsule_New((void *)handle, RNA_CAPSULE_ID, NULL);
|
||||
}
|
||||
|
||||
PyObject *pyrna_callback_remove(BPy_StructRNA *self, PyObject *args)
|
||||
{
|
||||
PyObject *py_handle;
|
||||
PyObject *py_args;
|
||||
void *handle;
|
||||
void *customdata;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!:callback_remove", &PyCapsule_Type, &py_handle))
|
||||
return NULL;
|
||||
|
||||
handle= PyCapsule_GetPointer(py_handle, NULL);
|
||||
handle= PyCapsule_GetPointer(py_handle, RNA_CAPSULE_ID);
|
||||
|
||||
if(handle==NULL) {
|
||||
PyErr_SetString(PyExc_ValueError, "callback_remove(handle): NULL handle given, invalid or already removed.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(RNA_struct_is_a(self->ptr.type, &RNA_Region)) {
|
||||
customdata= ED_region_draw_cb_customdata(handle);
|
||||
@@ -107,5 +114,8 @@ PyObject *pyrna_callback_remove(BPy_StructRNA *self, PyObject *args)
|
||||
ED_region_draw_cb_exit(((ARegion *)self->ptr.data)->type, handle);
|
||||
}
|
||||
|
||||
/* dont allow reuse */
|
||||
PyCapsule_SetName(py_handle, RNA_CAPSULE_ID_INVALID);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user