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:
authorStephen Swaney <sswaney@centurytel.net>2004-09-26 00:30:40 +0400
committerStephen Swaney <sswaney@centurytel.net>2004-09-26 00:30:40 +0400
commita509b8adc9b8952cdb395c69406e821f57a9a6c7 (patch)
tree7c0e3c7b81007acc6b3e268e59a6af5fcb4bd93f /source/blender/python/api2_2x/Text.c
parentbd371ddb9ff947d4e598ad04af9402d89fa80d5e (diff)
Another round in the Great BPy Cleanup:
Run everything thru indent to cleanup spaces vs tabs. Clean up some of the comments by hand. BGL.c was not touched due to all that macro wackyness. There are no functional changes to the code. Pre-indent versions of source are tagged with tag bpy-cleanup-20040925 , just in case.
Diffstat (limited to 'source/blender/python/api2_2x/Text.c')
-rw-r--r--source/blender/python/api2_2x/Text.c749
1 files changed, 378 insertions, 371 deletions
diff --git a/source/blender/python/api2_2x/Text.c b/source/blender/python/api2_2x/Text.c
index cb26fa394b1..029b53f2664 100644
--- a/source/blender/python/api2_2x/Text.c
+++ b/source/blender/python/api2_2x/Text.c
@@ -51,171 +51,167 @@
/*****************************************************************************/
/* Python API function prototypes for the Text module. */
/*****************************************************************************/
-static PyObject *M_Text_New (PyObject *self, PyObject *args,
- PyObject *keywords);
-static PyObject *M_Text_Get (PyObject *self, PyObject *args);
-static PyObject *M_Text_Load (PyObject *self, PyObject *args);
-static PyObject *M_Text_unlink (PyObject *self, PyObject *args);
+static PyObject *M_Text_New( PyObject * self, PyObject * args,
+ PyObject * keywords );
+static PyObject *M_Text_Get( PyObject * self, PyObject * args );
+static PyObject *M_Text_Load( PyObject * self, PyObject * args );
+static PyObject *M_Text_unlink( PyObject * self, PyObject * args );
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.Text.__doc__ */
/*****************************************************************************/
-static char M_Text_doc[] =
-"The Blender Text module\n\n";
+static char M_Text_doc[] = "The Blender Text module\n\n";
-static char M_Text_New_doc[] =
-"() - return a new Text object";
+static char M_Text_New_doc[] = "() - return a new Text object";
-static char M_Text_Get_doc[] =
-"(name) - return the Text with name 'name', \
+static char M_Text_Get_doc[] = "(name) - return the Text with name 'name', \
returns None if not found.\n If 'name' is not specified, \
it returns a list of all Texts in the\ncurrent scene.";
static char M_Text_Load_doc[] =
-"(filename) - return text from file filename as a Text Object, \
+ "(filename) - return text from file filename as a Text Object, \
returns None if not found.\n";
static char M_Text_unlink_doc[] =
-"(text) - remove Text object 'text' from Blender";
+ "(text) - remove Text object 'text' from Blender";
/*****************************************************************************/
/* Python method structure definition for Blender.Text module: */
/*****************************************************************************/
struct PyMethodDef M_Text_methods[] = {
- {"New",(PyCFunction)M_Text_New, METH_VARARGS|METH_KEYWORDS,
- M_Text_New_doc},
- {"Get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
- {"get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
- {"Load", M_Text_Load, METH_VARARGS, M_Text_Load_doc},
- {"unlink", M_Text_unlink, METH_VARARGS, M_Text_unlink_doc},
- {NULL, NULL, 0, NULL}
+ {"New", ( PyCFunction ) M_Text_New, METH_VARARGS | METH_KEYWORDS,
+ M_Text_New_doc},
+ {"Get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
+ {"get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
+ {"Load", M_Text_Load, METH_VARARGS, M_Text_Load_doc},
+ {"unlink", M_Text_unlink, METH_VARARGS, M_Text_unlink_doc},
+ {NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python BPy_Text structure definition: */
/*****************************************************************************/
typedef struct {
- PyObject_HEAD
- Text *text;
+ PyObject_HEAD Text * text;
} BPy_Text;
-static int Text_IsLinked(BPy_Text *self);
+static int Text_IsLinked( BPy_Text * self );
/*****************************************************************************/
/* Python BPy_Text methods declarations: */
/*****************************************************************************/
-static PyObject *Text_getName(BPy_Text *self);
-static PyObject *Text_getFilename(BPy_Text *self);
-static PyObject *Text_getNLines(BPy_Text *self);
-static PyObject *Text_setName(BPy_Text *self, PyObject *args);
-static PyObject *Text_clear(BPy_Text *self, PyObject *args);
-static PyObject *Text_write(BPy_Text *self, PyObject *args);
-static PyObject *Text_set(BPy_Text *self, PyObject *args);
-static PyObject *Text_asLines(BPy_Text *self, PyObject *args);
+static PyObject *Text_getName( BPy_Text * self );
+static PyObject *Text_getFilename( BPy_Text * self );
+static PyObject *Text_getNLines( BPy_Text * self );
+static PyObject *Text_setName( BPy_Text * self, PyObject * args );
+static PyObject *Text_clear( BPy_Text * self, PyObject * args );
+static PyObject *Text_write( BPy_Text * self, PyObject * args );
+static PyObject *Text_set( BPy_Text * self, PyObject * args );
+static PyObject *Text_asLines( BPy_Text * self, PyObject * args );
/*****************************************************************************/
/* Python BPy_Text methods table: */
/*****************************************************************************/
static PyMethodDef BPy_Text_methods[] = {
- /* name, method, flags, doc */
- {"getName", (PyCFunction)Text_getName, METH_NOARGS,
- "() - Return Text Object name"},
- {"getFilename", (PyCFunction)Text_getFilename, METH_VARARGS,
- "() - Return Text Object filename"},
- {"getNLines", (PyCFunction)Text_getNLines, METH_VARARGS,
- "() - Return number of lines in text buffer"},
- {"setName", (PyCFunction)Text_setName, METH_VARARGS,
- "(str) - Change Text Object name"},
- {"clear", (PyCFunction)Text_clear, METH_VARARGS,
- "() - Clear Text buffer"},
- {"write", (PyCFunction)Text_write, METH_VARARGS,
- "(line) - Append string 'str' to Text buffer"},
- {"set", (PyCFunction)Text_set, METH_VARARGS,
- "(name, val) - Set attribute 'name' to value 'val'"},
- {"asLines", (PyCFunction)Text_asLines, METH_VARARGS,
- "() - Return text buffer as a list of lines"},
- {NULL, NULL, 0, NULL}
+ /* name, method, flags, doc */
+ {"getName", ( PyCFunction ) Text_getName, METH_NOARGS,
+ "() - Return Text Object name"},
+ {"getFilename", ( PyCFunction ) Text_getFilename, METH_VARARGS,
+ "() - Return Text Object filename"},
+ {"getNLines", ( PyCFunction ) Text_getNLines, METH_VARARGS,
+ "() - Return number of lines in text buffer"},
+ {"setName", ( PyCFunction ) Text_setName, METH_VARARGS,
+ "(str) - Change Text Object name"},
+ {"clear", ( PyCFunction ) Text_clear, METH_VARARGS,
+ "() - Clear Text buffer"},
+ {"write", ( PyCFunction ) Text_write, METH_VARARGS,
+ "(line) - Append string 'str' to Text buffer"},
+ {"set", ( PyCFunction ) Text_set, METH_VARARGS,
+ "(name, val) - Set attribute 'name' to value 'val'"},
+ {"asLines", ( PyCFunction ) Text_asLines, METH_VARARGS,
+ "() - Return text buffer as a list of lines"},
+ {NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python Text_Type callback function prototypes: */
/*****************************************************************************/
-static void Text_dealloc (BPy_Text *self);
-static int Text_setAttr (BPy_Text *self, char *name, PyObject *v);
-static PyObject *Text_getAttr (BPy_Text *self, char *name);
-static int Text_compare (BPy_Text *a, BPy_Text *b);
-static PyObject *Text_repr (BPy_Text *self);
+static void Text_dealloc( BPy_Text * self );
+static int Text_setAttr( BPy_Text * self, char *name, PyObject * v );
+static PyObject *Text_getAttr( BPy_Text * self, char *name );
+static int Text_compare( BPy_Text * a, BPy_Text * b );
+static PyObject *Text_repr( BPy_Text * self );
/*****************************************************************************/
/* Python Text_Type structure definition: */
/*****************************************************************************/
-PyTypeObject Text_Type =
-{
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "Blender Text", /* tp_name */
- sizeof (BPy_Text), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor)Text_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc)Text_getAttr, /* tp_getattr */
- (setattrfunc)Text_setAttr, /* tp_setattr */
- (cmpfunc)Text_compare, /* tp_compare */
- (reprfunc)Text_repr, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_as_hash */
- 0,0,0,0,0,0,
- 0, /* tp_doc */
- 0,0,0,0,0,0,
- BPy_Text_methods, /* tp_methods */
- 0, /* tp_members */
+PyTypeObject Text_Type = {
+ PyObject_HEAD_INIT( NULL )
+ 0, /* ob_size */
+ "Blender Text", /* tp_name */
+ sizeof( BPy_Text ), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ /* methods */
+ ( destructor ) Text_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ ( getattrfunc ) Text_getAttr, /* tp_getattr */
+ ( setattrfunc ) Text_setAttr, /* tp_setattr */
+ ( cmpfunc ) Text_compare, /* tp_compare */
+ ( reprfunc ) Text_repr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_as_hash */
+ 0, 0, 0, 0, 0, 0,
+ 0, /* tp_doc */
+ 0, 0, 0, 0, 0, 0,
+ BPy_Text_methods, /* tp_methods */
+ 0, /* tp_members */
};
/*****************************************************************************/
/* Function: M_Text_New */
/* Python equivalent: Blender.Text.New */
/*****************************************************************************/
-static PyObject *M_Text_New(PyObject *self, PyObject *args, PyObject *keywords)
+static PyObject *M_Text_New( PyObject * self, PyObject * args,
+ PyObject * keywords )
{
- char *name = NULL;
- char buf[21];
- int follow = 0;
- Text *bl_text; /* blender text object */
- PyObject *py_text; /* python wrapper */
-
- if (!PyArg_ParseTuple(args, "|si", &name, &follow))
- return EXPP_ReturnPyObjError (PyExc_AttributeError,
- "expected string and int arguments (or nothing)");
-
- bl_text = add_empty_text();
-
- if (bl_text) {
- /* do not set user count because Text is already linked */
-
- /* create python wrapper obj */
- py_text = Text_CreatePyObject (bl_text);
- }
- else
- return EXPP_ReturnPyObjError (PyExc_RuntimeError,
- "couldn't create Text Object in Blender");
- if (!py_text)
- return EXPP_ReturnPyObjError (PyExc_MemoryError,
- "couldn't create Text Object wrapper");
-
- if (follow) bl_text->flags |= EXPP_TEXT_MODE_FOLLOW;
-
- if (name) {
- PyOS_snprintf(buf, sizeof(buf), "%s", name);
- rename_id(&bl_text->id, buf);
- }
-
- return py_text;
+ char *name = NULL;
+ char buf[21];
+ int follow = 0;
+ Text *bl_text; /* blender text object */
+ PyObject *py_text; /* python wrapper */
+
+ if( !PyArg_ParseTuple( args, "|si", &name, &follow ) )
+ return EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "expected string and int arguments (or nothing)" );
+
+ bl_text = add_empty_text( );
+
+ if( bl_text ) {
+ /* do not set user count because Text is already linked */
+
+ /* create python wrapper obj */
+ py_text = Text_CreatePyObject( bl_text );
+ } else
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't create Text Object in Blender" );
+ if( !py_text )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create Text Object wrapper" );
+
+ if( follow )
+ bl_text->flags |= EXPP_TEXT_MODE_FOLLOW;
+
+ if( name ) {
+ PyOS_snprintf( buf, sizeof( buf ), "%s", name );
+ rename_id( &bl_text->id, buf );
+ }
+
+ return py_text;
}
/*****************************************************************************/
@@ -226,65 +222,67 @@ static PyObject *M_Text_New(PyObject *self, PyObject *args, PyObject *keywords)
/* passed in, a list of all text names in the current */
/* scene is returned. */
/*****************************************************************************/
-static PyObject *M_Text_Get(PyObject *self, PyObject *args)
+static PyObject *M_Text_Get( PyObject * self, PyObject * args )
{
- char *name = NULL;
- Text *txt_iter;
+ char *name = NULL;
+ Text *txt_iter;
- if (!PyArg_ParseTuple(args, "|s", &name))
- return (EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected string argument (or nothing)"));
+ if( !PyArg_ParseTuple( args, "|s", &name ) )
+ return ( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected string argument (or nothing)" ) );
- txt_iter = G.main->text.first;
+ txt_iter = G.main->text.first;
- if (name) { /* (name) - Search text by name */
+ if( name ) { /* (name) - Search text by name */
- PyObject *wanted_txt = NULL;
+ PyObject *wanted_txt = NULL;
- while ((txt_iter) && (wanted_txt == NULL)) {
+ while( ( txt_iter ) && ( wanted_txt == NULL ) ) {
- if (strcmp (name, txt_iter->id.name+2) == 0) {
- wanted_txt = Text_CreatePyObject (txt_iter);
- }
+ if( strcmp( name, txt_iter->id.name + 2 ) == 0 ) {
+ wanted_txt = Text_CreatePyObject( txt_iter );
+ }
- txt_iter = txt_iter->id.next;
- }
+ txt_iter = txt_iter->id.next;
+ }
- if (wanted_txt == NULL) { /* Requested text doesn't exist */
- char error_msg[64];
- PyOS_snprintf(error_msg, sizeof(error_msg),
- "Text \"%s\" not found", name);
- return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
- }
+ if( wanted_txt == NULL ) { /* Requested text doesn't exist */
+ char error_msg[64];
+ PyOS_snprintf( error_msg, sizeof( error_msg ),
+ "Text \"%s\" not found", name );
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_NameError, error_msg ) );
+ }
- return wanted_txt;
- }
+ return wanted_txt;
+ }
- else { /* () - return a list of all texts in the scene */
- int index = 0;
- PyObject *txtlist, *pyobj;
+ else { /* () - return a list of all texts in the scene */
+ int index = 0;
+ PyObject *txtlist, *pyobj;
- txtlist = PyList_New (BLI_countlist (&(G.main->text)));
+ txtlist = PyList_New( BLI_countlist( &( G.main->text ) ) );
- if (txtlist == NULL)
- return (EXPP_ReturnPyObjError (PyExc_MemoryError,
- "couldn't create PyList"));
+ if( txtlist == NULL )
+ return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyList" ) );
- while (txt_iter) {
- pyobj = Text_CreatePyObject(txt_iter);
+ while( txt_iter ) {
+ pyobj = Text_CreatePyObject( txt_iter );
- if (!pyobj)
- return (EXPP_ReturnPyObjError (PyExc_MemoryError,
- "couldn't create PyString"));
+ if( !pyobj )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_MemoryError,
+ "couldn't create PyString" ) );
- PyList_SET_ITEM (txtlist, index, pyobj);
+ PyList_SET_ITEM( txtlist, index, pyobj );
- txt_iter = txt_iter->id.next;
- index++;
- }
+ txt_iter = txt_iter->id.next;
+ index++;
+ }
- return (txtlist);
- }
+ return ( txtlist );
+ }
}
/*****************************************************************************/
@@ -293,30 +291,30 @@ static PyObject *M_Text_Get(PyObject *self, PyObject *args)
/* Description: Receives a filename and returns the text object */
/* created from the corresponding file. */
/*****************************************************************************/
-static PyObject *M_Text_Load(PyObject *self, PyObject *args)
+static PyObject *M_Text_Load( PyObject * self, PyObject * args )
{
- char *fname;
- Text *txt_ptr;
- BPy_Text *txt;
+ char *fname;
+ Text *txt_ptr;
+ BPy_Text *txt;
+
+ if( !PyArg_ParseTuple( args, "s", &fname ) )
+ return ( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected string argument" ) );
- if (!PyArg_ParseTuple(args, "s", &fname))
- return (EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected string argument"));
-
- txt = (BPy_Text *)PyObject_NEW(BPy_Text, &Text_Type);
+ txt = ( BPy_Text * ) PyObject_NEW( BPy_Text, &Text_Type );
- if (!txt)
- return EXPP_ReturnPyObjError (PyExc_MemoryError,
- "couldn't create PyObject Text_Type");
+ if( !txt )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyObject Text_Type" );
- txt_ptr = add_text(fname);
- if (!txt_ptr)
- return EXPP_ReturnPyObjError (PyExc_IOError,
- "couldn't load text");
+ txt_ptr = add_text( fname );
+ if( !txt_ptr )
+ return EXPP_ReturnPyObjError( PyExc_IOError,
+ "couldn't load text" );
- txt->text = txt_ptr;
+ txt->text = txt_ptr;
- return (PyObject *)txt;
+ return ( PyObject * ) txt;
}
/*****************************************************************************/
@@ -324,216 +322,221 @@ static PyObject *M_Text_Load(PyObject *self, PyObject *args)
/* Python equivalent: Blender.Text.unlink */
/* Description: Removes the given Text object from Blender */
/*****************************************************************************/
-static PyObject *M_Text_unlink(PyObject *self, PyObject *args)
+static PyObject *M_Text_unlink( PyObject * self, PyObject * args )
{
- BPy_Text *textobj;
- Text *text;
+ BPy_Text *textobj;
+ Text *text;
- if (!PyArg_ParseTuple(args, "O!", &Text_Type, &textobj))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected a Text object as argument");
+ if( !PyArg_ParseTuple( args, "O!", &Text_Type, &textobj ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected a Text object as argument" );
- text = ((BPy_Text *)textobj)->text;
+ text = ( ( BPy_Text * ) textobj )->text;
- if (!text)
- return EXPP_ReturnPyObjError (PyExc_RuntimeError,
- "this text was already unlinked!");
+ if( !text )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "this text was already unlinked!" );
- BPY_clear_bad_scriptlinks(text);
- free_text_controllers(text);
- unlink_text(text);
+ BPY_clear_bad_scriptlinks( text );
+ free_text_controllers( text );
+ unlink_text( text );
- free_libblock(&G.main->text, text);
+ free_libblock( &G.main->text, text );
- ((BPy_Text *)textobj)->text = NULL;
+ ( ( BPy_Text * ) textobj )->text = NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_INCREF( Py_None );
+ return Py_None;
}
/*****************************************************************************/
/* Function: Text_Init */
/*****************************************************************************/
-PyObject *Text_Init (void)
+PyObject *Text_Init( void )
{
- PyObject *submodule;
+ PyObject *submodule;
- Text_Type.ob_type = &PyType_Type;
+ Text_Type.ob_type = &PyType_Type;
- submodule = Py_InitModule3("Blender.Text", M_Text_methods, M_Text_doc);
+ submodule =
+ Py_InitModule3( "Blender.Text", M_Text_methods, M_Text_doc );
- return (submodule);
+ return ( submodule );
}
/*****************************************************************************/
/* Function: Text_CreatePyObject */
/*****************************************************************************/
-PyObject *Text_CreatePyObject (Text *txt)
+PyObject *Text_CreatePyObject( Text * txt )
{
- BPy_Text *pytxt;
+ BPy_Text *pytxt;
- pytxt = (BPy_Text *)PyObject_NEW (BPy_Text, &Text_Type);
+ pytxt = ( BPy_Text * ) PyObject_NEW( BPy_Text, &Text_Type );
- if (!pytxt)
- return EXPP_ReturnPyObjError (PyExc_MemoryError,
- "couldn't create BPy_Text PyObject");
+ if( !pytxt )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create BPy_Text PyObject" );
- pytxt->text = txt;
+ pytxt->text = txt;
- return (PyObject *)pytxt;
+ return ( PyObject * ) pytxt;
}
/*****************************************************************************/
/* Python BPy_Text methods: */
/*****************************************************************************/
-static PyObject *Text_getName(BPy_Text *self)
+static PyObject *Text_getName( BPy_Text * self )
{
- PyObject *attr = PyString_FromString(self->text->id.name+2);
+ PyObject *attr = PyString_FromString( self->text->id.name + 2 );
- if (attr) return attr;
+ if( attr )
+ return attr;
- return EXPP_ReturnPyObjError (PyExc_RuntimeError,
- "couldn't get Text.name attribute");
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get Text.name attribute" );
}
-static PyObject *Text_getFilename(BPy_Text *self)
+static PyObject *Text_getFilename( BPy_Text * self )
{
- PyObject *attr;
+ PyObject *attr;
char *name = self->text->name;
-
- if (name) attr = PyString_FromString(self->text->name);
+
+ if( name )
+ attr = PyString_FromString( self->text->name );
else
attr = Py_None;
- if (attr) return attr;
+ if( attr )
+ return attr;
- return EXPP_ReturnPyObjError (PyExc_RuntimeError,
- "couldn't get Text.filename attribute");
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get Text.filename attribute" );
}
-static PyObject *Text_getNLines(BPy_Text *self)
-{ /* text->nlines isn't updated in Blender (?) */
- int nlines = 0;
- TextLine *line;
- PyObject *attr;
+static PyObject *Text_getNLines( BPy_Text * self )
+{ /* text->nlines isn't updated in Blender (?) */
+ int nlines = 0;
+ TextLine *line;
+ PyObject *attr;
- line = self->text->lines.first;
+ line = self->text->lines.first;
- while (line) { /* so we have to count them ourselves */
- line = line->next;
- nlines++;
- }
+ while( line ) { /* so we have to count them ourselves */
+ line = line->next;
+ nlines++;
+ }
- self->text->nlines = nlines; /* and update Blender, too (should we?) */
+ self->text->nlines = nlines; /* and update Blender, too (should we?) */
- attr = PyInt_FromLong(nlines);
+ attr = PyInt_FromLong( nlines );
- if (attr) return attr;
+ if( attr )
+ return attr;
- return EXPP_ReturnPyObjError (PyExc_RuntimeError,
- "couldn't get Text.nlines attribute");
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get Text.nlines attribute" );
}
-static PyObject *Text_setName(BPy_Text *self, PyObject *args)
+static PyObject *Text_setName( BPy_Text * self, PyObject * args )
{
- char *name;
- char buf[21];
-
- if (!PyArg_ParseTuple(args, "s", &name))
- return (EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected string argument"));
-
- PyOS_snprintf(buf, sizeof(buf), "%s", name);
-
- rename_id(&self->text->id, buf);
-
- Py_INCREF(Py_None);
- return Py_None;
+ char *name;
+ char buf[21];
+
+ if( !PyArg_ParseTuple( args, "s", &name ) )
+ return ( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected string argument" ) );
+
+ PyOS_snprintf( buf, sizeof( buf ), "%s", name );
+
+ rename_id( &self->text->id, buf );
+
+ Py_INCREF( Py_None );
+ return Py_None;
}
-static PyObject *Text_clear(BPy_Text *self, PyObject *args)
+static PyObject *Text_clear( BPy_Text * self, PyObject * args )
{
- int oldstate;
+ int oldstate;
- if (!self->text)
- return EXPP_ReturnPyObjError (PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object");
+ if( !self->text )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "This object isn't linked to a Blender Text Object" );
- oldstate = txt_get_undostate();
- txt_set_undostate(1);
- txt_sel_all(self->text);
- txt_cut_sel(self->text);
- txt_set_undostate(oldstate);
+ oldstate = txt_get_undostate( );
+ txt_set_undostate( 1 );
+ txt_sel_all( self->text );
+ txt_cut_sel( self->text );
+ txt_set_undostate( oldstate );
- Py_INCREF(Py_None);
- return Py_None;
+ Py_INCREF( Py_None );
+ return Py_None;
}
-static PyObject *Text_set(BPy_Text *self, PyObject *args)
+static PyObject *Text_set( BPy_Text * self, PyObject * args )
{
- int ival;
- char *attr;
-
- if (!PyArg_ParseTuple(args, "si", &attr, &ival))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected a string and an int as arguments");
-
- if (strcmp("follow_cursor", attr) == 0) {
- if (ival)
- self->text->flags |= EXPP_TEXT_MODE_FOLLOW;
- else
- self->text->flags &= EXPP_TEXT_MODE_FOLLOW;
- }
-
- Py_INCREF(Py_None);
- return Py_None;
+ int ival;
+ char *attr;
+
+ if( !PyArg_ParseTuple( args, "si", &attr, &ival ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected a string and an int as arguments" );
+
+ if( strcmp( "follow_cursor", attr ) == 0 ) {
+ if( ival )
+ self->text->flags |= EXPP_TEXT_MODE_FOLLOW;
+ else
+ self->text->flags &= EXPP_TEXT_MODE_FOLLOW;
+ }
+
+ Py_INCREF( Py_None );
+ return Py_None;
}
-static PyObject *Text_write(BPy_Text *self, PyObject *args)
+static PyObject *Text_write( BPy_Text * self, PyObject * args )
{
- char *str;
- int oldstate;
+ char *str;
+ int oldstate;
- if (!self->text)
- return EXPP_ReturnPyObjError (PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object");
+ if( !self->text )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "This object isn't linked to a Blender Text Object" );
- if (!PyArg_ParseTuple(args, "s", &str))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected string argument");
+ if( !PyArg_ParseTuple( args, "s", &str ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected string argument" );
- oldstate = txt_get_undostate();
- txt_insert_buf(self->text, str);
- txt_move_eof(self->text, 0);
- txt_set_undostate(oldstate);
+ oldstate = txt_get_undostate( );
+ txt_insert_buf( self->text, str );
+ txt_move_eof( self->text, 0 );
+ txt_set_undostate( oldstate );
- Py_INCREF(Py_None);
- return Py_None;
+ Py_INCREF( Py_None );
+ return Py_None;
}
-static PyObject *Text_asLines(BPy_Text *self, PyObject *args)
+static PyObject *Text_asLines( BPy_Text * self, PyObject * args )
{
- TextLine *line;
- PyObject *list, *ob;
+ TextLine *line;
+ PyObject *list, *ob;
- if (!self->text)
- return EXPP_ReturnPyObjError (PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object");
+ if( !self->text )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "This object isn't linked to a Blender Text Object" );
- line = self->text->lines.first;
- list= PyList_New(0);
+ line = self->text->lines.first;
+ list = PyList_New( 0 );
- if (!list)
- return EXPP_ReturnPyObjError (PyExc_MemoryError,
- "couldn't create PyList");
+ if( !list )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyList" );
- while (line) {
- ob = Py_BuildValue("s", line->line);
- PyList_Append(list, ob);
- line = line->next;
- }
+ while( line ) {
+ ob = Py_BuildValue( "s", line->line );
+ PyList_Append( list, ob );
+ line = line->next;
+ }
- return list;
+ return list;
}
/*****************************************************************************/
@@ -541,9 +544,9 @@ static PyObject *Text_asLines(BPy_Text *self, PyObject *args)
/* Description: This is a callback function for the BPy_Text type. It is */
/* the destructor function. */
/*****************************************************************************/
-static void Text_dealloc (BPy_Text *self)
+static void Text_dealloc( BPy_Text * self )
{
- PyObject_DEL (self);
+ PyObject_DEL( self );
}
/*****************************************************************************/
@@ -552,35 +555,36 @@ static void Text_dealloc (BPy_Text *self)
/* the function that accesses BPy_Text member variables and */
/* methods. */
/*****************************************************************************/
-static PyObject *Text_getAttr (BPy_Text *self, char *name)
+static PyObject *Text_getAttr( BPy_Text * self, char *name )
{
- PyObject *attr = Py_None;
-
- if (!self->text || !Text_IsLinked(self))
- return EXPP_ReturnPyObjError (PyExc_RuntimeError,
- "Text was already deleted!");
-
- if (strcmp(name, "name") == 0)
- attr = PyString_FromString(self->text->id.name+2);
- else if (strcmp(name, "filename") == 0)
- return Text_getFilename(self); /* special: can be null */
- else if (strcmp(name, "mode") == 0)
- attr = PyInt_FromLong(self->text->flags);
- else if (strcmp(name, "nlines") == 0)
- attr = Text_getNLines(self);
-
- else if (strcmp(name, "__members__") == 0)
- attr = Py_BuildValue("[s,s,s,s]",
- "name", "filename", "mode", "nlines");
-
- if (!attr)
- return (EXPP_ReturnPyObjError (PyExc_MemoryError,
- "couldn't create PyObject"));
-
- if (attr != Py_None) return attr; /* attribute found, return its value */
-
- /* not an attribute, search the methods table */
- return Py_FindMethod(BPy_Text_methods, (PyObject *)self, name);
+ PyObject *attr = Py_None;
+
+ if( !self->text || !Text_IsLinked( self ) )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "Text was already deleted!" );
+
+ if( strcmp( name, "name" ) == 0 )
+ attr = PyString_FromString( self->text->id.name + 2 );
+ else if( strcmp( name, "filename" ) == 0 )
+ return Text_getFilename( self ); /* special: can be null */
+ else if( strcmp( name, "mode" ) == 0 )
+ attr = PyInt_FromLong( self->text->flags );
+ else if( strcmp( name, "nlines" ) == 0 )
+ attr = Text_getNLines( self );
+
+ else if( strcmp( name, "__members__" ) == 0 )
+ attr = Py_BuildValue( "[s,s,s,s]",
+ "name", "filename", "mode", "nlines" );
+
+ if( !attr )
+ return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyObject" ) );
+
+ if( attr != Py_None )
+ return attr; /* attribute found, return its value */
+
+ /* not an attribute, search the methods table */
+ return Py_FindMethod( BPy_Text_methods, ( PyObject * ) self, name );
}
/*****************************************************************************/
@@ -589,41 +593,42 @@ static PyObject *Text_getAttr (BPy_Text *self, char *name)
/* function that changes Text Data members values. If this */
/* data is linked to a Blender Text, it also gets updated. */
/*****************************************************************************/
-static int Text_setAttr (BPy_Text *self, char *name, PyObject *value)
+static int Text_setAttr( BPy_Text * self, char *name, PyObject * value )
{
- PyObject *valtuple;
- PyObject *error = NULL;
+ PyObject *valtuple;
+ PyObject *error = NULL;
- if (!self->text || !Text_IsLinked(self))
- return EXPP_ReturnIntError (PyExc_RuntimeError,
- "Text was already deleted!");
+ if( !self->text || !Text_IsLinked( self ) )
+ return EXPP_ReturnIntError( PyExc_RuntimeError,
+ "Text was already deleted!" );
/* We're playing a trick on the Python API users here. Even if they use
* Text.member = val instead of Text.setMember(value), we end up using the
* function anyway, since it already has error checking, clamps to the right
* interval and updates the Blender Text structure when necessary. */
- valtuple = Py_BuildValue("(O)", value);/* the set* functions expect a tuple */
+ valtuple = Py_BuildValue( "(O)", value ); /* the set* functions expect a tuple */
- if (!valtuple)
- return EXPP_ReturnIntError(PyExc_MemoryError,
- "TextSetAttr: couldn't create PyTuple");
+ if( !valtuple )
+ return EXPP_ReturnIntError( PyExc_MemoryError,
+ "TextSetAttr: couldn't create PyTuple" );
- if (strcmp (name, "name") == 0)
- error = Text_setName (self, valtuple);
- else { /* Error: no such member in the Text Data structure */
- Py_DECREF(value);
- Py_DECREF(valtuple);
- return (EXPP_ReturnIntError (PyExc_KeyError,
- "attribute not found or immutable"));
- }
+ if( strcmp( name, "name" ) == 0 )
+ error = Text_setName( self, valtuple );
+ else { /* Error: no such member in the Text Data structure */
+ Py_DECREF( value );
+ Py_DECREF( valtuple );
+ return ( EXPP_ReturnIntError( PyExc_KeyError,
+ "attribute not found or immutable" ) );
+ }
- Py_DECREF(valtuple);
+ Py_DECREF( valtuple );
- if (error != Py_None) return -1;
+ if( error != Py_None )
+ return -1;
- Py_DECREF(Py_None); /* incref'ed by the called set* function */
- return 0; /* normal exit */
+ Py_DECREF( Py_None ); /* incref'ed by the called set* function */
+ return 0; /* normal exit */
}
/*****************************************************************************/
@@ -634,10 +639,10 @@ static int Text_setAttr (BPy_Text *self, char *name, PyObject *value)
/* they don't point to the same Blender Text struct. */
/* In Python it becomes 1 if they are equal, 0 otherwise. */
/*****************************************************************************/
-static int Text_compare (BPy_Text *a, BPy_Text *b)
+static int Text_compare( BPy_Text * a, BPy_Text * b )
{
- Text *pa = a->text, *pb = b->text;
- return (pa == pb) ? 0:-1;
+ Text *pa = a->text, *pb = b->text;
+ return ( pa == pb ) ? 0 : -1;
}
/*****************************************************************************/
@@ -645,27 +650,29 @@ static int Text_compare (BPy_Text *a, BPy_Text *b)
/* Description: This is a callback function for the BPy_Text type. It */
/* builds a meaninful string to represent text objects. */
/*****************************************************************************/
-static PyObject *Text_repr (BPy_Text *self)
+static PyObject *Text_repr( BPy_Text * self )
{
- if (self->text && Text_IsLinked(self))
- return PyString_FromFormat("[Text \"%s\"]", self->text->id.name+2);
- else
- return PyString_FromString("[Text <deleted>]");
+ if( self->text && Text_IsLinked( self ) )
+ return PyString_FromFormat( "[Text \"%s\"]",
+ self->text->id.name + 2 );
+ else
+ return PyString_FromString( "[Text <deleted>]" );
}
/* Internal function to confirm if a Text wasn't unlinked.
* This is necessary because without it, if a script writer
- * referenced an already unlinked Text obj, Blender would crash. */
-static int Text_IsLinked(BPy_Text *self)
+ * referenced an already unlinked Text obj, Blender would crash. */
+static int Text_IsLinked( BPy_Text * self )
{
- Text *txt_iter = G.main->text.first;
+ Text *txt_iter = G.main->text.first;
- while (txt_iter) {
- if (self->text == txt_iter) return 1; /* ok, still linked */
+ while( txt_iter ) {
+ if( self->text == txt_iter )
+ return 1; /* ok, still linked */
- txt_iter = txt_iter->id.next;
- }
+ txt_iter = txt_iter->id.next;
+ }
/* uh-oh, it was already deleted */
- self->text = NULL; /* so we invalidate the pointer */
- return 0;
+ self->text = NULL; /* so we invalidate the pointer */
+ return 0;
}