New UI popup block Blender.Draw.UIBlock(func) - similar to PupBlock but less restrictive since it uses user defined buttons.
Also added per button callbacks, so each button can have its own python functions.
This commit is contained in:
@@ -70,6 +70,14 @@ current image frame, some images change frame if they are a sequence */
|
||||
|
||||
#define ButtonObject_Check(v) ((v)->ob_type == &Button_Type)
|
||||
|
||||
#define UI_METHOD_ERRORCHECK \
|
||||
if (check_button_event(&event) == -1)\
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,\
|
||||
"button event argument must be in the range [0, 16382]");\
|
||||
if (callback && !PyCallable_Check(callback))\
|
||||
return EXPP_ReturnPyObjError( PyExc_ValueError,\
|
||||
"callback is not a python function");\
|
||||
|
||||
/* pointer to main dictionary defined in Blender.c */
|
||||
extern PyObject *g_blenderdict;
|
||||
|
||||
@@ -98,6 +106,7 @@ static PyObject *Method_Register( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_Redraw( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_Draw( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_Create( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_UIBlock( PyObject * self, PyObject * args );
|
||||
|
||||
static PyObject *Method_Button( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_Menu( PyObject * self, PyObject * args );
|
||||
@@ -111,8 +120,8 @@ static PyObject *Method_String( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_GetStringWidth( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_Text( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_Label( PyObject * self, PyObject * args );
|
||||
/* by Campbell: */
|
||||
static PyObject *Method_PupMenu( PyObject * self, PyObject * args );
|
||||
/* next Five by Campbell: */
|
||||
static PyObject *Method_PupIntInput( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_PupFloatInput( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_PupStrInput( PyObject * self, PyObject * args );
|
||||
@@ -126,8 +135,13 @@ static PyObject *Method_PupBlock( PyObject * self, PyObject * args );
|
||||
static uiBlock *Get_uiBlock( void );
|
||||
static void py_slider_update( void *butv, void *data2_unused );
|
||||
|
||||
/* hack to get 1 block for the UIBlock, only ever 1 at a time */
|
||||
static uiBlock *uiblock=NULL;
|
||||
|
||||
static char Draw_doc[] = "The Blender.Draw submodule";
|
||||
|
||||
static char Method_UIBlock_doc[] = "(drawfunc, x,y) - Popup dialog where buttons can be drawn (expemental)";
|
||||
|
||||
static char Method_Register_doc[] =
|
||||
"(draw, event, button) - Register callbacks for windowing\n\n\
|
||||
(draw) A function to draw the screen, taking no arguments\n\
|
||||
@@ -354,6 +368,7 @@ static char Method_Exit_doc[] = "() - Exit the windowing interface";
|
||||
|
||||
static struct PyMethodDef Draw_methods[] = {
|
||||
MethodDef( Create ),
|
||||
MethodDef( UIBlock ),
|
||||
MethodDef( Button ),
|
||||
MethodDef( Toggle ),
|
||||
MethodDef( Menu ),
|
||||
@@ -718,6 +733,27 @@ void BPY_spacescript_do_pywin_event( SpaceScript * sc, unsigned short event,
|
||||
}
|
||||
}
|
||||
|
||||
static void exec_but_callback(PyObject *callback, int event)
|
||||
{
|
||||
PyObject *result;
|
||||
|
||||
if (callback==NULL || callback == Py_None)
|
||||
return;
|
||||
|
||||
result = PyObject_CallObject( callback, Py_BuildValue( "(i)", event ) );
|
||||
if (!result) {
|
||||
PyErr_Print( );
|
||||
error( "Python script error: check console" );
|
||||
}
|
||||
Py_XDECREF( result );
|
||||
}
|
||||
|
||||
static void set_pycallback(uiBut *ubut, PyObject *callback, int event)
|
||||
{
|
||||
if (!callback || !PyCallable_Check(callback)) return;
|
||||
uiButSetFunc(ubut, exec_but_callback, callback, event);
|
||||
}
|
||||
|
||||
static PyObject *Method_Exit( PyObject * self, PyObject * args )
|
||||
{
|
||||
SpaceScript *sc;
|
||||
@@ -910,15 +946,54 @@ static PyObject *Method_Create( PyObject * self, PyObject * args )
|
||||
return (PyObject*) but;
|
||||
}
|
||||
|
||||
static PyObject *Method_UIBlock( PyObject * self, PyObject * args )
|
||||
{
|
||||
PyObject *val = NULL;
|
||||
PyObject *result = NULL;
|
||||
ListBase listb= {NULL, NULL};
|
||||
|
||||
if ( !PyArg_ParseTuple( args, "O", &val ) || !PyCallable_Check( val ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"expected 1 python function and 2 ints" );
|
||||
|
||||
if (uiblock)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"cannot run more then 1 UIBlock at a time" );
|
||||
|
||||
mywinset(G.curscreen->mainwin);
|
||||
uiblock= uiNewBlock(&listb, "numbuts", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
|
||||
|
||||
uiBlockSetFlag(uiblock, UI_BLOCK_LOOP|UI_BLOCK_REDRAW);
|
||||
result = PyObject_CallObject( val, Py_BuildValue( "()" ) );
|
||||
|
||||
if (!result) {
|
||||
PyErr_Print( );
|
||||
error( "Python script error: check console" );
|
||||
} else {
|
||||
uiBoundsBlock(uiblock, 5);
|
||||
uiDoBlocks(&listb, 0);
|
||||
}
|
||||
uiFreeBlocks(&listb);
|
||||
uiblock = NULL;
|
||||
|
||||
Py_XDECREF( result );
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static uiBlock *Get_uiBlock( void )
|
||||
{
|
||||
char butblock[32];
|
||||
|
||||
/* Global, used now for UIBlock */
|
||||
if (uiblock) {
|
||||
return uiblock;
|
||||
}
|
||||
/* Local */
|
||||
sprintf( butblock, "win %d", curarea->win );
|
||||
|
||||
return uiGetBlock( butblock, curarea );
|
||||
}
|
||||
|
||||
|
||||
/* We restrict the acceptable event numbers to a proper "free" range
|
||||
* according to other spaces in Blender.
|
||||
* winqread***space() (space events callbacks) use short for events
|
||||
@@ -930,37 +1005,11 @@ static int check_button_event(int *event) {
|
||||
(*event > EXPP_BUTTON_EVENTS_MAX)) {
|
||||
return -1;
|
||||
}
|
||||
*event += EXPP_BUTTON_EVENTS_OFFSET;
|
||||
if (uiblock==NULL) /* For UIBlock we need non offset UI elements */
|
||||
*event += EXPP_BUTTON_EVENTS_OFFSET;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *Method_Button( PyObject * self, PyObject * args )
|
||||
{
|
||||
uiBlock *block;
|
||||
char *name, *tip = NULL;
|
||||
int event;
|
||||
int x, y, w, h;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "siiiii|s", &name, &event,
|
||||
&x, &y, &w, &h, &tip ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string, five ints and optionally another string as arguments" );
|
||||
|
||||
if (check_button_event(&event) == -1)
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"button event argument must be in the range [0, 16382]");
|
||||
|
||||
block = Get_uiBlock( );
|
||||
|
||||
if( block )
|
||||
uiDefBut( block, BUT, event, name, (short)x, (short)y, (short)w, (short)h, 0, 0, 0, 0, 0,
|
||||
tip );
|
||||
|
||||
return EXPP_incr_ret( Py_None );
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyObject *Method_BeginAlign( PyObject * self, PyObject * args )
|
||||
{
|
||||
uiBlock *block = Get_uiBlock( );
|
||||
@@ -981,6 +1030,29 @@ static PyObject *Method_EndAlign( PyObject * self, PyObject * args )
|
||||
return EXPP_incr_ret( Py_None );
|
||||
}
|
||||
|
||||
static PyObject *Method_Button( PyObject * self, PyObject * args )
|
||||
{
|
||||
uiBlock *block;
|
||||
char *name, *tip = NULL;
|
||||
int event;
|
||||
int x, y, w, h;
|
||||
PyObject *callback=NULL;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "siiiii|sO", &name, &event,
|
||||
&x, &y, &w, &h, &tip, &callback ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string, five ints and optionally string and callback arguments" );
|
||||
|
||||
UI_METHOD_ERRORCHECK;
|
||||
|
||||
block = Get_uiBlock( );
|
||||
if( block ) {
|
||||
uiBut *ubut = uiDefBut( block, BUT, event, name, (short)x, (short)y, (short)w, (short)h, 0, 0, 0, 0, 0, tip );
|
||||
set_pycallback(ubut, callback, event);
|
||||
}
|
||||
return EXPP_incr_ret( Py_None );
|
||||
}
|
||||
|
||||
static PyObject *Method_Menu( PyObject * self, PyObject * args )
|
||||
{
|
||||
uiBlock *block;
|
||||
@@ -988,25 +1060,25 @@ static PyObject *Method_Menu( PyObject * self, PyObject * args )
|
||||
int event, def;
|
||||
int x, y, w, h;
|
||||
Button *but;
|
||||
PyObject *callback=NULL;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "siiiiii|s", &name, &event,
|
||||
&x, &y, &w, &h, &def, &tip ) )
|
||||
if( !PyArg_ParseTuple( args, "siiiiii|sO", &name, &event,
|
||||
&x, &y, &w, &h, &def, &tip, &callback ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string, six ints and optionally another string as arguments" );
|
||||
|
||||
if (check_button_event(&event) == -1)
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"button event argument must be in the range [0, 16382]");
|
||||
"expected a string, six ints and optionally string and callback arguments" );
|
||||
|
||||
UI_METHOD_ERRORCHECK;
|
||||
|
||||
but = newbutton( );
|
||||
but->type = BINT_TYPE;
|
||||
but->val.asint = def;
|
||||
|
||||
block = Get_uiBlock( );
|
||||
if( block )
|
||||
uiDefButI( block, MENU, event, name, (short)x, (short)y, (short)w, (short)h,
|
||||
if( block ) {
|
||||
uiBut *ubut = uiDefButI( block, MENU, event, name, (short)x, (short)y, (short)w, (short)h,
|
||||
&but->val.asint, 0, 0, 0, 0, tip );
|
||||
|
||||
set_pycallback(ubut, callback, event);
|
||||
}
|
||||
return ( PyObject * ) but;
|
||||
}
|
||||
|
||||
@@ -1017,25 +1089,25 @@ static PyObject *Method_Toggle( PyObject * self, PyObject * args )
|
||||
int event;
|
||||
int x, y, w, h, def;
|
||||
Button *but;
|
||||
PyObject *callback=NULL;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "siiiiii|s", &name, &event,
|
||||
&x, &y, &w, &h, &def, &tip ) )
|
||||
if( !PyArg_ParseTuple( args, "siiiiii|sO", &name, &event,
|
||||
&x, &y, &w, &h, &def, &tip, &callback ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string, six ints and optionally another string as arguments" );
|
||||
|
||||
if (check_button_event(&event) == -1)
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"button event argument must be in the range [0, 16382]");
|
||||
"expected a string, six ints and optionally string and callback arguments" );
|
||||
|
||||
UI_METHOD_ERRORCHECK;
|
||||
|
||||
but = newbutton( );
|
||||
but->type = BINT_TYPE;
|
||||
but->val.asint = def;
|
||||
|
||||
block = Get_uiBlock( );
|
||||
if( block )
|
||||
uiDefButI( block, TOG, event, name, (short)x, (short)y, (short)w, (short)h,
|
||||
if( block ) {
|
||||
uiBut *ubut = uiDefButI( block, TOG, event, name, (short)x, (short)y, (short)w, (short)h,
|
||||
&but->val.asint, 0, 0, 0, 0, tip );
|
||||
|
||||
set_pycallback(ubut, callback, event);
|
||||
}
|
||||
return ( PyObject * ) but;
|
||||
}
|
||||
|
||||
@@ -1083,18 +1155,17 @@ static PyObject *Method_Slider( PyObject * self, PyObject * args )
|
||||
int x, y, w, h, realtime = 1;
|
||||
Button *but;
|
||||
PyObject *mino, *maxo, *inio;
|
||||
PyObject *callback=NULL;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "siiiiiOOO|is", &name, &event,
|
||||
if( !PyArg_ParseTuple( args, "siiiiiOOO|isO", &name, &event,
|
||||
&x, &y, &w, &h, &inio, &mino, &maxo, &realtime,
|
||||
&tip ) )
|
||||
&tip, &callback ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string, five ints, three PyObjects\n\
|
||||
and optionally another int and string as arguments" );
|
||||
|
||||
if (check_button_event(&event) == -1)
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"button event argument must be in the range [0, 16382]");
|
||||
and optionally int, string and callback arguments" );
|
||||
|
||||
UI_METHOD_ERRORCHECK;
|
||||
|
||||
but = newbutton( );
|
||||
|
||||
if( PyFloat_Check( inio ) ) {
|
||||
@@ -1134,8 +1205,9 @@ static PyObject *Method_Slider( PyObject * self, PyObject * args )
|
||||
(short)h, &but->val.asint, (float)min, (float)max, 0, 0,
|
||||
tip );
|
||||
if( realtime )
|
||||
uiButSetFunc( ubut, py_slider_update, ubut,
|
||||
NULL );
|
||||
uiButSetFunc( ubut, py_slider_update, ubut, NULL );
|
||||
else
|
||||
set_pycallback(ubut, callback, event);
|
||||
}
|
||||
}
|
||||
return ( PyObject * ) but;
|
||||
@@ -1150,8 +1222,9 @@ static PyObject *Method_Scrollbar( PyObject * self, PyObject * args )
|
||||
Button *but;
|
||||
PyObject *mino, *maxo, *inio;
|
||||
float ini, min, max;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "iiiiiOOO|is", &event, &x, &y, &w, &h,
|
||||
uiBut *ubut;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "iiiiiOOO|isO", &event, &x, &y, &w, &h,
|
||||
&inio, &mino, &maxo, &realtime, &tip ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected five ints, three PyObjects and optionally\n\
|
||||
@@ -1163,8 +1236,8 @@ another int and string as arguments" );
|
||||
"expected numbers for initial, min, and max" );
|
||||
|
||||
if (check_button_event(&event) == -1)
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"button event argument must be in the range [0, 16382]");
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"button event argument must be in the range [0, 16382]");
|
||||
|
||||
but = newbutton( );
|
||||
|
||||
@@ -1176,33 +1249,24 @@ another int and string as arguments" );
|
||||
ini = (float)PyFloat_AsDouble( inio );
|
||||
min = (float)PyFloat_AsDouble( mino );
|
||||
max = (float)PyFloat_AsDouble( maxo );
|
||||
|
||||
block = Get_uiBlock( );
|
||||
|
||||
if( but->type == BFLOAT_TYPE ) {
|
||||
but->val.asfloat = ini;
|
||||
block = Get_uiBlock( );
|
||||
if( block ) {
|
||||
uiBut *ubut;
|
||||
if( block ) {
|
||||
if( but->type == BFLOAT_TYPE ) {
|
||||
but->val.asfloat = ini;
|
||||
ubut = uiDefButF( block, SCROLL, event, "", (short)x, (short)y, (short)w, (short)h,
|
||||
&but->val.asfloat, min, max, 0, 0,
|
||||
tip );
|
||||
&but->val.asfloat, min, max, 0, 0, tip );
|
||||
if( realtime )
|
||||
uiButSetFunc( ubut, py_slider_update, ubut,
|
||||
NULL );
|
||||
}
|
||||
} else {
|
||||
but->val.asint = (int)ini;
|
||||
block = Get_uiBlock( );
|
||||
if( block ) {
|
||||
uiBut *ubut;
|
||||
uiButSetFunc( ubut, py_slider_update, ubut, NULL );
|
||||
} else {
|
||||
but->val.asint = (int)ini;
|
||||
ubut = uiDefButI( block, SCROLL, event, "", (short)x, (short)y, (short)w, (short)h,
|
||||
&but->val.asint, min, max, 0, 0,
|
||||
tip );
|
||||
&but->val.asint, min, max, 0, 0, tip );
|
||||
if( realtime )
|
||||
uiButSetFunc( ubut, py_slider_update, ubut,
|
||||
NULL );
|
||||
uiButSetFunc( ubut, py_slider_update, ubut, NULL );
|
||||
}
|
||||
}
|
||||
|
||||
return ( PyObject * ) but;
|
||||
}
|
||||
|
||||
@@ -1216,15 +1280,14 @@ static PyObject *Method_ColorPicker( PyObject * self, PyObject * args )
|
||||
float col[3];
|
||||
int event;
|
||||
short x, y, w, h;
|
||||
PyObject *callback=NULL;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "ihhhhO!|s", &event,
|
||||
&x, &y, &w, &h, &PyTuple_Type, &inio, &tip ) )
|
||||
if( !PyArg_ParseTuple( args, "ihhhhO!|sO", &event,
|
||||
&x, &y, &w, &h, &PyTuple_Type, &inio, &tip, &callback ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected five ints, one tuple and optionally a string as arguments." );
|
||||
"expected five ints, one tuple and optionally string and callback arguments" );
|
||||
|
||||
if (check_button_event(&event) == -1)
|
||||
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
||||
"button event argument must be in the range [0, 16382]");
|
||||
UI_METHOD_ERRORCHECK;
|
||||
|
||||
if ( !PyArg_ParseTuple( inio, "fff", col, col+1, col+2 ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_ValueError, USAGE_ERROR);
|
||||
@@ -1248,6 +1311,7 @@ static PyObject *Method_ColorPicker( PyObject * self, PyObject * args )
|
||||
if( block ) {
|
||||
uiBut *ubut;
|
||||
ubut = uiDefButF( block, COL, event, "", x, y, w, h, but->val.asvec, 0, 0, 0, 0, tip);
|
||||
set_pycallback(ubut, callback, event);
|
||||
}
|
||||
|
||||
return ( PyObject * ) but;
|
||||
@@ -1265,15 +1329,14 @@ static PyObject *Method_Normal( PyObject * self, PyObject * args )
|
||||
float nor[3];
|
||||
int event;
|
||||
short x, y, w, h;
|
||||
PyObject *callback=NULL;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "ihhhhO!|s", &event,
|
||||
&x, &y, &w, &h, &PyTuple_Type, &inio, &tip ) )
|
||||
if( !PyArg_ParseTuple( args, "ihhhhO!|sO", &event,
|
||||
&x, &y, &w, &h, &PyTuple_Type, &inio, &tip, &callback ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected five ints, one tuple and optionally a string as arguments." );
|
||||
"expected five ints, one tuple and optionally string and callback arguments" );
|
||||
|
||||
if (check_button_event(&event) == -1)
|
||||
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
||||
"button event argument must be in the range [0, 16382]");
|
||||
UI_METHOD_ERRORCHECK;
|
||||
|
||||
if ( !PyArg_ParseTuple( inio, "fff", nor, nor+1, nor+2 ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_ValueError, USAGE_ERROR);
|
||||
@@ -1292,6 +1355,7 @@ static PyObject *Method_Normal( PyObject * self, PyObject * args )
|
||||
if( block ) {
|
||||
uiBut *ubut;
|
||||
ubut = uiDefButF( block, BUT_NORMAL, event, "", x, y, w, h, but->val.asvec, 0.0f, 1.0f, 0, 0, tip);
|
||||
set_pycallback(ubut, callback, event);
|
||||
}
|
||||
|
||||
return ( PyObject * ) but;
|
||||
@@ -1305,19 +1369,20 @@ static PyObject *Method_Number( PyObject * self, PyObject * args )
|
||||
int x, y, w, h;
|
||||
Button *but;
|
||||
PyObject *mino, *maxo, *inio;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "siiiiiOOO|s", &name, &event,
|
||||
&x, &y, &w, &h, &inio, &mino, &maxo, &tip ) )
|
||||
PyObject *callback=NULL;
|
||||
uiBut *ubut= NULL;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "siiiiiOOO|sO", &name, &event,
|
||||
&x, &y, &w, &h, &inio, &mino, &maxo, &tip, &callback ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string, five ints, three PyObjects and\n\
|
||||
optionally another string as arguments" );
|
||||
optionally string and callback arguments" );
|
||||
|
||||
if (check_button_event(&event) == -1)
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"button event argument must be in the range [0, 16382]");
|
||||
UI_METHOD_ERRORCHECK;
|
||||
|
||||
but = newbutton( );
|
||||
|
||||
block = Get_uiBlock( );
|
||||
|
||||
if( PyFloat_Check( inio ) ) {
|
||||
float ini, min, max, range, precission=0;
|
||||
|
||||
@@ -1337,9 +1402,9 @@ static PyObject *Method_Number( PyObject * self, PyObject * args )
|
||||
but->type = BFLOAT_TYPE;
|
||||
but->val.asfloat = ini;
|
||||
|
||||
block = Get_uiBlock( );
|
||||
|
||||
if( block )
|
||||
uiDefButF( block, NUM, event, name, (short)x, (short)y, (short)w, (short)h,
|
||||
ubut= uiDefButF( block, NUM, event, name, (short)x, (short)y, (short)w, (short)h,
|
||||
&but->val.asfloat, min, max, 10*range, precission, tip );
|
||||
} else {
|
||||
int ini, min, max;
|
||||
@@ -1351,12 +1416,13 @@ static PyObject *Method_Number( PyObject * self, PyObject * args )
|
||||
but->type = BINT_TYPE;
|
||||
but->val.asint = ini;
|
||||
|
||||
block = Get_uiBlock( );
|
||||
if( block )
|
||||
uiDefButI( block, NUM, event, name, (short)x, (short)y, (short)w, (short)h,
|
||||
ubut= uiDefButI( block, NUM, event, name, (short)x, (short)y, (short)w, (short)h,
|
||||
&but->val.asint, (float)min, (float)max, 0, 0, tip );
|
||||
}
|
||||
|
||||
|
||||
if (ubut) set_pycallback(ubut, callback, event);
|
||||
|
||||
return ( PyObject * ) but;
|
||||
}
|
||||
|
||||
@@ -1368,16 +1434,15 @@ static PyObject *Method_String( PyObject * self, PyObject * args )
|
||||
int event;
|
||||
int x, y, w, h, len, real_len = 0;
|
||||
Button *but;
|
||||
PyObject *callback=NULL;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "siiiiisi|s", &info_arg, &event,
|
||||
&x, &y, &w, &h, &newstr, &len, &tip ) )
|
||||
if( !PyArg_ParseTuple( args, "siiiiisi|sO", &info_arg, &event,
|
||||
&x, &y, &w, &h, &newstr, &len, &tip, &callback ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string, five ints, a string, an int and\n\
|
||||
optionally another string as arguments" );
|
||||
optionally string and callback arguments" );
|
||||
|
||||
if (check_button_event(&event) == -1)
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"button event argument must be in the range [0, 16382]");
|
||||
UI_METHOD_ERRORCHECK;
|
||||
|
||||
if (len > (UI_MAX_DRAW_STR - 1))
|
||||
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
||||
@@ -1398,10 +1463,11 @@ static PyObject *Method_String( PyObject * self, PyObject * args )
|
||||
else info_str = info_arg;
|
||||
|
||||
block = Get_uiBlock( );
|
||||
if( block )
|
||||
uiDefBut( block, TEX, event, info_str, (short)x, (short)y, (short)w, (short)h,
|
||||
if( block ) {
|
||||
uiBut *ubut = uiDefBut( block, TEX, event, info_str, (short)x, (short)y, (short)w, (short)h,
|
||||
but->val.asstr, 0, (float)len, 0, 0, tip );
|
||||
|
||||
set_pycallback(ubut, callback, event);
|
||||
}
|
||||
return ( PyObject * ) but;
|
||||
}
|
||||
|
||||
|
||||
@@ -221,203 +221,223 @@ Draw.Draw() functions that can be used inside the windowing loop.
|
||||
"""
|
||||
|
||||
def Exit():
|
||||
"""
|
||||
Exit the windowing interface.
|
||||
"""
|
||||
"""
|
||||
Exit the windowing interface.
|
||||
"""
|
||||
|
||||
def BeginAlign():
|
||||
"""
|
||||
Buttons after this function will draw aligned (button layout only).
|
||||
"""
|
||||
"""
|
||||
Buttons after this function will draw aligned (button layout only).
|
||||
"""
|
||||
|
||||
def EndAlign():
|
||||
"""
|
||||
Use after BeginAlign() to stop aligning the buttons (button layout only).
|
||||
"""
|
||||
"""
|
||||
Use after BeginAlign() to stop aligning the buttons (button layout only).
|
||||
"""
|
||||
|
||||
def UIBlock(draw):
|
||||
"""
|
||||
This function creates a popup area where buttons, lebels, sliders etc can be dwarn.
|
||||
|
||||
@type draw: function
|
||||
@param draw: A function to draw to the popup area, taking no arguments: draw().
|
||||
|
||||
@note: The size of the popup will expand to fit the bounds of the buttons created in the draw function.
|
||||
@note: Be sure to use the mouse coordinates to position the buttons under the mouse,
|
||||
so the popup dosnt exit as soon as it opens.
|
||||
The coordinates for buttons start 0,0 at the bottom left hand side of the screen.
|
||||
@note: Within this popup, Redraw events and the registered button callback will not work.
|
||||
For buttons to run events, use per button callbacks.
|
||||
@note: OpenGL drawing functions wont work within this popup, for text use L{Label} rather then L{Text}
|
||||
"""
|
||||
|
||||
def Register(draw = None, event = None, button = None):
|
||||
"""
|
||||
Register callbacks for windowing.
|
||||
@type draw: function
|
||||
@type event: function
|
||||
@type button: function
|
||||
@param draw: A function to draw the screen, taking no arguments: f().
|
||||
@param event: A function to handle keyboard and mouse input events, taking
|
||||
two arguments: f(evt, val), where:
|
||||
- 'evt' (int) is the event number;
|
||||
- 'val' (int) is the value modifier. If val = 0, the event refers to a
|
||||
key or mouse button being released. Otherwise it's a key/button press.
|
||||
@param button: A function to handle Draw Button events, taking one argument:
|
||||
f(evt), where:
|
||||
- 'evt' is the button number (see the I{event} parameter in L{Button}).
|
||||
@note: note that in the example at the beginning of this page Draw.Register
|
||||
is called only once. It's not necessary to re-register the callbacks,
|
||||
they will stay until Draw.Exit is called. It's enough to redraw the
|
||||
screen, when a relevant event is caught.
|
||||
@note: only during the B{event} callback: the L{Blender}.ascii variable holds
|
||||
the ASCII integer value (if it exists and is valid) of the current event.
|
||||
"""
|
||||
"""
|
||||
Register callbacks for windowing.
|
||||
@type draw: function
|
||||
@type event: function
|
||||
@type button: function
|
||||
@param draw: A function to draw the screen, taking no arguments: draw().
|
||||
@param event: A function to handle keyboard and mouse input events, taking
|
||||
two arguments: f(evt, val), where:
|
||||
- 'evt' (int) is the event number;
|
||||
- 'val' (int) is the value modifier. If val = 0, the event refers to a
|
||||
key or mouse button being released. Otherwise it's a key/button press.
|
||||
@param button: A function to handle Draw Button events, taking one argument:
|
||||
f(evt), where:
|
||||
- 'evt' is the button number (see the I{event} parameter in L{Button}).
|
||||
@note: note that in the example at the beginning of this page Draw.Register
|
||||
is called only once. It's not necessary to re-register the callbacks,
|
||||
they will stay until Draw.Exit is called. It's enough to redraw the
|
||||
screen, when a relevant event is caught.
|
||||
@note: only during the B{event} callback: the L{Blender}.ascii variable holds
|
||||
the ASCII integer value (if it exists and is valid) of the current event.
|
||||
"""
|
||||
|
||||
def Redraw(after = 0):
|
||||
"""
|
||||
Queue a redraw event. Redraw events are buffered so that, regardless of how
|
||||
many events are queued, the window only receives one redraw event.
|
||||
@type after: int
|
||||
@param after: If non-zero, the redraw is processed before other input events.
|
||||
"""
|
||||
"""
|
||||
Queue a redraw event. Redraw events are buffered so that, regardless of how
|
||||
many events are queued, the window only receives one redraw event.
|
||||
@type after: int
|
||||
@param after: If non-zero, the redraw is processed before other input events.
|
||||
"""
|
||||
|
||||
def Draw():
|
||||
"""
|
||||
Force an immediate redraw. Forced redraws are not buffered. In other words,
|
||||
the window is redrawn once every time this function is called.
|
||||
"""
|
||||
"""
|
||||
Force an immediate redraw. Forced redraws are not buffered. In other words,
|
||||
the window is redrawn once every time this function is called.
|
||||
"""
|
||||
|
||||
def Create(value):
|
||||
"""
|
||||
Create a default Button object.
|
||||
@type value: int, float, string or 3 floats
|
||||
@param value: The value to store in the button.
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
@note: String values must have less then 400 characters.
|
||||
"""
|
||||
"""
|
||||
Create a default Button object.
|
||||
@type value: int, float, string or 3 floats
|
||||
@param value: The value to store in the button.
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
@note: String values must have less then 400 characters.
|
||||
"""
|
||||
|
||||
def PushButton(name, event, x, y, width, height, tooltip = None):
|
||||
"""
|
||||
Create a new (push) Button object.
|
||||
@type name: string
|
||||
@param name: The string to display on the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@note: This function used to be called only "Button". We added an
|
||||
alternative alias to avoid a name clash with the L{Button} class/type that
|
||||
caused trouble in this documentation's generation. The old name shouldn't
|
||||
be deprecated, use Button or PushButton (better) at your choice.
|
||||
"""
|
||||
def PushButton(name, event, x, y, width, height, tooltip = None, callback = None):
|
||||
"""
|
||||
Create a new (push) Button object.
|
||||
@type name: string
|
||||
@param name: The string to display on the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@type callback: function
|
||||
@param callback: an optional argument so this button can have its own
|
||||
callback function. the function will run whenever this button is pressed.
|
||||
This function must accept one argument (the event) as an argument.
|
||||
@note: This function used to be called only "Button". We added an
|
||||
alternative alias to avoid a name clash with the L{Button} class/type that
|
||||
caused trouble in this documentation's generation. The old name shouldn't
|
||||
be deprecated, use Button or PushButton (better) at your choice.
|
||||
"""
|
||||
|
||||
def PupMenu(name, maxrow = None):
|
||||
"""
|
||||
Create a pop-up menu.
|
||||
"""
|
||||
Create a pop-up menu.
|
||||
|
||||
The menu options are specified through the 'name' parameter, like with
|
||||
L{Menu}: options are followed by a format code and separated by the '|'
|
||||
character. Valid format codes are:
|
||||
- %t - The option should be used as the title of the pop-up;
|
||||
- %l - insert a separating line (only works if 'maxrow' isn't given);
|
||||
- %xB{N} - Chosen this option, PupMenu should return the integer B{N}.
|
||||
The menu options are specified through the 'name' parameter, like with
|
||||
L{Menu}: options are followed by a format code and separated by the '|'
|
||||
character. Valid format codes are:
|
||||
- %t - The option should be used as the title of the pop-up;
|
||||
- %l - insert a separating line (only works if 'maxrow' isn't given);
|
||||
- %xB{N} - Chosen this option, PupMenu should return the integer B{N}.
|
||||
|
||||
Example::
|
||||
name = "OK?%t|QUIT BLENDER" # if no %xN int is set, indices start from 1
|
||||
result = Draw.PupMenu(name)
|
||||
if result:
|
||||
Draw.PupMenu("Really?%t|Yes|No")
|
||||
Example::
|
||||
name = "OK?%t|QUIT BLENDER" # if no %xN int is set, indices start from 1
|
||||
result = Draw.PupMenu(name)
|
||||
if result:
|
||||
Draw.PupMenu("Really?%t|Yes|No")
|
||||
|
||||
@type name: string
|
||||
@param name: The format string to define the contents of the button.
|
||||
@type maxrow: int
|
||||
@param maxrow: The maximum number of rows for each column in the pop-up.
|
||||
@rtype: int
|
||||
@return: the chosen entry number or -1 if none was chosen.
|
||||
"""
|
||||
@type name: string
|
||||
@param name: The format string to define the contents of the button.
|
||||
@type maxrow: int
|
||||
@param maxrow: The maximum number of rows for each column in the pop-up.
|
||||
@rtype: int
|
||||
@return: the chosen entry number or -1 if none was chosen.
|
||||
"""
|
||||
|
||||
def PupIntInput(text, default, min, max):
|
||||
"""
|
||||
Create an integer number input pop-up.
|
||||
"""
|
||||
Create an integer number input pop-up.
|
||||
|
||||
This allows python to use Blender's integer number pop-up input.
|
||||
This allows python to use Blender's integer number pop-up input.
|
||||
|
||||
Example::
|
||||
default = 50
|
||||
min = 0
|
||||
max = 100
|
||||
Example::
|
||||
default = 50
|
||||
min = 0
|
||||
max = 100
|
||||
|
||||
msg = "Set this value between 0 and 100"
|
||||
result = Draw.PupIntInput(msg, default, min, max)
|
||||
if result != None:
|
||||
print result
|
||||
else:
|
||||
print 'no user input'
|
||||
|
||||
@type text: string
|
||||
@param text: The text that is displayed in the pop-up.
|
||||
@type default: int
|
||||
@param default: The value that the pop-up is set to initially.
|
||||
@type min: int
|
||||
@param min: The lowest value the pop-up will allow.
|
||||
@type max: int
|
||||
@param max: The highest value the pop-up will allow.
|
||||
@rtype: int
|
||||
@return: the number chosen or None if none was chosen.
|
||||
"""
|
||||
msg = "Set this value between 0 and 100"
|
||||
result = Draw.PupIntInput(msg, default, min, max)
|
||||
if result != None:
|
||||
print result
|
||||
else:
|
||||
print 'no user input'
|
||||
|
||||
@type text: string
|
||||
@param text: The text that is displayed in the pop-up.
|
||||
@type default: int
|
||||
@param default: The value that the pop-up is set to initially.
|
||||
@type min: int
|
||||
@param min: The lowest value the pop-up will allow.
|
||||
@type max: int
|
||||
@param max: The highest value the pop-up will allow.
|
||||
@rtype: int
|
||||
@return: the number chosen or None if none was chosen.
|
||||
"""
|
||||
|
||||
def PupFloatInput(text, default, min, max, clickStep, floatLen):
|
||||
"""
|
||||
Create a floating point number input pop-up.
|
||||
|
||||
This allows python to use Blender's floating point pop-up input.
|
||||
"""
|
||||
Create a floating point number input pop-up.
|
||||
|
||||
Example::
|
||||
default = 50
|
||||
min = 0.0
|
||||
max = 10.0
|
||||
clickStep = 100
|
||||
floatLen = 3
|
||||
This allows python to use Blender's floating point pop-up input.
|
||||
|
||||
msg = "Set this value between 0 and 100"
|
||||
result = Draw.PupFloatInput(msg, default, min, max, clickStep, floatLen)
|
||||
if result != None:
|
||||
print result
|
||||
else:
|
||||
print 'no user input'
|
||||
|
||||
@type text: string
|
||||
@param text: The text that is displayed in the pop-up.
|
||||
@type default: float
|
||||
@param default: The value that the pop-up is set to initially.
|
||||
@type min: float
|
||||
@param min: The lowest value the pop-up will allow.
|
||||
@type max: float
|
||||
@param max: The highest value the pop-up will allow.
|
||||
@type clickStep: int
|
||||
@param clickStep: How much is incremented per user click, 100 will increment 1.0, 10 will increment 0.1 etc.
|
||||
@type floatLen: int
|
||||
@param floatLen: The number of decimal places to display, between 2 and 4.
|
||||
@rtype: float
|
||||
@return: the number chosen or None if none was chosen.
|
||||
"""
|
||||
Example::
|
||||
default = 50
|
||||
min = 0.0
|
||||
max = 10.0
|
||||
clickStep = 100
|
||||
floatLen = 3
|
||||
|
||||
msg = "Set this value between 0 and 100"
|
||||
result = Draw.PupFloatInput(msg, default, min, max, clickStep, floatLen)
|
||||
if result != None:
|
||||
print result
|
||||
else:
|
||||
print 'no user input'
|
||||
|
||||
@type text: string
|
||||
@param text: The text that is displayed in the pop-up.
|
||||
@type default: float
|
||||
@param default: The value that the pop-up is set to initially.
|
||||
@type min: float
|
||||
@param min: The lowest value the pop-up will allow.
|
||||
@type max: float
|
||||
@param max: The highest value the pop-up will allow.
|
||||
@type clickStep: int
|
||||
@param clickStep: How much is incremented per user click, 100 will increment 1.0, 10 will increment 0.1 etc.
|
||||
@type floatLen: int
|
||||
@param floatLen: The number of decimal places to display, between 2 and 4.
|
||||
@rtype: float
|
||||
@return: the number chosen or None if none was chosen.
|
||||
"""
|
||||
|
||||
def PupStrInput(text, default, max = 20):
|
||||
"""
|
||||
Create a string input pop-up.
|
||||
|
||||
This allows python to use Blender's string pop-up input.
|
||||
"""
|
||||
Create a string input pop-up.
|
||||
|
||||
Example::
|
||||
Blender.Draw.PupStrInput("Name:", "untitled", 25)
|
||||
|
||||
@type text: string
|
||||
@param text: The text that is displayed in the pop-up.
|
||||
@type default: string
|
||||
@param default: The value that the pop-up is set to initially. If it's longer
|
||||
then 'max', it's truncated.
|
||||
@type max: int
|
||||
@param max: The most characters the pop-up input will allow. If not given
|
||||
it defaults to 20 chars. It should be in the range [1, 100].
|
||||
@rtype: string
|
||||
@return: The text entered by the user or None if none was chosen.
|
||||
"""
|
||||
This allows python to use Blender's string pop-up input.
|
||||
|
||||
Example::
|
||||
Blender.Draw.PupStrInput("Name:", "untitled", 25)
|
||||
|
||||
@type text: string
|
||||
@param text: The text that is displayed in the pop-up.
|
||||
@type default: string
|
||||
@param default: The value that the pop-up is set to initially. If it's longer
|
||||
then 'max', it's truncated.
|
||||
@type max: int
|
||||
@param max: The most characters the pop-up input will allow. If not given
|
||||
it defaults to 20 chars. It should be in the range [1, 100].
|
||||
@rtype: string
|
||||
@return: The text entered by the user or None if none was chosen.
|
||||
"""
|
||||
|
||||
def PupBlock(title, sequence):
|
||||
"""
|
||||
@@ -463,103 +483,117 @@ def PupBlock(title, sequence):
|
||||
@return: 1 if the pop-up is confirmed, 0 otherwise
|
||||
"""
|
||||
|
||||
def Menu(name, event, x, y, width, height, default, tooltip = None):
|
||||
"""
|
||||
Create a new Menu Button object.
|
||||
|
||||
The menu options are specified through the 'name' of the button. Options are
|
||||
I{followed} by a format code and separated by the '|' (pipe) character. Valid
|
||||
format codes are:
|
||||
- %t - The option should be used as the title;
|
||||
- %l - Insert a separating line;
|
||||
- %xB{N} - The option should set the integer B{N} in the button value.
|
||||
def Menu(name, event, x, y, width, height, default, tooltip = None, callback = None):
|
||||
"""
|
||||
Create a new Menu Button object.
|
||||
|
||||
Example::
|
||||
name = "The Title %t|First Entry %x1|Second Entry %x2|Third Entry %x3"
|
||||
menu = Draw.Menu(name, 2, 60, 120, 200, 40, 3, "Just a test menu.")
|
||||
# note that, since default = 3, the "Third Entry"
|
||||
# will appear as the default choice in the Menu.
|
||||
The menu options are specified through the 'name' of the button. Options are
|
||||
I{followed} by a format code and separated by the '|' (pipe) character. Valid
|
||||
format codes are:
|
||||
- %t - The option should be used as the title;
|
||||
- %l - Insert a separating line;
|
||||
- %xB{N} - The option should set the integer B{N} in the button value.
|
||||
|
||||
@type name: string
|
||||
@param name: The format string to define the contents of the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type default: int
|
||||
@param default: The number of the option to be selected by default.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
"""
|
||||
Example::
|
||||
name = "The Title %t|First Entry %x1|Second Entry %x2|Third Entry %x3"
|
||||
menu = Draw.Menu(name, 2, 60, 120, 200, 40, 3, "Just a test menu.")
|
||||
# note that, since default = 3, the "Third Entry"
|
||||
# will appear as the default choice in the Menu.
|
||||
|
||||
def Toggle(name, event, x, y, width, height, default, tooltip = None):
|
||||
"""
|
||||
Create a new Toggle Button object.
|
||||
@type name: string
|
||||
@param name: The string to display on the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type default: int
|
||||
@param default: The value specifying the default state:
|
||||
(0 for "up", 1 for "down").
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
"""
|
||||
@type name: string
|
||||
@param name: The format string to define the contents of the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type default: int
|
||||
@param default: The number of the option to be selected by default.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@type callback: function
|
||||
@param callback: an optional argument so this button can have its own
|
||||
callback function. the function will run whenever this button is pressed.
|
||||
This function must accept one argument (the event) as an argument.
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
"""
|
||||
|
||||
def Toggle(name, event, x, y, width, height, default, tooltip = None, callback = None):
|
||||
"""
|
||||
Create a new Toggle Button object.
|
||||
@type name: string
|
||||
@param name: The string to display on the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type default: int
|
||||
@param default: The value specifying the default state:
|
||||
(0 for "up", 1 for "down").
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@type callback: function
|
||||
@param callback: an optional argument so this button can have its own
|
||||
callback function. the function will run whenever this button is pressed.
|
||||
This function must accept one argument (the event) as an argument.
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
"""
|
||||
|
||||
def Slider(name, event, x, y, width, height, initial, min, max, realtime = 1,
|
||||
tooltip = None):
|
||||
"""
|
||||
Create a new Slider Button object.
|
||||
@type name: string
|
||||
@param name: The string to display on the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type initial: int or float
|
||||
@type min: int or float
|
||||
@type max: int or float
|
||||
@param initial: The initial value.
|
||||
@param min: The minimum value.
|
||||
@param max: The maximum value.
|
||||
@type realtime: int
|
||||
@param realtime: If non-zero (the default), the slider will emit events as
|
||||
it is edited.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
"""
|
||||
tooltip = None, callback = None):
|
||||
"""
|
||||
Create a new Slider Button object.
|
||||
@type name: string
|
||||
@param name: The string to display on the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type initial: int or float
|
||||
@type min: int or float
|
||||
@type max: int or float
|
||||
@param initial: The initial value.
|
||||
@param min: The minimum value.
|
||||
@param max: The maximum value.
|
||||
@type realtime: int
|
||||
@param realtime: If non-zero (the default), the slider will emit events as
|
||||
it is edited.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
|
||||
@type callback: function
|
||||
@param callback: an optional argument so this button can have its own
|
||||
callback function. the function will run whenever this button is pressed.
|
||||
This function must accept one argument (the event) as an argument.
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
@note: slider callbacks will not work if the realtime setting is enabled.
|
||||
"""
|
||||
|
||||
#def Scrollbar(event, x, y, width, height, initial, min, max, realtime = 1,
|
||||
# tooltip = None):
|
||||
@@ -592,240 +626,254 @@ def Slider(name, event, x, y, width, height, initial, min, max, realtime = 1,
|
||||
# @return: The Button created.
|
||||
# """
|
||||
|
||||
def ColorPicker(event, x, y, width, height, initial, tooltip = None):
|
||||
"""
|
||||
Create a new Color Picker Button object.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type initial: 3-float tuple
|
||||
@param initial: The initial color value. All values must be between 0 and 1
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
@note: The color picker will not work if the Register's event function is None.
|
||||
@note: Using the same button variable with more then 1 button at a time will corrupt memory.
|
||||
"""
|
||||
def ColorPicker(event, x, y, width, height, initial, tooltip = None, callback = None):
|
||||
"""
|
||||
Create a new Color Picker Button object.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type initial: 3-float tuple
|
||||
@param initial: The initial color value. All values must be between 0 and 1
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@type callback: function
|
||||
@param callback: an optional argument so this button can have its own
|
||||
callback function. the function will run whenever this button is pressed.
|
||||
This function must accept one argument (the event) as an argument.
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
@note: The color picker will not work if the Register's event function is None.
|
||||
@note: Using the same button variable with more then 1 button at a time will corrupt memory.
|
||||
"""
|
||||
|
||||
def Normal(event, x, y, width, height, initial, tooltip = None):
|
||||
"""
|
||||
Create a new Normal button, this allows you to set a 3d vector by rotating a sphere.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width - non square normal buttons .
|
||||
@param height: The button height.
|
||||
@type initial: 3-float tuple
|
||||
@param initial: The initial vector value.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
@note: The normal button will not work if the Register's event function is None.
|
||||
@note: Using the same button variable with more then 1 button at a time will corrupt memory.
|
||||
"""
|
||||
def Normal(event, x, y, width, height, initial, tooltip = None, callback = None):
|
||||
"""
|
||||
Create a new Normal button, this allows you to set a 3d vector by rotating a sphere.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width - non square normal buttons .
|
||||
@param height: The button height.
|
||||
@type initial: 3-float tuple
|
||||
@param initial: The initial vector value.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@type callback: function
|
||||
@param callback: an optional argument so this button can have its own
|
||||
callback function. the function will run whenever this button is pressed.
|
||||
This function must accept one argument (the event) as an argument.
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
@note: The normal button will not work if the Register's event function is None.
|
||||
@note: Using the same button variable with more then 1 button at a time will corrupt memory.
|
||||
"""
|
||||
|
||||
def Number(name, event, x, y, width, height, initial, min, max, tooltip = None):
|
||||
"""
|
||||
Create a new Number Button object.
|
||||
@type name: string
|
||||
@param name: The string to display on the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type initial: int or float
|
||||
@type min: int or float
|
||||
@type max: int or float
|
||||
@param initial: The initial value.
|
||||
@param min: The minimum value.
|
||||
@param max: The maximum value.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
def Number(name, event, x, y, width, height, initial, min, max, tooltip = None, callback = None):
|
||||
"""
|
||||
Create a new Number Button object.
|
||||
@type name: string
|
||||
@param name: The string to display on the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type initial: int or float
|
||||
@type min: int or float
|
||||
@type max: int or float
|
||||
@param initial: The initial value.
|
||||
@param min: The minimum value.
|
||||
@param max: The maximum value.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@type callback: function
|
||||
@param callback: an optional argument so this button can have its own
|
||||
callback function. the function will run whenever this button is pressed.
|
||||
This function must accept one argument (the event) as an argument.
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
|
||||
I{B{Example:}}
|
||||
I{B{Example:}}
|
||||
|
||||
This example draws a single floating point value::
|
||||
from Blender import Draw
|
||||
b= Draw.Create(0.0) # Data for floating point button
|
||||
def bevent(evt):
|
||||
print 'My Button event:', evt
|
||||
def gui():
|
||||
global b
|
||||
b= Draw.Number('value: ', 1000, 0,0, 200, 20, b.val, 0,10, 'some text tip')
|
||||
This example draws a single floating point value::
|
||||
from Blender import Draw
|
||||
b= Draw.Create(0.0) # Data for floating point button
|
||||
def bevent(evt):
|
||||
print 'My Button event:', evt
|
||||
def gui():
|
||||
global b
|
||||
b= Draw.Number('value: ', 1000, 0,0, 200, 20, b.val, 0,10, 'some text tip')
|
||||
|
||||
Draw.Register(gui, None, bevent) # we are not going to worry about keyboard and mouse events
|
||||
"""
|
||||
Draw.Register(gui, None, bevent) # we are not going to worry about keyboard and mouse events
|
||||
"""
|
||||
|
||||
|
||||
def String(name, event, x, y, width, height, initial, length, tooltip = None):
|
||||
"""
|
||||
Create a new String Button object.
|
||||
@type name: string
|
||||
@param name: The string to display on the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type initial: string
|
||||
@param initial: The string to display initially.
|
||||
@type length: int
|
||||
@param length: The maximum input length.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
"""
|
||||
def String(name, event, x, y, width, height, initial, length, tooltip = None, callback = None):
|
||||
"""
|
||||
Create a new String Button object.
|
||||
@type name: string
|
||||
@param name: The string to display on the button.
|
||||
@type event: int
|
||||
@param event: The event number to pass to the button event function when
|
||||
activated.
|
||||
@type x: int
|
||||
@type y: int
|
||||
@param x: The lower left x (horizontal) coordinate of the button.
|
||||
@param y: The lower left y (vertical) coordinate of the button.
|
||||
@type width: int
|
||||
@type height: int
|
||||
@param width: The button width.
|
||||
@param height: The button height.
|
||||
@type initial: string
|
||||
@param initial: The string to display initially.
|
||||
@type length: int
|
||||
@param length: The maximum input length.
|
||||
@type tooltip: string
|
||||
@param tooltip: The button's tooltip (the string that appears when the mouse
|
||||
is kept over the button).
|
||||
@type callback: function
|
||||
@param callback: an optional argument so this button can have its own
|
||||
callback function. the function will run whenever this button is pressed.
|
||||
This function must accept one argument (the event) as an argument.
|
||||
@rtype: Blender Button
|
||||
@return: The Button created.
|
||||
"""
|
||||
|
||||
def GetStringWidth(string, fontsize = 'normal'):
|
||||
"""
|
||||
Get the width in pixels of a string.
|
||||
@type string: string
|
||||
@param string: A string.
|
||||
@type fontsize: string
|
||||
@param fontsize: The size of the font: 'large', 'normal', 'small' or 'tiny'.
|
||||
@rtype: int
|
||||
@return: The width of I{string} with the chosen I{fontsize}.
|
||||
"""
|
||||
"""
|
||||
Get the width in pixels of a string.
|
||||
@type string: string
|
||||
@param string: A string.
|
||||
@type fontsize: string
|
||||
@param fontsize: The size of the font: 'large', 'normal', 'small' or 'tiny'.
|
||||
@rtype: int
|
||||
@return: The width of I{string} with the chosen I{fontsize}.
|
||||
"""
|
||||
|
||||
def Text(string, fontsize = 'normal'):
|
||||
"""
|
||||
Draw a string on the screen.
|
||||
"""
|
||||
Draw a string on the screen.
|
||||
|
||||
Text location is set using the OpenGL raster location functions L{BGL.glRasterPos} before the text is drawn.
|
||||
This sets the text location from the lower left corner of the current window.
|
||||
Text location is set using the OpenGL raster location functions L{BGL.glRasterPos} before the text is drawn.
|
||||
This sets the text location from the lower left corner of the current window.
|
||||
|
||||
Text color is set using the OpenGL color functions L{BGL.glColor} before the text is drawn.
|
||||
|
||||
@type string: string
|
||||
@param string: The text string to draw.
|
||||
@type fontsize: string
|
||||
@param fontsize: The size of the font: 'large', 'normal', 'small' or 'tiny'.
|
||||
@rtype: int
|
||||
@return: The width of I{string} drawn with the chosen I{fontsize}.
|
||||
@note: For drawing text in the 3d view see the workaround in L{BGL.glRasterPos}
|
||||
"""
|
||||
Text color is set using the OpenGL color functions L{BGL.glColor} before the text is drawn.
|
||||
|
||||
@type string: string
|
||||
@param string: The text string to draw.
|
||||
@type fontsize: string
|
||||
@param fontsize: The size of the font: 'large', 'normal', 'small' or 'tiny'.
|
||||
@rtype: int
|
||||
@return: The width of I{string} drawn with the chosen I{fontsize}.
|
||||
@note: For drawing text in the 3d view see the workaround in L{BGL.glRasterPos}
|
||||
"""
|
||||
|
||||
def Label(string, x, y, w, h):
|
||||
"""
|
||||
Draw a text lable on the screen.
|
||||
|
||||
@type string: string
|
||||
@param string: The text string to draw.
|
||||
@rtype: None
|
||||
@return: None
|
||||
"""
|
||||
"""
|
||||
Draw a text lable on the screen.
|
||||
|
||||
@type string: string
|
||||
@param string: The text string to draw.
|
||||
@rtype: None
|
||||
@return: None
|
||||
"""
|
||||
|
||||
def Image(image, x, y, zoomx=1.0, zoomy=1.0, clipx=0, clipy=0, clipw=-1, cliph=-1):
|
||||
"""
|
||||
Draw an image on the screen.
|
||||
"""
|
||||
Draw an image on the screen.
|
||||
|
||||
The image is drawn at the location specified by the coordinates (x,y). A
|
||||
pair of optional zoom factors (in horizontal and vertical directions) can
|
||||
be applied to the image as it is drawn, and an additional clipping rectangle
|
||||
can be applied to extract a particular sub-region of the image to draw.
|
||||
The image is drawn at the location specified by the coordinates (x,y). A
|
||||
pair of optional zoom factors (in horizontal and vertical directions) can
|
||||
be applied to the image as it is drawn, and an additional clipping rectangle
|
||||
can be applied to extract a particular sub-region of the image to draw.
|
||||
|
||||
Note that the clipping rectangle is given in image space coordinates. In
|
||||
image space, the origin is located at the bottom left, with x coordinates
|
||||
increasing to the right and y coordinates increasing upwards. No matter
|
||||
where the clipping rectangle is placed in image space, the lower-left pixel
|
||||
drawn on the screen is always placed at the coordinates (x,y). The
|
||||
clipping rectangle is itself clipped to the dimensions of the image. If
|
||||
either the width or the height of the clipping rectangle are negative then
|
||||
the corresponding dimension (width or height) is set to include as much of
|
||||
the image as possible.
|
||||
|
||||
For drawing images with alpha blending with the background you will need to enable blending as shown in the example.
|
||||
|
||||
|
||||
Note that the clipping rectangle is given in image space coordinates. In
|
||||
image space, the origin is located at the bottom left, with x coordinates
|
||||
increasing to the right and y coordinates increasing upwards. No matter
|
||||
where the clipping rectangle is placed in image space, the lower-left pixel
|
||||
drawn on the screen is always placed at the coordinates (x,y). The
|
||||
clipping rectangle is itself clipped to the dimensions of the image. If
|
||||
either the width or the height of the clipping rectangle are negative then
|
||||
the corresponding dimension (width or height) is set to include as much of
|
||||
the image as possible.
|
||||
|
||||
Example::
|
||||
import Blender
|
||||
from Blender import BGL, Image, Draw
|
||||
For drawing images with alpha blending with the background you will need to enable blending as shown in the example.
|
||||
|
||||
Example::
|
||||
import Blender
|
||||
from Blender import BGL, Image, Draw
|
||||
|
||||
myimage = Image.Load('myimage.png')
|
||||
|
||||
def gui():
|
||||
BGL.glEnable( BGL.GL_BLEND ) # Only needed for alpha blending images with background.
|
||||
BGL.glBlendFunc(BGL.GL_SRC_ALPHA, BGL.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
Draw.Image(myimage, 50, 50)
|
||||
|
||||
BGL.glDisable( BGL.GL_BLEND )
|
||||
def event(evt, val):
|
||||
if evt == Draw.ESCKEY:
|
||||
Draw.Exit()
|
||||
|
||||
Draw.Register(gui, event, None)
|
||||
|
||||
myimage = Image.Load('myimage.png')
|
||||
|
||||
def gui():
|
||||
BGL.glEnable( BGL.GL_BLEND ) # Only needed for alpha blending images with background.
|
||||
BGL.glBlendFunc(BGL.GL_SRC_ALPHA, BGL.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
Draw.Image(myimage, 50, 50)
|
||||
|
||||
BGL.glDisable( BGL.GL_BLEND )
|
||||
def event(evt, val):
|
||||
if evt == Draw.ESCKEY:
|
||||
Draw.Exit()
|
||||
|
||||
Draw.Register(gui, event, None)
|
||||
|
||||
@type image: Blender.Image
|
||||
@param image: The image to draw.
|
||||
@type x: int
|
||||
@param x: The lower left x (horizontal) position of the origin of the image.
|
||||
@type y: int
|
||||
@param y: The lower left y (vertical) position of the origin of the image.
|
||||
@type zoomx: float
|
||||
@param zoomx: The x (horizontal) zoom factor to use when drawing the image.
|
||||
@type zoomy: float
|
||||
@param zoomy: The y (vertical) zoom factor to use when drawing the image.
|
||||
@type clipx: int
|
||||
@param clipx: The lower left x (horizontal) origin of the clipping rectangle
|
||||
within the image. A value of 0 indicates the left of the
|
||||
image.
|
||||
@type clipy: int
|
||||
@param clipy: The lower left y (vertical) origin of the clipping rectangle
|
||||
within the image. A value of 0 indicates the bottom of the
|
||||
image.
|
||||
@type clipw: int
|
||||
@param clipw: The width of the clipping rectangle within the image. If this
|
||||
value is negative then the clipping rectangle includes as much
|
||||
of the image as possible in the x (horizontal) direction.
|
||||
@type cliph: int
|
||||
@param cliph: The height of the clipping rectangle within the image. If this
|
||||
value is negative then the clipping rectangle includes as much
|
||||
of the image as possible in the y (vertical) direction.
|
||||
"""
|
||||
@type image: Blender.Image
|
||||
@param image: The image to draw.
|
||||
@type x: int
|
||||
@param x: The lower left x (horizontal) position of the origin of the image.
|
||||
@type y: int
|
||||
@param y: The lower left y (vertical) position of the origin of the image.
|
||||
@type zoomx: float
|
||||
@param zoomx: The x (horizontal) zoom factor to use when drawing the image.
|
||||
@type zoomy: float
|
||||
@param zoomy: The y (vertical) zoom factor to use when drawing the image.
|
||||
@type clipx: int
|
||||
@param clipx: The lower left x (horizontal) origin of the clipping rectangle
|
||||
within the image. A value of 0 indicates the left of the
|
||||
image.
|
||||
@type clipy: int
|
||||
@param clipy: The lower left y (vertical) origin of the clipping rectangle
|
||||
within the image. A value of 0 indicates the bottom of the
|
||||
image.
|
||||
@type clipw: int
|
||||
@param clipw: The width of the clipping rectangle within the image. If this
|
||||
value is negative then the clipping rectangle includes as much
|
||||
of the image as possible in the x (horizontal) direction.
|
||||
@type cliph: int
|
||||
@param cliph: The height of the clipping rectangle within the image. If this
|
||||
value is negative then the clipping rectangle includes as much
|
||||
of the image as possible in the y (vertical) direction.
|
||||
"""
|
||||
|
||||
class Button:
|
||||
"""
|
||||
The Button object
|
||||
=================
|
||||
This object represents a button in Blender's GUI.
|
||||
@type val: int or float, string or 3-float tuple (depends on button type).
|
||||
@ivar val: The button's value.
|
||||
"""
|
||||
"""
|
||||
The Button object
|
||||
=================
|
||||
This object represents a button in Blender's GUI.
|
||||
@type val: int or float, string or 3-float tuple (depends on button type).
|
||||
@ivar val: The button's value.
|
||||
"""
|
||||
|
||||
@@ -19,107 +19,104 @@ a script isn't kept after it leaves: the data is not persistent. The Registry
|
||||
module was created to give programmers a way around this limitation.
|
||||
|
||||
Possible uses:
|
||||
- saving arbitrary data from a script that itself or another one will need
|
||||
to access later.
|
||||
- saving configuration data for a script: users can view and edit this data
|
||||
using the "Scripts Configuration Editor" script.
|
||||
- saving the current state of a script's GUI (its button values) to restore it
|
||||
when the script is executed again.
|
||||
- saving arbitrary data from a script that itself or another one will need
|
||||
to access later.
|
||||
- saving configuration data for a script: users can view and edit this data
|
||||
using the "Scripts Configuration Editor" script.
|
||||
- saving the current state of a script's GUI (its button values) to restore it
|
||||
when the script is executed again.
|
||||
|
||||
Example::
|
||||
|
||||
import Blender
|
||||
from Blender import Registry
|
||||
import Blender
|
||||
from Blender import Registry
|
||||
|
||||
# this function updates the Registry when we need to:
|
||||
def update_Registry():
|
||||
d = {}
|
||||
d['myvar1'] = myvar1
|
||||
d['myvar2'] = myvar2
|
||||
d['mystr'] = mystr
|
||||
# cache = True: data is also saved to a file
|
||||
Blender.Registry.SetKey('MyScript', d, True)
|
||||
# this function updates the Registry when we need to:
|
||||
def update_Registry():
|
||||
d = {}
|
||||
d['myvar1'] = myvar1
|
||||
d['myvar2'] = myvar2
|
||||
d['mystr'] = mystr
|
||||
# cache = True: data is also saved to a file
|
||||
Blender.Registry.SetKey('MyScript', d, True)
|
||||
|
||||
# first declare global variables that should go to the Registry:
|
||||
myvar1 = 0
|
||||
myvar2 = 3.2
|
||||
mystr = "hello"
|
||||
# first declare global variables that should go to the Registry:
|
||||
myvar1 = 0
|
||||
myvar2 = 3.2
|
||||
mystr = "hello"
|
||||
|
||||
# then check if they are already there (saved on a
|
||||
# previous execution of this script):
|
||||
rdict = Registry.GetKey('MyScript', True) # True to check on disk also
|
||||
if rdict: # if found, get the values saved there
|
||||
try:
|
||||
myvar1 = rdict['myvar1']
|
||||
myvar2 = rdict['myvar2']
|
||||
mystr = rdict['mystr']
|
||||
except: update_Registry() # if data isn't valid rewrite it
|
||||
# then check if they are already there (saved on a
|
||||
# previous execution of this script):
|
||||
rdict = Registry.GetKey('MyScript', True) # True to check on disk also
|
||||
if rdict: # if found, get the values saved there
|
||||
try:
|
||||
myvar1 = rdict['myvar1']
|
||||
myvar2 = rdict['myvar2']
|
||||
mystr = rdict['mystr']
|
||||
except: update_Registry() # if data isn't valid rewrite it
|
||||
|
||||
# ...
|
||||
# here goes the main part of the script ...
|
||||
# ...
|
||||
# ...
|
||||
# here goes the main part of the script ...
|
||||
# ...
|
||||
|
||||
# if at some point the data is changed, we update the Registry:
|
||||
update_Registry()
|
||||
# if at some point the data is changed, we update the Registry:
|
||||
update_Registry()
|
||||
|
||||
@note: In Python terms, the Registry holds a dictionary of dictionaries.
|
||||
Technically any Python or BPython object can be stored: there are no
|
||||
restrictions, but ...
|
||||
Technically any Python or BPython object can be stored: there are no
|
||||
restrictions, but ...
|
||||
|
||||
@note: We have a few recommendations:
|
||||
|
||||
Data saved to the Registry is kept in memory, so if you decide to store large
|
||||
amounts your script users should be clearly informed about it --
|
||||
always keep in mind that you have no idea about their resources and the
|
||||
applications they are running at a given time (unless you are the only
|
||||
user), so let them decide.
|
||||
|
||||
There are restrictions to the data that gets automatically saved to disk by
|
||||
L{SetKey}(keyname, dict, True): this feature is only meant for simple data
|
||||
(bools, ints, floats, strings and dictionaries or sequences of these types).
|
||||
Strings are clamped if longer than 300 characters and at most 60 elements are
|
||||
allowed. Since this is only meant for scripts configuration variables,
|
||||
these are sensible restrictions, generous enough for the task.
|
||||
Data saved to the Registry is kept in memory, so if you decide to store large
|
||||
amounts your script users should be clearly informed about it --
|
||||
always keep in mind that you have no idea about their resources and the
|
||||
applications they are running at a given time (unless you are the only
|
||||
user), so let them decide.
|
||||
|
||||
For more demanding needs, it's of course trivial to save data to another
|
||||
file or to a L{Blender Text<Text>}.
|
||||
There are restrictions to the data that gets automatically saved to disk by
|
||||
L{SetKey}(keyname, dict, True): this feature is only meant for simple data
|
||||
(bools, ints, floats, strings and dictionaries or sequences of these types).
|
||||
|
||||
For more demanding needs, it's of course trivial to save data to another
|
||||
file or to a L{Blender Text<Text>}.
|
||||
"""
|
||||
|
||||
def Keys ():
|
||||
"""
|
||||
Get all keys currently in the Registry's dictionary.
|
||||
"""
|
||||
"""
|
||||
Get all keys currently in the Registry's dictionary.
|
||||
"""
|
||||
|
||||
def GetKey (key, cached = False):
|
||||
"""
|
||||
Get key 'key' from the Registry.
|
||||
@type key: string
|
||||
@param key: a key from the Registry dictionary.
|
||||
@type cached: bool
|
||||
@param cached: if True and the requested key isn't already loaded in the
|
||||
Registry, it will also be searched on the user or default scripts config
|
||||
data dir (config subdir in L{Blender.Get}('datadir')).
|
||||
@return: the dictionary called 'key'.
|
||||
"""
|
||||
"""
|
||||
Get key 'key' from the Registry.
|
||||
@type key: string
|
||||
@param key: a key from the Registry dictionary.
|
||||
@type cached: bool
|
||||
@param cached: if True and the requested key isn't already loaded in the
|
||||
Registry, it will also be searched on the user or default scripts config
|
||||
data dir (config subdir in L{Blender.Get}('datadir')).
|
||||
@return: the dictionary called 'key'.
|
||||
"""
|
||||
|
||||
def SetKey (key, dict, cache = False):
|
||||
"""
|
||||
Store a new entry in the Registry.
|
||||
@type key: string
|
||||
@param key: the name of the new entry, tipically your script's name.
|
||||
@type dict: dictionary
|
||||
@param dict: a dict with all data you want to save in the Registry.
|
||||
@type cache: bool
|
||||
@param cache: if True the given key data will also be saved as a file
|
||||
in the config subdir of the scripts user or default data dir (see
|
||||
L{Blender.Get}).
|
||||
@warn: as stated in the notes above, there are restrictions to what can
|
||||
be automatically stored in config files.
|
||||
"""
|
||||
"""
|
||||
Store a new entry in the Registry.
|
||||
@type key: string
|
||||
@param key: the name of the new entry, tipically your script's name.
|
||||
@type dict: dictionary
|
||||
@param dict: a dict with all data you want to save in the Registry.
|
||||
@type cache: bool
|
||||
@param cache: if True the given key data will also be saved as a file
|
||||
in the config subdir of the scripts user or default data dir (see
|
||||
L{Blender.Get}).
|
||||
@warn: as stated in the notes above, there are restrictions to what can
|
||||
be automatically stored in config files.
|
||||
"""
|
||||
|
||||
def RemoveKey (key):
|
||||
"""
|
||||
Remove the dictionary with key 'key' from the Registry.
|
||||
@type key: string
|
||||
@param key: the name of an existing Registry key.
|
||||
"""
|
||||
"""
|
||||
Remove the dictionary with key 'key' from the Registry.
|
||||
@type key: string
|
||||
@param key: the name of an existing Registry key.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user