Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-23 05:12:23 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-23 05:12:23 +0400
commit68b0a8e39026ea2b391751406dc4bdb0a4ed958c (patch)
treecdf8a143a6cf2b832f49a31c2d3b7003f92eaa43 /source/blender/freestyle/intern/python/BPy_StrokeShader.cpp
parent0fb83d78faa99a8ea3fd396887b2b31a6a36a8cd (diff)
Freestyle Python API improvements - part 7.
Fix for PyGetSetDef and proper handling of keyword arguments were done in UnaryPredicate0D, UnaryPredicate1D, BinaryPredicate1D, and StrokeShader classes. Style modules were updated accordingly. Additional code clean-up was also made.
Diffstat (limited to 'source/blender/freestyle/intern/python/BPy_StrokeShader.cpp')
-rw-r--r--source/blender/freestyle/intern/python/BPy_StrokeShader.cpp169
1 files changed, 87 insertions, 82 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp b/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp
index 202e33c3231..f4a2501547b 100644
--- a/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp
+++ b/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp
@@ -33,124 +33,124 @@ extern "C" {
///////////////////////////////////////////////////////////////////////////////////////////
//-------------------MODULE INITIALIZATION--------------------------------
-int StrokeShader_Init( PyObject *module )
+int StrokeShader_Init(PyObject *module)
{
- if( module == NULL )
+ if (module == NULL)
return -1;
- if( PyType_Ready( &StrokeShader_Type ) < 0 )
+ if (PyType_Ready(&StrokeShader_Type) < 0)
return -1;
- Py_INCREF( &StrokeShader_Type );
+ Py_INCREF(&StrokeShader_Type);
PyModule_AddObject(module, "StrokeShader", (PyObject *)&StrokeShader_Type);
- if( PyType_Ready( &BackboneStretcherShader_Type ) < 0 )
+ if (PyType_Ready(&BackboneStretcherShader_Type) < 0)
return -1;
- Py_INCREF( &BackboneStretcherShader_Type );
+ Py_INCREF(&BackboneStretcherShader_Type);
PyModule_AddObject(module, "BackboneStretcherShader", (PyObject *)&BackboneStretcherShader_Type);
- if( PyType_Ready( &BezierCurveShader_Type ) < 0 )
+ if (PyType_Ready(&BezierCurveShader_Type) < 0)
return -1;
- Py_INCREF( &BezierCurveShader_Type );
+ Py_INCREF(&BezierCurveShader_Type);
PyModule_AddObject(module, "BezierCurveShader", (PyObject *)&BezierCurveShader_Type);
- if( PyType_Ready( &CalligraphicShader_Type ) < 0 )
+ if (PyType_Ready(&CalligraphicShader_Type) < 0)
return -1;
- Py_INCREF( &CalligraphicShader_Type );
+ Py_INCREF(&CalligraphicShader_Type);
PyModule_AddObject(module, "CalligraphicShader", (PyObject *)&CalligraphicShader_Type);
- if( PyType_Ready( &ColorNoiseShader_Type ) < 0 )
+ if (PyType_Ready(&ColorNoiseShader_Type) < 0)
return -1;
- Py_INCREF( &ColorNoiseShader_Type );
+ Py_INCREF(&ColorNoiseShader_Type);
PyModule_AddObject(module, "ColorNoiseShader", (PyObject *)&ColorNoiseShader_Type);
- if( PyType_Ready( &ColorVariationPatternShader_Type ) < 0 )
+ if (PyType_Ready(&ColorVariationPatternShader_Type) < 0)
return -1;
- Py_INCREF( &ColorVariationPatternShader_Type );
+ Py_INCREF(&ColorVariationPatternShader_Type);
PyModule_AddObject(module, "ColorVariationPatternShader", (PyObject *)&ColorVariationPatternShader_Type);
- if( PyType_Ready( &ConstantColorShader_Type ) < 0 )
+ if (PyType_Ready(&ConstantColorShader_Type) < 0)
return -1;
- Py_INCREF( &ConstantColorShader_Type );
+ Py_INCREF(&ConstantColorShader_Type);
PyModule_AddObject(module, "ConstantColorShader", (PyObject *)&ConstantColorShader_Type);
- if( PyType_Ready( &ConstantThicknessShader_Type ) < 0 )
+ if (PyType_Ready(&ConstantThicknessShader_Type) < 0)
return -1;
- Py_INCREF( &ConstantThicknessShader_Type );
+ Py_INCREF(&ConstantThicknessShader_Type);
PyModule_AddObject(module, "ConstantThicknessShader", (PyObject *)&ConstantThicknessShader_Type);
- if( PyType_Ready( &ConstrainedIncreasingThicknessShader_Type ) < 0 )
+ if (PyType_Ready(&ConstrainedIncreasingThicknessShader_Type) < 0)
return -1;
- Py_INCREF( &ConstrainedIncreasingThicknessShader_Type );
+ Py_INCREF(&ConstrainedIncreasingThicknessShader_Type);
PyModule_AddObject(module, "ConstrainedIncreasingThicknessShader", (PyObject *)&ConstrainedIncreasingThicknessShader_Type);
- if( PyType_Ready( &fstreamShader_Type ) < 0 )
+ if (PyType_Ready(&fstreamShader_Type) < 0)
return -1;
- Py_INCREF( &fstreamShader_Type );
+ Py_INCREF(&fstreamShader_Type);
PyModule_AddObject(module, "fstreamShader", (PyObject *)&fstreamShader_Type);
- if( PyType_Ready( &GuidingLinesShader_Type ) < 0 )
+ if (PyType_Ready(&GuidingLinesShader_Type) < 0)
return -1;
- Py_INCREF( &GuidingLinesShader_Type );
+ Py_INCREF(&GuidingLinesShader_Type);
PyModule_AddObject(module, "GuidingLinesShader", (PyObject *)&GuidingLinesShader_Type);
- if( PyType_Ready( &IncreasingColorShader_Type ) < 0 )
+ if (PyType_Ready(&IncreasingColorShader_Type) < 0)
return -1;
- Py_INCREF( &IncreasingColorShader_Type );
+ Py_INCREF(&IncreasingColorShader_Type);
PyModule_AddObject(module, "IncreasingColorShader", (PyObject *)&IncreasingColorShader_Type);
- if( PyType_Ready( &IncreasingThicknessShader_Type ) < 0 )
+ if (PyType_Ready(&IncreasingThicknessShader_Type) < 0)
return -1;
- Py_INCREF( &IncreasingThicknessShader_Type );
+ Py_INCREF(&IncreasingThicknessShader_Type);
PyModule_AddObject(module, "IncreasingThicknessShader", (PyObject *)&IncreasingThicknessShader_Type);
- if( PyType_Ready( &PolygonalizationShader_Type ) < 0 )
+ if (PyType_Ready(&PolygonalizationShader_Type) < 0)
return -1;
- Py_INCREF( &PolygonalizationShader_Type );
+ Py_INCREF(&PolygonalizationShader_Type);
PyModule_AddObject(module, "PolygonalizationShader", (PyObject *)&PolygonalizationShader_Type);
- if( PyType_Ready( &SamplingShader_Type ) < 0 )
+ if (PyType_Ready(&SamplingShader_Type) < 0)
return -1;
- Py_INCREF( &SamplingShader_Type );
+ Py_INCREF(&SamplingShader_Type);
PyModule_AddObject(module, "SamplingShader", (PyObject *)&SamplingShader_Type);
- if( PyType_Ready( &SmoothingShader_Type ) < 0 )
+ if (PyType_Ready(&SmoothingShader_Type) < 0)
return -1;
- Py_INCREF( &SmoothingShader_Type );
+ Py_INCREF(&SmoothingShader_Type);
PyModule_AddObject(module, "SmoothingShader", (PyObject *)&SmoothingShader_Type);
- if( PyType_Ready( &SpatialNoiseShader_Type ) < 0 )
+ if (PyType_Ready(&SpatialNoiseShader_Type) < 0)
return -1;
- Py_INCREF( &SpatialNoiseShader_Type );
+ Py_INCREF(&SpatialNoiseShader_Type);
PyModule_AddObject(module, "SpatialNoiseShader", (PyObject *)&SpatialNoiseShader_Type);
- if( PyType_Ready( &streamShader_Type ) < 0 )
+ if (PyType_Ready(&streamShader_Type) < 0)
return -1;
- Py_INCREF( &streamShader_Type );
+ Py_INCREF(&streamShader_Type);
PyModule_AddObject(module, "streamShader", (PyObject *)&streamShader_Type);
- if( PyType_Ready( &StrokeTextureShader_Type ) < 0 )
+ if (PyType_Ready(&StrokeTextureShader_Type) < 0)
return -1;
- Py_INCREF( &StrokeTextureShader_Type );
+ Py_INCREF(&StrokeTextureShader_Type);
PyModule_AddObject(module, "StrokeTextureShader", (PyObject *)&StrokeTextureShader_Type);
- if( PyType_Ready( &TextureAssignerShader_Type ) < 0 )
+ if (PyType_Ready(&TextureAssignerShader_Type) < 0)
return -1;
- Py_INCREF( &TextureAssignerShader_Type );
+ Py_INCREF(&TextureAssignerShader_Type);
PyModule_AddObject(module, "TextureAssignerShader", (PyObject *)&TextureAssignerShader_Type);
- if( PyType_Ready( &ThicknessNoiseShader_Type ) < 0 )
+ if (PyType_Ready(&ThicknessNoiseShader_Type) < 0)
return -1;
- Py_INCREF( &ThicknessNoiseShader_Type );
+ Py_INCREF(&ThicknessNoiseShader_Type);
PyModule_AddObject(module, "ThicknessNoiseShader", (PyObject *)&ThicknessNoiseShader_Type);
- if( PyType_Ready( &ThicknessVariationPatternShader_Type ) < 0 )
+ if (PyType_Ready(&ThicknessVariationPatternShader_Type) < 0)
return -1;
- Py_INCREF( &ThicknessVariationPatternShader_Type );
+ Py_INCREF(&ThicknessVariationPatternShader_Type);
PyModule_AddObject(module, "ThicknessVariationPatternShader", (PyObject *)&ThicknessVariationPatternShader_Type);
- if( PyType_Ready( &TipRemoverShader_Type ) < 0 )
+ if (PyType_Ready(&TipRemoverShader_Type) < 0)
return -1;
- Py_INCREF( &TipRemoverShader_Type );
+ Py_INCREF(&TipRemoverShader_Type);
PyModule_AddObject(module, "TipRemoverShader", (PyObject *)&TipRemoverShader_Type);
return 0;
@@ -168,8 +168,8 @@ static char StrokeShader___doc__[] =
"code example of such an iteration::\n"
"\n"
" it = ioStroke.strokeVerticesBegin()\n"
-" while it.isEnd() == 0:\n"
-" att = it.getObject().attribute()\n"
+" while not it.is_end:\n"
+" att = it.object.attribute\n"
" ## perform here any attribute modification\n"
" it.increment()\n"
"\n"
@@ -179,10 +179,12 @@ static char StrokeShader___doc__[] =
static int StrokeShader___init__(BPy_StrokeShader *self, PyObject *args, PyObject *kwds)
{
- if ( !PyArg_ParseTuple(args, "") )
- return -1;
+ static const char *kwlist[] = {NULL};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist))
+ return -1;
self->ss = new StrokeShader();
- self->ss->py_ss = (PyObject *) self;
+ self->ss->py_ss = (PyObject *)self;
return 0;
}
@@ -190,63 +192,66 @@ static void StrokeShader___dealloc__(BPy_StrokeShader* self)
{
if (self->ss)
delete self->ss;
- Py_TYPE(self)->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
-
static PyObject * StrokeShader___repr__(BPy_StrokeShader* self)
{
- return PyUnicode_FromFormat("type: %s - address: %p", self->ss->getName().c_str(), self->ss );
-}
-
-static char StrokeShader_getName___doc__[] =
-".. method:: getName()\n"
-"\n"
-" Returns the name of this stroke shader.\n"
-"\n"
-" :return: The name of this stroke shader.\n"
-" :rtype: str\n";
-
-static PyObject * StrokeShader_getName( BPy_StrokeShader *self, PyObject *args)
-{
- return PyUnicode_FromString( self->ss->getName().c_str() );
+ return PyUnicode_FromFormat("type: %s - address: %p", self->ss->getName().c_str(), self->ss);
}
static char StrokeShader_shade___doc__[] =
-".. method:: shade(s)\n"
+".. method:: shade(stroke)\n"
"\n"
" The shading method. Must be overloaded by inherited classes.\n"
"\n"
-" :arg s: A Stroke object.\n"
-" :type s: :class:`Stroke`\n";
+" :arg stroke: A Stroke object.\n"
+" :type stroke: :class:`Stroke`\n";
-static PyObject *StrokeShader_shade( BPy_StrokeShader *self , PyObject *args) {
+static PyObject *StrokeShader_shade(BPy_StrokeShader *self, PyObject *args, PyObject *kwds)
+{
+ static const char *kwlist[] = {"stroke", NULL};
PyObject *py_s = 0;
- if(!( PyArg_ParseTuple(args, "O!", &Stroke_Type, &py_s) ))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Stroke_Type, &py_s))
return NULL;
- if( typeid(*(self->ss)) == typeid(StrokeShader) ) {
+ if (typeid(*(self->ss)) == typeid(StrokeShader)) {
PyErr_SetString(PyExc_TypeError, "shade method not properly overridden");
return NULL;
}
- if (self->ss->shade(*( ((BPy_Stroke *) py_s)->s )) < 0) {
+ if (self->ss->shade(*(((BPy_Stroke *)py_s)->s)) < 0) {
if (!PyErr_Occurred()) {
- string msg(self->ss->getName() + " shade method failed");
- PyErr_SetString(PyExc_RuntimeError, msg.c_str());
+ string class_name(Py_TYPE(self)->tp_name);
+ PyErr_SetString(PyExc_RuntimeError, (class_name + " shade method failed").c_str());
}
return NULL;
}
Py_RETURN_NONE;
}
-/*----------------------StrokeShader instance definitions ----------------------------*/
static PyMethodDef BPy_StrokeShader_methods[] = {
- {"getName", ( PyCFunction ) StrokeShader_getName, METH_NOARGS, StrokeShader_getName___doc__},
- {"shade", ( PyCFunction ) StrokeShader_shade, METH_VARARGS, StrokeShader_shade___doc__},
+ {"shade", (PyCFunction)StrokeShader_shade, METH_VARARGS | METH_KEYWORDS, StrokeShader_shade___doc__},
{NULL, NULL, 0, NULL}
};
+/*----------------------StrokeShader get/setters ----------------------------*/
+
+PyDoc_STRVAR(StrokeShader_name_doc,
+"The name of the stroke shader.\n"
+"\n"
+":type: str");
+
+static PyObject *StrokeShader_name_get(BPy_StrokeShader *self, void *UNUSED(closure))
+{
+ return PyUnicode_FromString(Py_TYPE(self)->tp_name);
+}
+
+static PyGetSetDef BPy_StrokeShader_getseters[] = {
+ {(char *)"name", (getter)StrokeShader_name_get, (setter)NULL, (char *)StrokeShader_name_doc, NULL},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+};
+
/*-----------------------BPy_StrokeShader type definition ------------------------------*/
PyTypeObject StrokeShader_Type = {
@@ -279,7 +284,7 @@ PyTypeObject StrokeShader_Type = {
0, /* tp_iternext */
BPy_StrokeShader_methods, /* tp_methods */
0, /* tp_members */
- 0, /* tp_getset */
+ BPy_StrokeShader_getseters, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */