Text plugin basis with plugin for suggestions/completions. The suggest plugin works for imported global variables, methods, modules and module members. For example typing:

import Blender
from Blender import *
| <- cursor here suggests globals
Blender.Draw.gl| <- cursor here suggests all Draw members starting gl

Currently suggestions are listed in the console when the space is redrawn but will be presented as a menu-style list soon. Also to add are shortcut/activation keys to allow plugins to respond to certain key strokes.
This commit is contained in:
2008-06-24 15:25:25 +00:00
parent 05ce388f35
commit bdc030c664
11 changed files with 561 additions and 1 deletions

View File

@@ -1066,6 +1066,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;

View File

@@ -106,6 +106,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 +186,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;

View File

@@ -99,6 +99,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 */

View File

@@ -34,8 +34,11 @@
#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 "gen_utils.h"
#include "gen_library.h"
@@ -96,6 +99,7 @@ static PyObject *Text_set( BPy_Text * self, PyObject * args );
static PyObject *Text_asLines( BPy_Text * self );
static PyObject *Text_getCursorPos( BPy_Text * self );
static PyObject *Text_setCursorPos( BPy_Text * self, PyObject * args );
static PyObject *Text_suggest( BPy_Text * self, PyObject * args );
/*****************************************************************************/
/* Python BPy_Text methods table: */
@@ -124,6 +128,8 @@ static PyMethodDef BPy_Text_methods[] = {
"() - Return cursor position as (row, col) tuple"},
{"setCursorPos", ( PyCFunction ) Text_setCursorPos, METH_VARARGS,
"(row, col) - Set the cursor position to (row, col)"},
{"suggest", ( PyCFunction ) Text_suggest, METH_VARARGS,
"(list) - List of tuples of the form (name, type) where type is one of 'm', 'v', 'f' for module, variable and function respectively"},
{NULL, NULL, 0, NULL}
};
@@ -511,6 +517,57 @@ static PyObject *Text_setCursorPos( BPy_Text * self, PyObject * args )
Py_RETURN_NONE;
}
static PyObject *Text_suggest( BPy_Text * self, PyObject * args )
{
PyObject *item = NULL;
PyObject *list = NULL, *resl = NULL;
int list_len, i;
char *prefix, *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 tuples */
if(!PyArg_ParseTuple(args, "O!s", &PyList_Type, &list, &prefix))
return EXPP_ReturnPyObjError(PyExc_TypeError,
"expected list of tuples followed by a 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");
list_len = PyList_Size(list);
clear_suggest_text();
for (i = 0; i < list_len; i++) {
item = PyList_GetItem(list, i);
if (!PyTuple_Check(item) || PyTuple_GET_SIZE(item) != 2)
return EXPP_ReturnPyObjError(PyExc_AttributeError,
"list must contain only tuples of size 2" );
name = PyString_AsString(PyTuple_GetItem(item, 0));
type = PyString_AsString(PyTuple_GetItem(item, 1))[0];
if (!strlen(name) || (type!='m' && type!='v' && type!='f'))
return EXPP_ReturnPyObjError(PyExc_AttributeError,
"layer values must be in the range [1, 20]" );
add_suggestion(name, type);
}
update_suggestions(prefix);
set_suggest_text(st->text);
scrarea_queue_redraw(curarea);
Py_RETURN_NONE;
}
/*****************************************************************************/
/* Function: Text_compare */
/* Description: This is a callback function for the BPy_Text type. It */

View File

@@ -150,5 +150,15 @@ class Text:
cursor.
"""
def suggest(list):
"""
Set the suggestion list to the given list of tuples. This list *must* be
sorted by its first element, name.
@type list: list of tuples
@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).
"""
import id_generics
Text.__doc__ += id_generics.attributes
Text.__doc__ += id_generics.attributes