* Added function Blender.Draw.GetStringWidth().
* Added doc and small test for Blender.Test * trying changes to make Blender.Test.unlink() safer.
This commit is contained in:
@@ -422,4 +422,4 @@ static PyObject *Method_##funcname (PyObject *self, PyObject *args) {\
|
||||
|
||||
/* #endif */
|
||||
|
||||
PyObject *M_BGL_Init(void);
|
||||
PyObject *BGL_Init(void);
|
||||
|
@@ -621,6 +621,24 @@ static PyObject *Method_String (PyObject *self, PyObject *args)
|
||||
return (PyObject *) but;
|
||||
}
|
||||
|
||||
static PyObject *Method_GetStringWidth (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *text;
|
||||
PyObject *width;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &text))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected string argument");
|
||||
|
||||
width = PyInt_FromLong(BMF_GetStringWidth (G.font, text));
|
||||
|
||||
if (!width)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create PyInt");
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
static PyObject *Method_Text (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *text;
|
||||
|
@@ -265,10 +265,14 @@ new String button\n\n\
|
||||
|
||||
static PyObject *Method_String (PyObject *self, PyObject *args);
|
||||
|
||||
static char Method_GetStringWidth_doc[] =
|
||||
"(text) - Return the width in pixels of the given string";
|
||||
|
||||
static char Method_Text_doc[] =
|
||||
"(text) - Draw text onscreen\n\n\
|
||||
(text) The text to draw\n";
|
||||
|
||||
static PyObject *Method_GetStringWidth (PyObject *self, PyObject *args);
|
||||
static PyObject *Method_Text (PyObject *self, PyObject *args);
|
||||
|
||||
#define _MethodDef(func, prefix) \
|
||||
@@ -290,6 +294,8 @@ static struct PyMethodDef Draw_methods[] = {
|
||||
MethodDef(Number),
|
||||
MethodDef(String),
|
||||
|
||||
MethodDef(GetStringWidth),
|
||||
|
||||
MethodDef(Text),
|
||||
|
||||
MethodDef(Exit),
|
||||
|
@@ -41,7 +41,7 @@ static PyObject *M_Text_New(PyObject *self, PyObject *args, PyObject *keywords)
|
||||
char buf[21];
|
||||
int follow = 0;
|
||||
Text *bl_text; /* blender text object */
|
||||
C_Text *py_text; /* python wrapper */
|
||||
PyObject *py_text; /* python wrapper */
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|si", &name, &follow))
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
@@ -50,7 +50,7 @@ static PyObject *M_Text_New(PyObject *self, PyObject *args, PyObject *keywords)
|
||||
bl_text = add_empty_text();
|
||||
|
||||
if (bl_text)
|
||||
py_text = (C_Text *)PyObject_NEW(C_Text, &Text_Type);
|
||||
py_text = Text_CreatePyObject (bl_text);
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't create Text Object in Blender");
|
||||
@@ -58,8 +58,6 @@ static PyObject *M_Text_New(PyObject *self, PyObject *args, PyObject *keywords)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create Text Object wrapper");
|
||||
|
||||
py_text->text = bl_text;
|
||||
|
||||
if (follow) bl_text->flags |= EXPP_TEXT_MODE_FOLLOW;
|
||||
|
||||
if (name) {
|
||||
@@ -67,7 +65,7 @@ static PyObject *M_Text_New(PyObject *self, PyObject *args, PyObject *keywords)
|
||||
rename_id(&bl_text->id, buf);
|
||||
}
|
||||
|
||||
return (PyObject *)py_text;
|
||||
return py_text;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -91,13 +89,14 @@ static PyObject *M_Text_Get(PyObject *self, PyObject *args)
|
||||
|
||||
if (name) { /* (name) - Search text by name */
|
||||
|
||||
C_Text *wanted_txt = NULL;
|
||||
PyObject *wanted_txt = NULL;
|
||||
|
||||
while ((txt_iter) && (wanted_txt == NULL)) {
|
||||
|
||||
if (strcmp (name, txt_iter->id.name+2) == 0) {
|
||||
wanted_txt = (C_Text *)PyObject_NEW(C_Text, &Text_Type);
|
||||
if (wanted_txt) wanted_txt->text = txt_iter;
|
||||
wanted_txt = Text_CreatePyObject (txt_iter);
|
||||
}
|
||||
|
||||
txt_iter = txt_iter->id.next;
|
||||
}
|
||||
|
||||
@@ -108,27 +107,27 @@ static PyObject *M_Text_Get(PyObject *self, PyObject *args)
|
||||
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
|
||||
}
|
||||
|
||||
return (PyObject *)wanted_txt;
|
||||
return wanted_txt;
|
||||
}
|
||||
|
||||
else { /* () - return a list of all texts in the scene */
|
||||
int index = 0;
|
||||
PyObject *txtlist, *pystr;
|
||||
PyObject *txtlist, *pyobj;
|
||||
|
||||
txtlist = PyList_New (BLI_countlist (&(G.main->text)));
|
||||
|
||||
if (txtlist == NULL)
|
||||
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create PyList"));
|
||||
|
||||
while (txt_iter) {
|
||||
pystr = PyString_FromString (txt_iter->id.name+2);
|
||||
pyobj = Text_CreatePyObject(txt_iter);
|
||||
|
||||
if (!pystr)
|
||||
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||
if (!pyobj)
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create PyString"));
|
||||
|
||||
PyList_SET_ITEM (txtlist, index, pystr);
|
||||
PyList_SET_ITEM (txtlist, index, pyobj);
|
||||
|
||||
txt_iter = txt_iter->id.next;
|
||||
index++;
|
||||
@@ -139,7 +138,7 @@ static PyObject *M_Text_Get(PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Text_Get */
|
||||
/* Function: M_Text_Load */
|
||||
/* Python equivalent: Blender.Text.Load */
|
||||
/* Description: Receives a filename and returns the text object */
|
||||
/* created from the corresponding file. */
|
||||
@@ -148,13 +147,13 @@ static PyObject *M_Text_Load(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *fname;
|
||||
Text *txt_ptr;
|
||||
C_Text *txt;
|
||||
BPy_Text *txt;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &fname))
|
||||
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected string argument"));
|
||||
|
||||
txt = (C_Text *)PyObject_NEW(C_Text, &Text_Type);
|
||||
txt = (BPy_Text *)PyObject_NEW(BPy_Text, &Text_Type);
|
||||
|
||||
if (!txt)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
@@ -170,31 +169,33 @@ static PyObject *M_Text_Load(PyObject *self, PyObject *args)
|
||||
return (PyObject *)txt;
|
||||
}
|
||||
|
||||
/*@This function removes the text entry from the text editor.
|
||||
* The text is not freed here, but inside the garbage collector. */
|
||||
|
||||
/* This function actually makes Blender dump core if the script is repeatedly
|
||||
* executed, gotta investigate better */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Text_unlink */
|
||||
/* Python equivalent: Blender.Text.unlink */
|
||||
/* Description: Removes the given Text object from Blender */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Text_unlink(PyObject *self, PyObject *args)
|
||||
{
|
||||
C_Text *textobj;
|
||||
BPy_Text *textobj;
|
||||
Text *text;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!", &Text_Type, &textobj))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected a Text object as argument");
|
||||
|
||||
BPY_clear_bad_scriptlinks(textobj->text);
|
||||
free_text_controllers(textobj->text);
|
||||
unlink_text(textobj->text);
|
||||
/*@We actually should not free the text object here, but let the
|
||||
* __del__ method of the wrapper do the job. This would require some
|
||||
* changes in the GUI code though..
|
||||
* So we mark the wrapper as invalid by setting wrapper->data = 0 */
|
||||
free_libblock(&G.main->text, textobj->text);
|
||||
text = ((BPy_Text *)textobj)->text;
|
||||
|
||||
textobj->text = NULL; /* XXX */
|
||||
Py_XDECREF(textobj); /* XXX just a guess -- works ? */
|
||||
if (!text)
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"this text was already unlinked!");
|
||||
|
||||
BPY_clear_bad_scriptlinks(text);
|
||||
free_text_controllers(text);
|
||||
unlink_text(text);
|
||||
|
||||
free_libblock(&G.main->text, text);
|
||||
|
||||
((BPy_Text *)textobj)->text = NULL;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
@@ -215,9 +216,27 @@ PyObject *Text_Init (void)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Text methods: */
|
||||
/* Function: Text_CreatePyObject */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Text_getName(C_Text *self)
|
||||
PyObject *Text_CreatePyObject (Text *txt)
|
||||
{
|
||||
BPy_Text *pytxt;
|
||||
|
||||
pytxt = (BPy_Text *)PyObject_NEW (BPy_Text, &Text_Type);
|
||||
|
||||
if (!pytxt)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create BPy_Text PyObject");
|
||||
|
||||
pytxt->text = txt;
|
||||
|
||||
return (PyObject *)pytxt;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Text methods: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Text_getName(BPy_Text *self)
|
||||
{
|
||||
PyObject *attr = PyString_FromString(self->text->id.name+2);
|
||||
|
||||
@@ -227,7 +246,7 @@ static PyObject *Text_getName(C_Text *self)
|
||||
"couldn't get Text.name attribute");
|
||||
}
|
||||
|
||||
static PyObject *Text_getFilename(C_Text *self)
|
||||
static PyObject *Text_getFilename(BPy_Text *self)
|
||||
{
|
||||
PyObject *attr = PyString_FromString(self->text->name);
|
||||
|
||||
@@ -237,7 +256,7 @@ static PyObject *Text_getFilename(C_Text *self)
|
||||
"couldn't get Text.filename attribute");
|
||||
}
|
||||
|
||||
static PyObject *Text_getNLines(C_Text *self)
|
||||
static PyObject *Text_getNLines(BPy_Text *self)
|
||||
{ /* text->nlines isn't updated in Blender (?) */
|
||||
int nlines = 0;
|
||||
TextLine *line;
|
||||
@@ -260,7 +279,7 @@ static PyObject *Text_getNLines(C_Text *self)
|
||||
"couldn't get Text.nlines attribute");
|
||||
}
|
||||
|
||||
static PyObject *Text_setName(C_Text *self, PyObject *args)
|
||||
static PyObject *Text_setName(BPy_Text *self, PyObject *args)
|
||||
{
|
||||
char *name;
|
||||
char buf[21];
|
||||
@@ -277,7 +296,7 @@ static PyObject *Text_setName(C_Text *self, PyObject *args)
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Text_clear(C_Text *self, PyObject *args)
|
||||
static PyObject *Text_clear(BPy_Text *self, PyObject *args)
|
||||
{
|
||||
int oldstate;
|
||||
|
||||
@@ -295,7 +314,7 @@ static PyObject *Text_clear(C_Text *self, PyObject *args)
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Text_set(C_Text *self, PyObject *args)
|
||||
static PyObject *Text_set(BPy_Text *self, PyObject *args)
|
||||
{
|
||||
int ival;
|
||||
char *attr;
|
||||
@@ -315,7 +334,7 @@ static PyObject *Text_set(C_Text *self, PyObject *args)
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Text_write(C_Text *self, PyObject *args)
|
||||
static PyObject *Text_write(BPy_Text *self, PyObject *args)
|
||||
{
|
||||
char *str;
|
||||
int oldstate;
|
||||
@@ -337,7 +356,7 @@ static PyObject *Text_write(C_Text *self, PyObject *args)
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Text_asLines(C_Text *self, PyObject *args)
|
||||
static PyObject *Text_asLines(BPy_Text *self, PyObject *args)
|
||||
{
|
||||
TextLine *line;
|
||||
PyObject *list, *ob;
|
||||
@@ -363,24 +382,29 @@ static PyObject *Text_asLines(C_Text *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: TextDeAlloc */
|
||||
/* Description: This is a callback function for the C_Text type. It is */
|
||||
/* Function: Text_dealloc */
|
||||
/* Description: This is a callback function for the BPy_Text type. It is */
|
||||
/* the destructor function. */
|
||||
/*****************************************************************************/
|
||||
static void TextDeAlloc (C_Text *self)
|
||||
static void Text_dealloc (BPy_Text *self)
|
||||
{
|
||||
PyObject_DEL (self);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: TextGetAttr */
|
||||
/* Description: This is a callback function for the C_Text type. It is */
|
||||
/* the function that accesses C_Text member variables and */
|
||||
/* Function: Text_getAttr */
|
||||
/* Description: This is a callback function for the BPy_Text type. It is */
|
||||
/* the function that accesses BPy_Text member variables and */
|
||||
/* methods. */
|
||||
/*****************************************************************************/
|
||||
static PyObject* TextGetAttr (C_Text *self, char *name)
|
||||
static PyObject *Text_getAttr (BPy_Text *self, char *name)
|
||||
{
|
||||
PyObject *attr = Py_None;
|
||||
Text *text = self->text;
|
||||
|
||||
if (!text || !Text_IsLinked(text))
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"Text was already deleted!");
|
||||
|
||||
if (strcmp(name, "name") == 0)
|
||||
attr = PyString_FromString(self->text->id.name+2);
|
||||
@@ -402,19 +426,24 @@ static PyObject* TextGetAttr (C_Text *self, char *name)
|
||||
if (attr != Py_None) return attr; /* attribute found, return its value */
|
||||
|
||||
/* not an attribute, search the methods table */
|
||||
return Py_FindMethod(C_Text_methods, (PyObject *)self, name);
|
||||
return Py_FindMethod(BPy_Text_methods, (PyObject *)self, name);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: TextSetAttr */
|
||||
/* Description: This is a callback function for the C_Text type. It is the */
|
||||
/* Function: Text_setAttr */
|
||||
/* Description: This is a callback function for the BPy_Text type. It is the */
|
||||
/* function that changes Text Data members values. If this */
|
||||
/* data is linked to a Blender Text, it also gets updated. */
|
||||
/*****************************************************************************/
|
||||
static int TextSetAttr (C_Text *self, char *name, PyObject *value)
|
||||
static int Text_setAttr (BPy_Text *self, char *name, PyObject *value)
|
||||
{
|
||||
PyObject *valtuple;
|
||||
PyObject *error = NULL;
|
||||
Text *text = self->text;
|
||||
|
||||
if (!text || !Text_IsLinked(text))
|
||||
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
|
||||
@@ -445,36 +474,58 @@ static int TextSetAttr (C_Text *self, char *name, PyObject *value)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: TextCompare */
|
||||
/* Description: This is a callback function for the C_Text type. It */
|
||||
/* Function: Text_compare */
|
||||
/* Description: This is a callback function for the BPy_Text type. It */
|
||||
/* compares two Text_Type objects. Only the "==" and "!=" */
|
||||
/* comparisons are meaninful. Returns 0 for equality and -1 if */
|
||||
/* they don't point to the same Blender Text struct. */
|
||||
/* In Python it becomes 1 if they are equal, 0 otherwise. */
|
||||
/*****************************************************************************/
|
||||
static int TextCompare (C_Text *a, C_Text *b)
|
||||
static int Text_compare (BPy_Text *a, BPy_Text *b)
|
||||
{
|
||||
Text *pa = a->text, *pb = b->text;
|
||||
return (pa == pb) ? 0:-1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: TextPrint */
|
||||
/* Description: This is a callback function for the C_Text type. It */
|
||||
/* Function: Text_print */
|
||||
/* Description: This is a callback function for the BPy_Text type. It */
|
||||
/* builds a meaninful string to 'print' text objects. */
|
||||
/*****************************************************************************/
|
||||
static int TextPrint(C_Text *self, FILE *fp, int flags)
|
||||
static int Text_print(BPy_Text *self, FILE *fp, int flags)
|
||||
{
|
||||
if (self->text && Text_IsLinked(self->text))
|
||||
fprintf(fp, "[Text \"%s\"]", self->text->id.name+2);
|
||||
else
|
||||
fprintf(fp, "[Text <deleted>]");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: TextRepr */
|
||||
/* Description: This is a callback function for the C_Text type. It */
|
||||
/* Function: Text_repr */
|
||||
/* Description: This is a callback function for the BPy_Text type. It */
|
||||
/* builds a meaninful string to represent text objects. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *TextRepr (C_Text *self)
|
||||
static PyObject *Text_repr (BPy_Text *self)
|
||||
{
|
||||
if (self->text && Text_IsLinked(self->text))
|
||||
return PyString_FromString(self->text->id.name+2);
|
||||
else
|
||||
return PyString_FromString("<deleted>");
|
||||
}
|
||||
|
||||
/* internal function to confirm if a Text wasn't unlinked */
|
||||
static int Text_IsLinked(Text *text)
|
||||
{
|
||||
Text *txt_iter = G.main->text.first;
|
||||
|
||||
while (txt_iter) {
|
||||
if (text == txt_iter) return 1;
|
||||
txt_iter = txt_iter->id.next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -76,11 +76,11 @@ 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 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 the text window";
|
||||
"(text) - remove Text object 'text' from Blender";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Text module: */
|
||||
@@ -96,30 +96,30 @@ struct PyMethodDef M_Text_methods[] = {
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Text structure definition: */
|
||||
/* Python BPy_Text structure definition: */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Text *text;
|
||||
|
||||
} C_Text;
|
||||
} BPy_Text;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Text methods declarations: */
|
||||
/* Python BPy_Text methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Text_getName(C_Text *self);
|
||||
static PyObject *Text_getFilename(C_Text *self);
|
||||
static PyObject *Text_getNLines(C_Text *self);
|
||||
static PyObject *Text_setName(C_Text *self, PyObject *args);
|
||||
static PyObject *Text_clear(C_Text *self, PyObject *args);
|
||||
static PyObject *Text_write(C_Text *self, PyObject *args);
|
||||
static PyObject *Text_set(C_Text *self, PyObject *args);
|
||||
static PyObject *Text_asLines(C_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 C_Text methods table: */
|
||||
/* Python BPy_Text methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef C_Text_methods[] = {
|
||||
static PyMethodDef BPy_Text_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", (PyCFunction)Text_getName, METH_NOARGS,
|
||||
"() - Return Text Object name"},
|
||||
@@ -143,12 +143,12 @@ static PyMethodDef C_Text_methods[] = {
|
||||
/*****************************************************************************/
|
||||
/* Python Text_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static void TextDeAlloc (C_Text *self);
|
||||
static int TextPrint (C_Text *self, FILE *fp, int flags);
|
||||
static int TextSetAttr (C_Text *self, char *name, PyObject *v);
|
||||
static PyObject *TextGetAttr (C_Text *self, char *name);
|
||||
static int TextCompare (C_Text *a, C_Text *b);
|
||||
static PyObject *TextRepr (C_Text *self);
|
||||
static void Text_dealloc (BPy_Text *self);
|
||||
static int Text_print (BPy_Text *self, FILE *fp, int flags);
|
||||
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: */
|
||||
@@ -157,16 +157,16 @@ PyTypeObject Text_Type =
|
||||
{
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"Text", /* tp_name */
|
||||
sizeof (C_Text), /* tp_basicsize */
|
||||
"Blender Text", /* tp_name */
|
||||
sizeof (BPy_Text), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)TextDeAlloc, /* tp_dealloc */
|
||||
(printfunc)TextPrint, /* tp_print */
|
||||
(getattrfunc)TextGetAttr, /* tp_getattr */
|
||||
(setattrfunc)TextSetAttr, /* tp_setattr */
|
||||
(cmpfunc)TextCompare, /* tp_compare */
|
||||
(reprfunc)TextRepr, /* tp_repr */
|
||||
(destructor)Text_dealloc, /* tp_dealloc */
|
||||
(printfunc)Text_print, /* 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 */
|
||||
@@ -174,8 +174,10 @@ PyTypeObject Text_Type =
|
||||
0,0,0,0,0,0,
|
||||
0, /* tp_doc */
|
||||
0,0,0,0,0,0,
|
||||
C_Text_methods, /* tp_methods */
|
||||
BPy_Text_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
};
|
||||
|
||||
static int Text_IsLinked(Text *text);
|
||||
|
||||
#endif /* EXPP_TEXT_H */
|
||||
|
124
source/blender/python/api2_2x/doc/Text.py
Normal file
124
source/blender/python/api2_2x/doc/Text.py
Normal file
@@ -0,0 +1,124 @@
|
||||
# Blender.Text module and the Text PyType object
|
||||
|
||||
"""
|
||||
The Blender.Text submodule
|
||||
|
||||
This module provides access to B{Text} objects in Blender.
|
||||
|
||||
Example::
|
||||
import Blender
|
||||
from Blender import Text
|
||||
#
|
||||
txt = Text.New("MyText") # create a new Text object
|
||||
print Text.Get() # current list of Texts in Blender
|
||||
txt.write("Appending some ") # appending text
|
||||
txt.write("text to my\\n") # '\\n' inserts new-line markers
|
||||
txt.write("text buffer.")
|
||||
print txt.asLines() # retrieving the buffer as a list of lines
|
||||
Text.unlink(txt) # removing a Text object
|
||||
"""
|
||||
|
||||
def New (name = None, follow_cursor = 0):
|
||||
"""
|
||||
Create a new Text object.
|
||||
@type name: string
|
||||
@param name: The Text name.
|
||||
@type follow_cursor: int
|
||||
@param follow_cursor: The text follow flag: if 1, the text display always
|
||||
follows the cursor.
|
||||
@rtype: Blender Text
|
||||
@return: The created Text Data object.
|
||||
"""
|
||||
|
||||
def Get (name = None):
|
||||
"""
|
||||
Get the Text object(s) from Blender.
|
||||
@type name: string
|
||||
@param name: The name of the Text object.
|
||||
@rtype: Blender Text or a list of Blender Texts
|
||||
@return: It depends on the 'name' parameter:
|
||||
- (name): The Text object with the given name;
|
||||
- (): A list with all Text objects in the current scene.
|
||||
"""
|
||||
|
||||
def Load (filename):
|
||||
"""
|
||||
Load a file into a Blender Text object.
|
||||
@type filename: string
|
||||
@param filename: The name of the file to load.
|
||||
@rtype: Blender Text
|
||||
@return: A Text object with the contents of the loaded file.
|
||||
"""
|
||||
|
||||
def unlink(textobj):
|
||||
"""
|
||||
Unlink (remove) the given Text object from Blender.
|
||||
@type textobj: Blender Text
|
||||
@param textobj: The Text object to be deleted.
|
||||
"""
|
||||
|
||||
class Text:
|
||||
"""
|
||||
The Text object
|
||||
===============
|
||||
This object gives access to Texts in Blender.
|
||||
@cvar name: The Text name.
|
||||
@cvar filename: The filename of the file loaded into this Text.
|
||||
@cvar mode: The follow_mode flag: if 1 it is 'on'; if 0, 'off'.
|
||||
@cvar nlines: The number of lines in this Text.
|
||||
"""
|
||||
|
||||
def getName():
|
||||
"""
|
||||
Get the name of this Text object.
|
||||
@rtype: string
|
||||
"""
|
||||
|
||||
def setName(name):
|
||||
"""
|
||||
Set the name of this Text object.
|
||||
@type name: string
|
||||
@param name: The new name.
|
||||
"""
|
||||
|
||||
def getFilename():
|
||||
"""
|
||||
Get the filename of the file loaded into this Text object.
|
||||
@rtype: string
|
||||
"""
|
||||
|
||||
def getNLines():
|
||||
"""
|
||||
Get the number of lines in this Text buffer.
|
||||
@rtype: int
|
||||
"""
|
||||
|
||||
def clear():
|
||||
"""
|
||||
Clear this Text object: its buffer becomes empty.
|
||||
"""
|
||||
|
||||
def set(attribute, value):
|
||||
"""
|
||||
Set this Text's attributes.
|
||||
@type attribute: string
|
||||
@param attribute: The attribute to change:
|
||||
currently, 'follow_cursor' is the only one available. It can be
|
||||
turned 'on' with value = 1 and 'off' with value = 0.
|
||||
@type value: int
|
||||
@param value: The new attribute value.
|
||||
"""
|
||||
|
||||
def write(data):
|
||||
"""
|
||||
Append a string to this Text buffer.
|
||||
@type data: string
|
||||
@param data: The string to append to the text buffer.
|
||||
"""
|
||||
|
||||
def asLines():
|
||||
"""
|
||||
Retrieve the contents of this Text buffer as a list of strings.
|
||||
@rtype: list
|
||||
@return: A list of strings.
|
||||
"""
|
29
source/blender/python/api2_2x/doc/testtext.py
Normal file
29
source/blender/python/api2_2x/doc/testtext.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Test Blender.Text
|
||||
|
||||
import Blender
|
||||
from Blender import Text
|
||||
|
||||
txt = Text.New("MyText")
|
||||
all_texts = Text.Get()
|
||||
|
||||
for i in [1,4,7]:
|
||||
txt.write("%d\n%d\n%d little indians\n" % (i, i+1, i+2))
|
||||
|
||||
x = txt.getNLines()
|
||||
|
||||
txt.write("%d little indian boys!" % x)
|
||||
|
||||
lines = txt.asLines()
|
||||
|
||||
txt.clear()
|
||||
txt.write("... Yo-ho-ho! And a bottle of rum!")
|
||||
|
||||
for s in lines:
|
||||
print s
|
||||
|
||||
print all_texts
|
||||
print txt.asLines()
|
||||
|
||||
Text.unlink(txt)
|
||||
|
||||
print all_texts
|
@@ -44,6 +44,7 @@
|
||||
#include <DNA_effect_types.h>
|
||||
#include <DNA_meta_types.h>
|
||||
#include <DNA_image_types.h>
|
||||
#include <DNA_text_types.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global variables */
|
||||
@@ -128,11 +129,14 @@ PyObject * Image_Init (void);
|
||||
PyObject * Image_CreatePyObject (Image *image);
|
||||
int Image_CheckPyObject (PyObject *pyobj);
|
||||
|
||||
/* Text */
|
||||
PyObject * Text_Init (void);
|
||||
PyObject * Text_CreatePyObject (Text *txt);
|
||||
|
||||
/* Init functions for other modules */
|
||||
PyObject * Window_Init (void);
|
||||
PyObject * Draw_Init (void);
|
||||
PyObject * BGL_Init (void);
|
||||
PyObject * Text_Init (void);
|
||||
PyObject * M_World_Init (void);
|
||||
|
||||
#endif /* EXPP_modules_h */
|
||||
|
Reference in New Issue
Block a user