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')
-rw-r--r--source/blender/python/BPY_extern.h3
-rw-r--r--source/blender/python/BPY_interface.c36
-rw-r--r--source/blender/python/BPY_menus.c40
-rw-r--r--source/blender/python/BPY_menus.h2
-rw-r--r--source/blender/python/api2_2x/Text.c401
-rw-r--r--source/blender/python/api2_2x/Text.h2
-rw-r--r--source/blender/python/api2_2x/doc/Draw.py8
-rw-r--r--source/blender/python/api2_2x/doc/Text.py103
8 files changed, 562 insertions, 33 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index 83b9a66942a..344d0e17797 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -48,6 +48,7 @@ struct bPythonConstraint; /* DNA_constraint_types.h */
struct bConstraintOb; /* DNA_constraint_types.h */
struct bConstraintTarget; /* DNA_constraint_types.h*/
struct Script; /* DNA_screen_types.h */
+struct BPyMenu;
#ifdef __cplusplus
extern "C" {
#endif
@@ -91,6 +92,8 @@ extern "C" {
int BPY_txt_do_python_Text( struct Text *text );
int BPY_menu_do_python( short menutype, int event );
+ int BPY_menu_do_shortcut( short menutype, unsigned short key, unsigned short modifiers );
+ int BPY_menu_invoke( struct BPyMenu *pym, short menutype );
void BPY_run_python_script( char *filename );
int BPY_run_script(struct Script *script);
void BPY_free_compiled_text( struct Text *text );
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c
index 81ac9bea46a..47bec81df7a 100644
--- a/source/blender/python/BPY_interface.c
+++ b/source/blender/python/BPY_interface.c
@@ -556,6 +556,7 @@ void BPY_Err_Handle( char *script_name )
if( exception
&& PyErr_GivenExceptionMatches( exception, PyExc_SyntaxError ) ) {
/* no traceback available when SyntaxError */
+ PyErr_NormalizeException( &exception, &err, &tb );
PyErr_Restore( exception, err, tb ); /* takes away reference! */
PyErr_Print( );
v = PyObject_GetAttrString( err, "lineno" );
@@ -921,8 +922,38 @@ int BPY_run_script(Script *script)
*****************************************************************************/
int BPY_menu_do_python( short menutype, int event )
{
- char *argstr = NULL;
BPyMenu *pym;
+ pym = BPyMenu_GetEntry( menutype, ( short ) event );
+ return BPY_menu_invoke( pym, menutype );
+}
+
+/****************************************************************************
+* Description: This function executes the script by its shortcut.
+* Notes: It is called by the ui code in src/???.c when a user presses an
+* unassigned key combination. Scripts are searched in the BPyMenuTable,
+* using the given menutype and event values to know which one to invoke.
+*****************************************************************************/
+int BPY_menu_do_shortcut( short menutype, unsigned short key, unsigned short qual )
+{
+ BPyMenu *pym;
+ pym = BPyMenu_GetEntry( menutype, 0 );
+
+ while ( pym ) {
+ if ( pym->key && pym->key == key && pym->qual == qual ) {
+ return BPY_menu_invoke( pym, menutype );
+ }
+ pym = pym->next;
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+* Description: This function executes the script described by a menu item.
+*****************************************************************************/
+int BPY_menu_invoke( BPyMenu *pym, short menutype )
+{
+ char *argstr = NULL;
BPySubMenu *pysm;
char scriptname[21];
Script *script = NULL;
@@ -930,8 +961,6 @@ int BPY_menu_do_python( short menutype, int event )
PyGILState_STATE gilstate;
char filestr[FILE_MAX];
- pym = BPyMenu_GetEntry( menutype, ( short ) event );
-
if( !pym )
return 0;
@@ -1015,6 +1044,7 @@ int BPY_menu_do_python( short menutype, int event )
case PYMENU_RENDER:
case PYMENU_WIZARDS:
case PYMENU_SCRIPTTEMPLATE:
+ case PYMENU_TEXTPLUGIN:
case PYMENU_MESHFACEKEY:
break;
diff --git a/source/blender/python/BPY_menus.c b/source/blender/python/BPY_menus.c
index 82da9edbee6..69b50e5c47a 100644
--- a/source/blender/python/BPY_menus.c
+++ b/source/blender/python/BPY_menus.c
@@ -42,6 +42,7 @@
#endif
#include "BKE_global.h"
#include "BKE_utildefines.h"
+#include "BIF_keyval.h"
#include "BLI_blenlib.h"
#include "MEM_guardedalloc.h"
#include "DNA_userdef_types.h" /* for U.pythondir */
@@ -106,6 +107,8 @@ static int bpymenu_group_atoi( char *str )
return PYMENU_ARMATURE;
else if( !strcmp( str, "ScriptTemplate" ) )
return PYMENU_SCRIPTTEMPLATE;
+ else if( !strcmp( str, "TextPlugin" ) )
+ return PYMENU_TEXTPLUGIN;
else if( !strcmp( str, "MeshFaceKey" ) )
return PYMENU_MESHFACEKEY;
else if( !strcmp( str, "AddMesh" ) )
@@ -184,6 +187,9 @@ char *BPyMenu_group_itoa( short menugroup )
case PYMENU_SCRIPTTEMPLATE:
return "ScriptTemplate";
break;
+ case PYMENU_TEXTPLUGIN:
+ return "TextPlugin";
+ break;
case PYMENU_MESHFACEKEY:
return "MeshFaceKey";
break;
@@ -328,6 +334,23 @@ static void bpymenu_set_tooltip( BPyMenu * pymenu, char *tip )
return;
}
+static void bpymenu_set_shortcut( BPyMenu * pymenu, char *combi )
+{
+ unsigned short key, qual;
+
+ if( !pymenu )
+ return;
+
+ if (!decode_key_string(combi, &key, &qual)) {
+ return; /* TODO: Print some error */
+ }
+
+ pymenu->key = key;
+ pymenu->qual = qual;
+
+ return;
+}
+
/* bpymenu_AddEntry:
* try to find an existing pymenu entry with the given type and name;
* if found, update it with new info, otherwise create a new one and fill it.
@@ -688,6 +711,7 @@ void BPyMenu_PrintAllEntries( void )
* # Blender: <code>short int</code> (minimal Blender version)
* # Group: 'group name' (defines menu)
* # Submenu: 'submenu name' related_1word_arg
+ * # Shortcut: Modifier+Key (optional shortcut combination for supported groups)
* # Tooltip: 'tooltip for the menu'
* # \"\"\"
*
@@ -796,13 +820,19 @@ static int bpymenu_ParseFile(FILE *file, char *fname, int is_userdir)
if ((matches == 3) && (strstr(head, "Submenu:") != NULL)) {
bpymenu_AddSubEntry(scriptMenu, middle, tail);
} else {
- /* Tooltip: 'tooltip for the menu */
+ /* Shortcut: 'key+combination' */
matches = sscanf(line, "%[^']'%[^']'%c", head, middle, tail);
- if ((matches == 3) && ((strstr(head, "Tooltip:") != NULL) ||
- (strstr(head, "Tip:") != NULL))) {
- bpymenu_set_tooltip(scriptMenu, middle);
+ if ((matches == 3) && (strstr(head, "Shortcut:") != NULL)) {
+ bpymenu_set_shortcut(scriptMenu, middle);
+ } else {
+ /* Tooltip: 'tooltip for the menu */
+ matches = sscanf(line, "%[^']'%[^']'%c", head, middle, tail);
+ if ((matches == 3) && ((strstr(head, "Tooltip:") != NULL) ||
+ (strstr(head, "Tip:") != NULL))) {
+ bpymenu_set_tooltip(scriptMenu, middle);
+ }
+ parser_state = 0;
}
- parser_state = 0;
}
break;
diff --git a/source/blender/python/BPY_menus.h b/source/blender/python/BPY_menus.h
index 1b557f79286..576d7b8dcd6 100644
--- a/source/blender/python/BPY_menus.h
+++ b/source/blender/python/BPY_menus.h
@@ -59,6 +59,7 @@ typedef struct BPyMenu {
char *name;
char *filename;
char *tooltip;
+ unsigned short key, qual; /* Registered shortcut key */
short version; /* Blender version */
int dir; /* 0: default, 1: U.pythondir */
struct BPySubMenu *submenus;
@@ -99,6 +100,7 @@ typedef enum {
PYMENU_UVCALCULATION,
PYMENU_ARMATURE,
PYMENU_SCRIPTTEMPLATE,
+ PYMENU_TEXTPLUGIN,
PYMENU_HELP,/*Main Help menu items - prob best to leave for 'official' ones*/
PYMENU_HELPSYSTEM,/* Resources, troubleshooting, system tools */
PYMENU_HELPWEBSITES,/* Help -> Websites submenu */
diff --git a/source/blender/python/api2_2x/Text.c b/source/blender/python/api2_2x/Text.c
index 308ad094c7b..a76a6f56224 100644
--- a/source/blender/python/api2_2x/Text.c
+++ b/source/blender/python/api2_2x/Text.c
@@ -34,9 +34,13 @@
#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"
@@ -90,9 +94,20 @@ 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 );
+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 );
/*****************************************************************************/
/* Python BPy_Text methods table: */
@@ -109,12 +124,34 @@ 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_NOARGS,
- "() - Return text buffer as a list of lines"},
+ {"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"},
{NULL, NULL, 0, NULL}
};
@@ -302,7 +339,7 @@ static PyObject *M_Text_unlink( PyObject * self, PyObject * args )
/*****************************************************************************/
PyObject *Text_Init( void )
{
- PyObject *submodule;
+ PyObject *submodule, *dict;
if( PyType_Ready( &Text_Type ) < 0 )
return NULL;
@@ -310,6 +347,19 @@ 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 );
}
@@ -327,6 +377,8 @@ PyObject *Text_CreatePyObject( Text * txt )
"couldn't create BPy_Text PyObject" );
pytxt->text = txt;
+ pytxt->iol = NULL;
+ pytxt->ioc = -1;
return ( PyObject * ) pytxt;
}
@@ -376,23 +428,47 @@ static PyObject *Text_clear( BPy_Text * self)
Py_RETURN_NONE;
}
-static PyObject *Text_set( BPy_Text * self, PyObject * args )
+static PyObject *Text_reset( BPy_Text * self )
{
- int ival;
- char *attr;
+ self->iol = NULL;
+ self->ioc = -1;
- if( !PyArg_ParseTuple( args, "si", &attr, &ival ) )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected a string and an int as arguments" );
+ Py_RETURN_NONE;
+}
- if( strcmp( "follow_cursor", attr ) == 0 ) {
- if( ival )
- self->text->flags |= EXPP_TEXT_MODE_FOLLOW;
- else
- self->text->flags &= EXPP_TEXT_MODE_FOLLOW;
+static PyObject *Text_readline( BPy_Text * self )
+{
+ 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;
}
- Py_RETURN_NONE;
+ if (!self->iol) {
+ PyErr_SetString( PyExc_StopIteration, "End of buffer reached" );
+ return PyString_FromString( "" );
+ }
+
+ if (self->ioc > self->iol->len) {
+ self->iol = NULL;
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "Line length exceeded, text may have changed while reading" );
+ }
+
+ 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;
}
static PyObject *Text_write( BPy_Text * self, PyObject * value )
@@ -413,35 +489,324 @@ 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 )
+static PyObject *Text_asLines( BPy_Text * self, PyObject * args )
{
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 ) {
+ while( line && (i < end || end == -1) ) {
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, *resl = 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 */
diff --git a/source/blender/python/api2_2x/Text.h b/source/blender/python/api2_2x/Text.h
index 0c5e2607f03..73943ddb9cd 100644
--- a/source/blender/python/api2_2x/Text.h
+++ b/source/blender/python/api2_2x/Text.h
@@ -41,6 +41,8 @@ extern PyTypeObject Text_Type;
typedef struct {
PyObject_HEAD
Text * text; /* libdata must be second */
+ TextLine * iol; /* current line being read or NULL if reset */
+ int ioc; /* character offset in line being read */
} BPy_Text;
PyObject *Text_Init( void );
diff --git a/source/blender/python/api2_2x/doc/Draw.py b/source/blender/python/api2_2x/doc/Draw.py
index 18234754315..97e22797902 100644
--- a/source/blender/python/api2_2x/doc/Draw.py
+++ b/source/blender/python/api2_2x/doc/Draw.py
@@ -357,12 +357,14 @@ def PupTreeMenu( menu ):
"""
Create a popup menu tree.
- Each item in the list is a menu item - (str, event), separator - None or submenu - (str, [...]).
+ Each item in the list is: a menu item - (str, event); a separator - None;
+ or submenu - (str, [...]).
- Submenus list uses the same syntax as the menu list.
+ Submenus list uses the same syntax as the menu list. To add a title to the
+ main menu, end the first entry str with '%t' - the event is ignored.
Example::
- result = Draw.PupTreeMenu( [ ("Menu Item 1", 10), ("Menu Item 2", 12), ("SubMenu", [("Menu Item 3", 100), ("MenuItem4", 101) ] ) ] )
+ result = Draw.PupTreeMenu( [ ("Title%t", 0), ("Menu Item 1", 10), ("Menu Item 2", 12), ("SubMenu", [("Menu Item 3", 100), ("MenuItem4", 101) ] ) ] )
@type menu: string
@param menu: A menu list
diff --git a/source/blender/python/api2_2x/doc/Text.py b/source/blender/python/api2_2x/doc/Text.py
index 98ecb664b71..022205573aa 100644
--- a/source/blender/python/api2_2x/doc/Text.py
+++ b/source/blender/python/api2_2x/doc/Text.py
@@ -100,6 +100,19 @@ class Text:
Clear this Text object: its buffer becomes empty.
"""
+ def reset():
+ """
+ Reset the read IO pointer to the start of the buffer.
+ """
+
+ def readline():
+ """
+ Reads a line of text from the buffer from the current IO pointer
+ position to the end of the line. If the text has changed since the last
+ read, reset() *must* be called.
+ @rtype: string
+ """
+
def set(attribute, value):
"""
Set this Text's attributes.
@@ -118,12 +131,94 @@ class Text:
@param data: The string to append to the text buffer.
"""
- def asLines():
+ def insert(data):
"""
- Retrieve the contents of this Text buffer as a list of strings.
+ Inserts a string into this Text buffer at the cursor.
+ @type data: string
+ @param data: The string to insert into the text buffer.
+ """
+
+ def asLines(start=0, end=-1):
+ """
+ Retrieve the contents of this Text buffer as a list of strings between
+ the start and end lines specified. If end < 0 all lines from start will
+ be included.
+ @type start int
+ @param start: Optional index of first line of the span to return
+ @type end int
+ @param end: Optional index of the line to which the span is taken or
+ -1 to include all lines from start
@rtype: list of strings
- @return: A list of strings, one for each line in the buffer
+ @return: A list of strings, one for each line in the buffer between
+ start and end.
+ """
+
+ def getCursorPos():
+ """
+ Retrieve the position of the cursor in this Text buffer.
+ @rtype: (int, int)
+ @return: A pair (row, col) indexing the line and character of the
+ cursor.
+ """
+
+ def setCursorPos(row, col):
+ """
+ Set the position of the cursor in this Text buffer. Any selection will
+ be cleared. Use setSelectPos to extend a selection from the point
+ specified here.
+ @type row: int
+ @param row: The index of the line in which to position the cursor.
+ @type col: int
+ @param col: The index of the character within the line to position the
+ cursor.
+ """
+
+ def getSelectPos():
+ """
+ Retrieve the position of the selection cursor in this Text buffer.
+ @rtype: (int, int)
+ @return: A pair (row, col) indexing the line and character of the
+ selection cursor.
+ """
+
+ def setSelectPos(row, col):
+ """
+ Set the position of the selection cursor in this Text buffer. This
+ method should be called after setCursorPos to extend the selection to
+ the specified point.
+ @type row: int
+ @param row: The index of the line in which to position the cursor.
+ @type col: int
+ @param col: The index of the character within the line to position the
+ cursor.
+ """
+
+ def suggest(list, prefix=''):
+ """
+ Suggest a list of names. If list is a list of tuples (name, type) the
+ list will be formatted to syntax-highlight each entry type. Types must
+ be strings in the list ['m', 'f', 'v', 'k', '?']. It is recommended that
+ the list be sorted, case-insensitively by name.
+
+ @type list: list of tuples or strings
+ @param list: List of pair-tuples of the form (name, type) where name is
+ the suggested name and type is one of 'm' (module or class), 'f'
+ (function or method), 'v' (variable), 'k' (keyword), '?' (other).
+ Lists of plain strings are also accepted where the type is always
+ '?'.
+ @type prefix: string
+ @param prefix: The optional prefix used to limit what is suggested from
+ the list. This is usually whatever precedes the cursor so that
+ backspace will update it.
+ """
+
+ def showDocs(docs):
+ """
+ Displays a word-wrapped message box containing the specified
+ documentation when this Text object is visible.
+ @type docs: string
+ @param docs: The documentation string to display.
"""
import id_generics
-Text.__doc__ += id_generics.attributes \ No newline at end of file
+Text.__doc__ += id_generics.attributes