diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-20 07:37:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-20 07:37:55 +0400 |
commit | 3d8ee287509f3a0dac535914a7193397217b006c (patch) | |
tree | 2a2fc72b6151fd21bef9c29248ee2b59da443044 /source/blender/python/mathutils/mathutils_Color.c | |
parent | 32b23b9f746b9bec4023da1d2ef6085fbbde9ae7 (diff) |
__str__ functions for other mathutils types
Diffstat (limited to 'source/blender/python/mathutils/mathutils_Color.c')
-rw-r--r-- | source/blender/python/mathutils/mathutils_Color.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/source/blender/python/mathutils/mathutils_Color.c b/source/blender/python/mathutils/mathutils_Color.c index e46dda7560f..46486ec7f48 100644 --- a/source/blender/python/mathutils/mathutils_Color.c +++ b/source/blender/python/mathutils/mathutils_Color.c @@ -32,6 +32,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_dynstr.h" #define COLOR_SIZE 3 @@ -125,6 +126,21 @@ static PyObject *Color_repr(ColorObject * self) return ret; } +static PyObject *Color_str(ColorObject * self) +{ + DynStr *ds; + + if (BaseMath_ReadCallback(self) == -1) + return NULL; + + ds= BLI_dynstr_new(); + + BLI_dynstr_appendf(ds, "<Color (r=%.4f, g=%.4f, b=%.4f) >", + self->col[0], self->col[1], self->col[2]); + + return mathutils_dynstr_to_py(ds); /* frees ds */ +} + //------------------------tp_richcmpr //returns -1 execption, 0 false, 1 true static PyObject* Color_richcmpr(PyObject *a, PyObject *b, int op) @@ -789,7 +805,7 @@ PyTypeObject color_Type = { &Color_AsMapping, //tp_as_mapping NULL, //tp_hash NULL, //tp_call - NULL, //tp_str + (reprfunc) Color_str, //tp_str NULL, //tp_getattro NULL, //tp_setattro NULL, //tp_as_buffer |