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:
Diffstat (limited to 'source/blender/python/api2_2x/Text.c')
-rw-r--r--source/blender/python/api2_2x/Text.c401
1 files changed, 18 insertions, 383 deletions
diff --git a/source/blender/python/api2_2x/Text.c b/source/blender/python/api2_2x/Text.c
index 9719daaa3d4..308ad094c7b 100644
--- a/source/blender/python/api2_2x/Text.c
+++ b/source/blender/python/api2_2x/Text.c
@@ -34,13 +34,9 @@
#include "BKE_global.h"
#include "BKE_main.h"
#include "BIF_drawtext.h"
-#include "BIF_screen.h"
#include "BKE_text.h"
-#include "BKE_suggestions.h"
#include "BLI_blenlib.h"
-#include "DNA_screen_types.h"
#include "DNA_space_types.h"
-#include "MEM_guardedalloc.h"
#include "gen_utils.h"
#include "gen_library.h"
#include "../BPY_extern.h"
@@ -94,20 +90,9 @@ struct PyMethodDef M_Text_methods[] = {
static PyObject *Text_getFilename( BPy_Text * self );
static PyObject *Text_getNLines( BPy_Text * self );
static PyObject *Text_clear( BPy_Text * self );
-static PyObject *Text_reset( BPy_Text * self );
-static PyObject *Text_readline( BPy_Text * self );
static PyObject *Text_write( BPy_Text * self, PyObject * value );
-static PyObject *Text_insert( BPy_Text * self, PyObject * value );
-static PyObject *Text_delete( BPy_Text * self, PyObject * value );
static PyObject *Text_set( BPy_Text * self, PyObject * args );
-static PyObject *Text_asLines( BPy_Text * self, PyObject * args );
-static PyObject *Text_getCursorPos( BPy_Text * self );
-static PyObject *Text_setCursorPos( BPy_Text * self, PyObject * args );
-static PyObject *Text_getSelectPos( BPy_Text * self );
-static PyObject *Text_setSelectPos( BPy_Text * self, PyObject * args );
-static PyObject *Text_markSelection( BPy_Text * self, PyObject * args );
-static PyObject *Text_suggest( BPy_Text * self, PyObject * args );
-static PyObject *Text_showDocs( BPy_Text * self, PyObject * args );
+static PyObject *Text_asLines( BPy_Text * self );
/*****************************************************************************/
/* Python BPy_Text methods table: */
@@ -124,34 +109,12 @@ static PyMethodDef BPy_Text_methods[] = {
"(str) - Change Text Object name"},
{"clear", ( PyCFunction ) Text_clear, METH_NOARGS,
"() - Clear Text buffer"},
- {"reset", ( PyCFunction ) Text_reset, METH_NOARGS,
- "() - Moves the IO pointer back to the start of the Text buffer for reading"},
- {"readline", ( PyCFunction ) Text_readline, METH_NOARGS,
- "() - Reads a line of text from the buffer and returns it incrementing the internal IO pointer."},
{"write", ( PyCFunction ) Text_write, METH_O,
"(line) - Append string 'str' to Text buffer"},
- {"insert", ( PyCFunction ) Text_insert, METH_O,
- "(line) - Insert string 'str' to Text buffer at cursor location"},
- {"delete", ( PyCFunction ) Text_delete, METH_O,
- "(chars) - Deletes a number of characters to the left (chars<0) or right (chars>0)"},
{"set", ( PyCFunction ) Text_set, METH_VARARGS,
"(name, val) - Set attribute 'name' to value 'val'"},
- {"asLines", ( PyCFunction ) Text_asLines, METH_VARARGS,
- "(start=0, end=nlines) - Return text buffer as a list of lines between start and end"},
- {"getCursorPos", ( PyCFunction ) Text_getCursorPos, METH_NOARGS,
- "() - Return cursor position as (row, col) tuple"},
- {"setCursorPos", ( PyCFunction ) Text_setCursorPos, METH_VARARGS,
- "(row, col) - Set the cursor position to (row, col)"},
- {"getSelectPos", ( PyCFunction ) Text_getSelectPos, METH_NOARGS,
- "() - Return the selection cursor position as (row, col) tuple"},
- {"setSelectPos", ( PyCFunction ) Text_setSelectPos, METH_VARARGS,
- "(row, col) - Set the selection cursor position to (row, col)"},
- {"markSelection", ( PyCFunction ) Text_markSelection, METH_VARARGS,
- "(group, (r, g, b), flags) - Places a marker over the current selection. Group: number > 0, flags: TMARK_TEMP, TMARK_EDITALL, etc."},
- {"suggest", ( PyCFunction ) Text_suggest, METH_VARARGS,
- "(list, prefix='') - Presents a list of suggestions. List is of strings, or tuples. Tuples must be of the form (name, type) where type is one of 'm', 'v', 'f', 'k' for module, variable, function and keyword respectively or '?' for other types"},
- {"showDocs", ( PyCFunction ) Text_showDocs, METH_VARARGS,
- "(docs) - Documentation string"},
+ {"asLines", ( PyCFunction ) Text_asLines, METH_NOARGS,
+ "() - Return text buffer as a list of lines"},
{NULL, NULL, 0, NULL}
};
@@ -339,7 +302,7 @@ static PyObject *M_Text_unlink( PyObject * self, PyObject * args )
/*****************************************************************************/
PyObject *Text_Init( void )
{
- PyObject *submodule, *dict;
+ PyObject *submodule;
if( PyType_Ready( &Text_Type ) < 0 )
return NULL;
@@ -347,19 +310,6 @@ PyObject *Text_Init( void )
submodule =
Py_InitModule3( "Blender.Text", M_Text_methods, M_Text_doc );
- dict = PyModule_GetDict( submodule );
-
-#define EXPP_ADDCONST(x) \
- EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(x))
-
- /* So, for example:
- * EXPP_ADDCONST(LEFTMOUSE) becomes
- * EXPP_dict_set_item_str(dict, "LEFTMOUSE", PyInt_FromLong(LEFTMOUSE))
- */
-
- EXPP_ADDCONST( TMARK_TEMP );
- EXPP_ADDCONST( TMARK_EDITALL );
-
return ( submodule );
}
@@ -377,8 +327,6 @@ PyObject *Text_CreatePyObject( Text * txt )
"couldn't create BPy_Text PyObject" );
pytxt->text = txt;
- pytxt->iol = NULL;
- pytxt->ioc = -1;
return ( PyObject * ) pytxt;
}
@@ -428,47 +376,23 @@ static PyObject *Text_clear( BPy_Text * self)
Py_RETURN_NONE;
}
-static PyObject *Text_reset( BPy_Text * self )
-{
- self->iol = NULL;
- self->ioc = -1;
-
- Py_RETURN_NONE;
-}
-
-static PyObject *Text_readline( BPy_Text * self )
+static PyObject *Text_set( BPy_Text * self, PyObject * args )
{
- PyObject *tmpstr;
-
- if( !self->text )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object" );
-
- /* Reset */
- if (!self->iol && self->ioc == -1) {
- self->iol = self->text->lines.first;
- self->ioc = 0;
- }
+ int ival;
+ char *attr;
- if (!self->iol) {
- PyErr_SetString( PyExc_StopIteration, "End of buffer reached" );
- return PyString_FromString( "" );
- }
+ if( !PyArg_ParseTuple( args, "si", &attr, &ival ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected a string and an int as arguments" );
- if (self->ioc > self->iol->len) {
- self->iol = NULL;
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "Line length exceeded, text may have changed while reading" );
+ if( strcmp( "follow_cursor", attr ) == 0 ) {
+ if( ival )
+ self->text->flags |= EXPP_TEXT_MODE_FOLLOW;
+ else
+ self->text->flags &= EXPP_TEXT_MODE_FOLLOW;
}
- tmpstr = PyString_FromString( self->iol->line + self->ioc );
- if (self->iol->next)
- PyString_ConcatAndDel( &tmpstr, PyString_FromString("\n") );
-
- self->iol = self->iol->next;
- self->ioc = 0;
-
- return tmpstr;
+ Py_RETURN_NONE;
}
static PyObject *Text_write( BPy_Text * self, PyObject * value )
@@ -489,324 +413,35 @@ static PyObject *Text_write( BPy_Text * self, PyObject * value )
txt_move_eof( self->text, 0 );
txt_set_undostate( oldstate );
- Text_reset( self );
-
- Py_RETURN_NONE;
-}
-
-static PyObject *Text_insert( BPy_Text * self, PyObject * value )
-{
- char *str = PyString_AsString(value);
- int oldstate;
-
- if( !self->text )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object" );
-
- if( !str )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected string argument" );
-
- oldstate = txt_get_undostate( );
- txt_insert_buf( self->text, str );
- txt_set_undostate( oldstate );
-
- Text_reset( self );
-
- Py_RETURN_NONE;
-}
-
-static PyObject *Text_delete( BPy_Text * self, PyObject * value )
-{
- int num = PyInt_AsLong(value);
- int oldstate;
-
- if( !self->text )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object" );
-
- if( !num )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected non-zero int argument" );
-
- oldstate = txt_get_undostate( );
- while (num<0) {
- txt_backspace_char(self->text);
- num++;
- }
- while (num>0) {
- txt_delete_char(self->text);
- num--;
- }
- txt_set_undostate( oldstate );
-
- Text_reset( self );
-
- Py_RETURN_NONE;
-}
-
-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_RETURN_NONE;
}
-static PyObject *Text_asLines( BPy_Text * self, PyObject * args )
+static PyObject *Text_asLines( BPy_Text * self )
{
TextLine *line;
PyObject *list, *tmpstr;
- int start=0, end=-1, i;
if( !self->text )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"This object isn't linked to a Blender Text Object" );
- if( !PyArg_ParseTuple( args, "|ii", &start, &end ) )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected upto two optional ints as arguments" );
-
- if (start<0)
- start=0;
-
line = self->text->lines.first;
- for (i = 0; i < start && line->next; i++)
- line= line->next;
-
list = PyList_New( 0 );
if( !list )
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create PyList" );
- while( line && (i < end || end == -1) ) {
+ while( line ) {
tmpstr = PyString_FromString( line->line );
PyList_Append( list, tmpstr );
Py_DECREF(tmpstr);
line = line->next;
- i++;
}
return list;
}
-static PyObject *Text_getCursorPos( BPy_Text * self )
-{
- Text *text;
- TextLine *linep;
- int row, col;
-
- text = self->text;
- if( !text )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object" );
-
- for (row=0,linep=text->lines.first; linep!=text->curl; linep=linep->next)
- row++;
- col= text->curc;
-
- return Py_BuildValue( "ii", row, col );
-}
-
-static PyObject *Text_setCursorPos( BPy_Text * self, PyObject * args )
-{
- int row, col;
- SpaceText *st;
-
- if (!self->text)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object");
-
- if (!PyArg_ParseTuple(args, "ii", &row, &col))
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "expected two ints as arguments.");
- if (row<0) row=0;
- if (col<0) col=0;
-
- txt_move_to(self->text, row, col, 0);
-
- if (curarea->spacetype == SPACE_TEXT && (st=curarea->spacedata.first))
- pop_space_text(st);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *Text_getSelectPos( BPy_Text * self )
-{
- Text *text;
- TextLine *linep;
- int row, col;
-
- text = self->text;
- if( !text )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object" );
-
- for (row=0,linep=text->lines.first; linep!=text->sell; linep=linep->next)
- row++;
- col= text->selc;
-
- return Py_BuildValue( "ii", row, col );
-}
-
-static PyObject *Text_setSelectPos( BPy_Text * self, PyObject * args )
-{
- int row, col;
- SpaceText *st;
-
- if (!self->text)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object");
-
- if (!PyArg_ParseTuple(args, "ii", &row, &col))
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "expected two ints as arguments.");
- if (row<0) row=0;
- if (col<0) col=0;
-
- txt_move_to(self->text, row, col, 1);
-
- if (curarea->spacetype == SPACE_TEXT && (st=curarea->spacedata.first))
- pop_space_text(st);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *Text_markSelection( BPy_Text * self, PyObject * args )
-{
- int group = 0, flags = 0,r, g, b;
- Text *text;
- char color[4];
-
- text = self->text;
- if (!text)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object");
-
- if (!PyArg_ParseTuple(args, "i(iii)i", &group, &r, &g, &b, &flags))
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "expected int, 3-tuple of ints and int as arguments.");
-
- if (text->curl != text->sell)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "Cannot mark multi-line selection.");
-
- color[0] = (char) (r&0xFF);
- color[1] = (char) (g&0xFF);
- color[2] = (char) (b&0xFF);
- color[3] = 255;
-
- group &= 0xFFFF;
-
- txt_add_marker(text, text->curl, text->curc, text->selc, color, group, flags);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *Text_suggest( BPy_Text * self, PyObject * args )
-{
- PyObject *item = NULL, *tup1 = NULL, *tup2 = NULL;
- PyObject *list = NULL;
- int list_len, i;
- char *prefix = NULL, *name, type;
- SpaceText *st;
-
- if (!self->text)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object");
-
- /* Parse args for a list of strings/tuples */
- if (!PyArg_ParseTuple(args, "O!|s", &PyList_Type, &list, &prefix))
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "expected list of strings or tuples followed by an optional string");
-
- if (curarea->spacetype != SPACE_TEXT)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "Active space type is not text");
-
- st = curarea->spacedata.first;
- if (!st || !st->text)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "Active text area has no Text object");
-
- texttool_suggest_clear();
- texttool_text_set_active(st->text);
- list_len = PyList_Size(list);
-
- for (i = 0; i < list_len; i++) {
- item = PyList_GetItem(list, i);
-
- if (PyString_Check(item)) {
- name = PyString_AsString(item);
- type = '?';
- } else if (PyTuple_Check(item) && PyTuple_GET_SIZE(item) == 2) {
- tup1 = PyTuple_GetItem(item, 0);
- tup2 = PyTuple_GetItem(item, 1);
- if (PyString_Check(tup1) && PyString_Check(tup2)) {
- name = PyString_AsString(tup1);
- type = PyString_AsString(tup2)[0];
- } else
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "list must contain tuples of two strings only: (name, type)" );
- } else
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "list must contain only individual strings or tuples of size 2" );
-
- if (!strlen(name) || (type!='m' && type!='v' && type!='f' && type!='k' && type!='?'))
- return EXPP_ReturnPyObjError(PyExc_AttributeError,
- "names must be non-empty and types in ['m', 'v', 'f', 'k', '?']" );
-
- texttool_suggest_add(name, type);
- }
- if (!prefix)
- prefix = "";
- texttool_suggest_prefix(prefix);
- scrarea_queue_redraw(curarea);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *Text_showDocs( BPy_Text * self, PyObject * args )
-{
- char *docs;
- SpaceText *st;
-
- if (!self->text)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "This object isn't linked to a Blender Text Object");
-
- if (!PyArg_ParseTuple(args, "s", &docs))
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected a string as argument" );
-
- if (curarea->spacetype != SPACE_TEXT)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "Active space type is not text");
-
- st = curarea->spacedata.first;
- if (!st || !st->text)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "Active text area has no Text object");
-
- texttool_text_set_active(st->text);
- texttool_docs_show(docs);
- scrarea_queue_redraw(curarea);
-
- Py_RETURN_NONE;
-}
-
/*****************************************************************************/
/* Function: Text_compare */
/* Description: This is a callback function for the BPy_Text type. It */