From 389c7e101e9172b27ee52809a89e76d1086df61c Mon Sep 17 00:00:00 2001 From: Willian Padovani Germano Date: Sun, 29 Jun 2003 14:35:49 +0000 Subject: [PATCH] - Trying to fix something I caused: Added a function call to creator.c that is needed by exppython, but forgot to add the function also to the old bpython implementation. Thanks, Hos! - Addition in Draw.Text and Draw.GetStringWidth (Python Draw methods): Now script writers can select the font size: normal, small or tiny. --- source/blender/bpython/include/BPY_extern.h | 1 + source/blender/bpython/intern/BPY_main.c | 11 + source/blender/python/api2_2x/Draw.c | 1112 ++++++++++--------- 3 files changed, 578 insertions(+), 546 deletions(-) diff --git a/source/blender/bpython/include/BPY_extern.h b/source/blender/bpython/include/BPY_extern.h index 6e92d82e655..a2e55a0b8db 100644 --- a/source/blender/bpython/include/BPY_extern.h +++ b/source/blender/bpython/include/BPY_extern.h @@ -40,6 +40,7 @@ struct _object; // forward declaration for PyObject ! void BPY_start_python(void); void BPY_end_python(void); +void BPY_syspath_append_pythondir(void); int BPY_Err_getLinenumber(void); const char *BPY_Err_getFilename(void); void BPY_Err_Handle(struct Text *text); diff --git a/source/blender/bpython/intern/BPY_main.c b/source/blender/bpython/intern/BPY_main.c index f65bcce693a..aa306dcee38 100644 --- a/source/blender/bpython/intern/BPY_main.c +++ b/source/blender/bpython/intern/BPY_main.c @@ -231,6 +231,17 @@ void init_syspath(void) BPY_debug(("append done\n")); } +/*****************************************************************************/ +/* Description: This function adds the user defined folder for Python */ +/* scripts to sys.path. This is done in init_syspath, too, but */ +/* when Blender's main() runs BPY_start_python(), U.pythondir */ +/* isn't set yet, so we provide this function to be executed */ +/* after U.pythondir is defined. */ +/*****************************************************************************/ +void BPY_syspath_append_pythondir(void) +{ + syspath_append(Py_BuildValue("s", U.pythondir)); +} #define FILENAME_LENGTH 24 typedef struct _ScriptError { diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c index 8febbed4db4..267e9181ba1 100644 --- a/source/blender/python/api2_2x/Draw.c +++ b/source/blender/python/api2_2x/Draw.c @@ -42,92 +42,92 @@ extern short EXPP_releaseGlobalDict; static void Button_dealloc(PyObject *self) { - Button *but = (Button*)self; + Button *but = (Button*)self; - if(but->type == 3) MEM_freeN (but->val.asstr); - - PyObject_DEL (self); + if(but->type == 3) MEM_freeN (but->val.asstr); + + PyObject_DEL (self); } static PyObject *Button_getattr(PyObject *self, char *name) { - Button *but = (Button*)self; - - if(strcmp(name, "val") == 0) { - if (but->type==1) - return Py_BuildValue("i", but->val.asint); - else if (but->type==2) - return Py_BuildValue("f", but->val.asfloat); - else if (but->type==3) - return Py_BuildValue("s", but->val.asstr); - } + Button *but = (Button*)self; + + if(strcmp(name, "val") == 0) { + if (but->type==1) + return Py_BuildValue("i", but->val.asint); + else if (but->type==2) + return Py_BuildValue("f", but->val.asfloat); + else if (but->type==3) + return Py_BuildValue("s", but->val.asstr); + } - PyErr_SetString(PyExc_AttributeError, name); - return NULL; + PyErr_SetString(PyExc_AttributeError, name); + return NULL; } static int Button_setattr(PyObject *self, char *name, PyObject *v) { - Button *but= (Button*) self; - - if(strcmp(name, "val") == 0) { - if (but->type==1) - PyArg_Parse(v, "i", &but->val.asint); - else if (but->type==2) - PyArg_Parse(v, "f", &but->val.asfloat); - else if (but->type==3) { - char *newstr; - - PyArg_Parse(v, "s", &newstr); - strncpy(but->val.asstr, newstr, but->slen); - } - } else { - PyErr_SetString(PyExc_AttributeError, name); - return -1; - } - - return 0; + Button *but= (Button*) self; + + if(strcmp(name, "val") == 0) { + if (but->type==1) + PyArg_Parse(v, "i", &but->val.asint); + else if (but->type==2) + PyArg_Parse(v, "f", &but->val.asfloat); + else if (but->type==3) { + char *newstr; + + PyArg_Parse(v, "s", &newstr); + strncpy(but->val.asstr, newstr, but->slen); + } + } else { + PyErr_SetString(PyExc_AttributeError, name); + return -1; + } + + return 0; } static PyObject *Button_repr(PyObject *self) { - return PyObject_Repr(Button_getattr(self, "val")); + return PyObject_Repr(Button_getattr(self, "val")); } static Button *newbutton (void) { - Button *but= (Button *) PyObject_NEW(Button, &Button_Type); - - return but; + Button *but= (Button *) PyObject_NEW(Button, &Button_Type); + + return but; } /* GUI interface routines */ static void exit_pydraw(SpaceText *st) { - scrarea_queue_redraw(st->area); - - if (st) { - Py_XDECREF((PyObject *) st->py_draw); - Py_XDECREF((PyObject *) st->py_event); - Py_XDECREF((PyObject *) st->py_button); + scrarea_queue_redraw(st->area); + + if (st) { + Py_XDECREF((PyObject *) st->py_draw); + Py_XDECREF((PyObject *) st->py_event); + Py_XDECREF((PyObject *) st->py_button); - st->py_draw= st->py_event= st->py_button= NULL; - } + st->py_draw= st->py_event= st->py_button= NULL; + } } static void exec_callback(SpaceText *st, PyObject *callback, PyObject *args) { - PyObject *result = PyObject_CallObject (callback, args); + PyObject *result = PyObject_CallObject (callback, args); - if (result == NULL) { - st->text->compiled = NULL; - PyErr_Print (); - exit_pydraw (st); - } + if (result == NULL) { + st->text->compiled = NULL; + PyErr_Print (); + exit_pydraw (st); + } - Py_XDECREF (result); - Py_DECREF (args); + Py_XDECREF (result); + Py_DECREF (args); } /* BPY_spacetext_do_pywin_draw, the static spacetext_do_pywin_buttons and @@ -138,55 +138,55 @@ static void exec_callback(SpaceText *st, PyObject *callback, PyObject *args) void BPY_spacetext_do_pywin_draw(SpaceText *st) { - uiBlock *block; - char butblock[20]; + uiBlock *block; + char butblock[20]; - sprintf(butblock, "win %d", curarea->win); - block= uiNewBlock(&curarea->uiblocks, butblock, UI_EMBOSSX, - UI_HELV, curarea->win); - - if (st->py_draw) { - glPushAttrib(GL_ALL_ATTRIB_BITS); - exec_callback(st, st->py_draw, Py_BuildValue("()")); - glPopAttrib(); - } else { - glClearColor(0.4375, 0.4375, 0.4375, 0.0); - glClear(GL_COLOR_BUFFER_BIT); - } + sprintf(butblock, "win %d", curarea->win); + block= uiNewBlock(&curarea->uiblocks, butblock, UI_EMBOSSX, + UI_HELV, curarea->win); + + if (st->py_draw) { + glPushAttrib(GL_ALL_ATTRIB_BITS); + exec_callback(st, st->py_draw, Py_BuildValue("()")); + glPopAttrib(); + } else { + glClearColor(0.4375, 0.4375, 0.4375, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + } - uiDrawBlock(block); + uiDrawBlock(block); - curarea->win_swap= WIN_BACK_OK; + curarea->win_swap= WIN_BACK_OK; } static void spacetext_do_pywin_buttons(SpaceText *st, unsigned short event) { - if (st->py_button) { - exec_callback(st, st->py_button, Py_BuildValue("(i)", event)); - } + if (st->py_button) { + exec_callback(st, st->py_button, Py_BuildValue("(i)", event)); + } } void BPY_spacetext_do_pywin_event(SpaceText *st, unsigned short event, short val) { - if (event == QKEY && G.qual & (LR_ALTKEY|LR_CTRLKEY|LR_SHIFTKEY)) { - exit_pydraw(st); - return; - } + if (event == QKEY && G.qual & (LR_ALTKEY|LR_CTRLKEY|LR_SHIFTKEY)) { + exit_pydraw(st); + return; + } - if (val) { - if (uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0; + if (val) { + if (uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0; - if (event==UI_BUT_EVENT) - spacetext_do_pywin_buttons(st, val); - } - - if (st->py_event) - exec_callback(st, st->py_event, Py_BuildValue("(ii)", event, val)); + if (event==UI_BUT_EVENT) + spacetext_do_pywin_buttons(st, val); + } + + if (st->py_event) + exec_callback(st, st->py_event, Py_BuildValue("(ii)", event, val)); } int BPY_spacetext_is_pywin(SpaceText *st) { - return (st->py_draw || st->py_event || st->py_button); + return (st->py_draw || st->py_event || st->py_button); } /* the define CLEAR_NAMESPACE is currently ignored. It should be @@ -194,214 +194,214 @@ int BPY_spacetext_is_pywin(SpaceText *st) * programmer(s) who put it there. */ static PyObject *Method_Exit (PyObject *self, PyObject *args) -{ - SpaceText *st= curarea->spacedata.first; +{ + SpaceText *st= curarea->spacedata.first; - if (!PyArg_ParseTuple(args, "")) - return EXPP_ReturnPyObjError (PyExc_AttributeError, - "expected empty argument list"); + if (!PyArg_ParseTuple(args, "")) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected empty argument list"); - exit_pydraw(st); + exit_pydraw(st); - if (EXPP_releaseGlobalDict) { - PyObject *d = st->py_globaldict; - /* d is the current window's global namespace dictionary */ - if (d) { - PyDict_Clear(d); - Py_DECREF(d); /* release dictionary */ - } - } + if (EXPP_releaseGlobalDict) { + PyObject *d = st->py_globaldict; + /* d is the current window's global namespace dictionary */ + if (d) { + PyDict_Clear(d); + Py_DECREF(d); /* release dictionary */ + } + } - return EXPP_incr_ret (Py_None); + return EXPP_incr_ret (Py_None); } static PyObject *Method_Register (PyObject *self, PyObject *args) { - PyObject *newdrawc= NULL, *neweventc= NULL, *newbuttonc= NULL; - SpaceText *st= curarea->spacedata.first; - - if (!PyArg_ParseTuple(args, "O|OO", &newdrawc, - &neweventc, &newbuttonc)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected one or three PyObjects"); + PyObject *newdrawc= NULL, *neweventc= NULL, *newbuttonc= NULL; + SpaceText *st= curarea->spacedata.first; + + if (!PyArg_ParseTuple(args, "O|OO", &newdrawc, + &neweventc, &newbuttonc)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected one or three PyObjects"); - /*@This is a hack again: - * Every python script should actually do a global variable cleanup at - * the end of execution. - * For scripts registering GUI callbacks, this does not work, because - * the global namespace of the interpreter still needs to be accessed - * from the callback. - * Workaround: a text object has a flag which allows the global name - * space to be cleared at the end of the script. This flag should be - * normally set when executed with Alt-P. For a script registering with - * the GUI though, clear the flag and set it when the GUI mode is left - * (Method_Exit). - */ + /*@This is a hack again: + * Every python script should actually do a global variable cleanup at + * the end of execution. + * For scripts registering GUI callbacks, this does not work, because + * the global namespace of the interpreter still needs to be accessed + * from the callback. + * Workaround: a text object has a flag which allows the global name + * space to be cleared at the end of the script. This flag should be + * normally set when executed with Alt-P. For a script registering with + * the GUI though, clear the flag and set it when the GUI mode is left + * (Method_Exit). + */ -/* EXPP_debug(("--- disable clear namespace")); */ +/* EXPP_debug(("--- disable clear namespace")); */ - st->flags &= ~ST_CLEAR_NAMESPACE; + st->flags &= ~ST_CLEAR_NAMESPACE; - if (!PyCallable_Check(newdrawc)) newdrawc = NULL; - if (!PyCallable_Check(neweventc)) neweventc = NULL; - if (!PyCallable_Check(newbuttonc)) newbuttonc = NULL; + if (!PyCallable_Check(newdrawc)) newdrawc = NULL; + if (!PyCallable_Check(neweventc)) neweventc = NULL; + if (!PyCallable_Check(newbuttonc)) newbuttonc = NULL; - if (!(newdrawc || neweventc || newbuttonc)) - return EXPP_incr_ret(Py_None); + if (!(newdrawc || neweventc || newbuttonc)) + return EXPP_incr_ret(Py_None); - exit_pydraw(st); + exit_pydraw(st); - Py_XINCREF(newdrawc); - Py_XINCREF(neweventc); - Py_XINCREF(newbuttonc); + Py_XINCREF(newdrawc); + Py_XINCREF(neweventc); + Py_XINCREF(newbuttonc); - st->py_draw= newdrawc; - st->py_event= neweventc; - st->py_button= newbuttonc; + st->py_draw= newdrawc; + st->py_event= neweventc; + st->py_button= newbuttonc; - scrarea_queue_redraw(st->area); + scrarea_queue_redraw(st->area); - return EXPP_incr_ret (Py_None); + return EXPP_incr_ret (Py_None); } static PyObject *Method_Redraw (PyObject *self, PyObject *args) { - int after= 0; - - if (!PyArg_ParseTuple(args, "|i", &after)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected int argument (or nothing)"); + int after= 0; + + if (!PyArg_ParseTuple(args, "|i", &after)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected int argument (or nothing)"); - if (after) addafterqueue(curarea->win, REDRAW, 1); - else scrarea_queue_winredraw(curarea); - - return EXPP_incr_ret(Py_None); + if (after) addafterqueue(curarea->win, REDRAW, 1); + else scrarea_queue_winredraw(curarea); + + return EXPP_incr_ret(Py_None); } static PyObject *Method_Draw (PyObject *self, PyObject *args) { - /*@ If forced drawing is disable queue a redraw event instead */ - if (EXPP_disable_force_draw) { - scrarea_queue_winredraw(curarea); - return EXPP_incr_ret (Py_None); - } + /*@ If forced drawing is disable queue a redraw event instead */ + if (EXPP_disable_force_draw) { + scrarea_queue_winredraw(curarea); + return EXPP_incr_ret (Py_None); + } - if (!PyArg_ParseTuple(args, "")) - return EXPP_ReturnPyObjError (PyExc_AttributeError, - "expected empty argument list"); + if (!PyArg_ParseTuple(args, "")) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected empty argument list"); - scrarea_do_windraw(curarea); + scrarea_do_windraw(curarea); - screen_swapbuffers(); + screen_swapbuffers(); - return EXPP_incr_ret (Py_None); + return EXPP_incr_ret (Py_None); } static PyObject *Method_Create (PyObject *self, PyObject *args) { - Button *but; - PyObject *in; + Button *but; + PyObject *in; - if (!PyArg_ParseTuple(args, "O", &in)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected PyObject argument"); - - but= newbutton(); - if(PyFloat_Check(in)) { - but->type= 2; - but->val.asfloat= PyFloat_AsDouble(in); - } else if (PyInt_Check(in)) { - but->type= 1; - but->val.asint= PyInt_AsLong(in); - } else if (PyString_Check(in)) { - char *newstr= PyString_AsString(in); - - but->type= 3; - but->slen= strlen(newstr); - but->val.asstr= MEM_mallocN(but->slen+1, "button string"); - - strcpy(but->val.asstr, newstr); - } - - return (PyObject *) but; + if (!PyArg_ParseTuple(args, "O", &in)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected PyObject argument"); + + but= newbutton(); + if(PyFloat_Check(in)) { + but->type= 2; + but->val.asfloat= PyFloat_AsDouble(in); + } else if (PyInt_Check(in)) { + but->type= 1; + but->val.asint= PyInt_AsLong(in); + } else if (PyString_Check(in)) { + char *newstr= PyString_AsString(in); + + but->type= 3; + but->slen= strlen(newstr); + but->val.asstr= MEM_mallocN(but->slen+1, "button string"); + + strcpy(but->val.asstr, newstr); + } + + return (PyObject *) but; } static uiBlock *Get_uiBlock(void) { - char butblock[32]; - - sprintf(butblock, "win %d", curarea->win); + char butblock[32]; + + sprintf(butblock, "win %d", curarea->win); - return uiGetBlock(butblock, curarea); + return uiGetBlock(butblock, curarea); } 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"); - - block= Get_uiBlock(); + 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"); + + block= Get_uiBlock(); - if(block) uiDefBut(block, BUT, event, name, x, y, w, h, - 0, 0, 0, 0, 0, tip); - - return EXPP_incr_ret(Py_None); + if(block) uiDefBut(block, BUT, event, name, x, y, w, h, + 0, 0, 0, 0, 0, tip); + + return EXPP_incr_ret(Py_None); } static PyObject *Method_Menu (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip= NULL; - int event, def; - int x, y, w, h; - Button *but; - - if (!PyArg_ParseTuple(args, "siiiiii|s", &name, &event, - &x, &y, &w, &h, &def, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, six ints and optionally another string as arguments"); + uiBlock *block; + char *name, *tip= NULL; + int event, def; + int x, y, w, h; + Button *but; + + if (!PyArg_ParseTuple(args, "siiiiii|s", &name, &event, + &x, &y, &w, &h, &def, &tip)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, six ints and optionally another string as arguments"); - but= newbutton(); - but->type= 1; - but->val.asint= def; - - block= Get_uiBlock(); - if(block) uiDefButI(block, MENU, event, name, x, y, w, h, - &but->val.asint, 0, 0, 0, 0, tip); - - return (PyObject *) but; + but= newbutton(); + but->type= 1; + but->val.asint= def; + + block= Get_uiBlock(); + if(block) uiDefButI(block, MENU, event, name, x, y, w, h, + &but->val.asint, 0, 0, 0, 0, tip); + + return (PyObject *) but; } static PyObject *Method_Toggle (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip= NULL; - int event; - int x, y, w, h, def; - Button *but; - - if (!PyArg_ParseTuple(args, "siiiiii|s", &name, &event, - &x, &y, &w, &h, &def, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, six ints and optionally another string as arguments"); + uiBlock *block; + char *name, *tip= NULL; + int event; + int x, y, w, h, def; + Button *but; + + if (!PyArg_ParseTuple(args, "siiiiii|s", &name, &event, + &x, &y, &w, &h, &def, &tip)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, six ints and optionally another string as arguments"); - but= newbutton(); - but->type= 1; - but->val.asint= def; - - block= Get_uiBlock(); - if(block) uiDefButI(block, TOG, event, name, x, y, w, h, - &but->val.asint, 0, 0, 0, 0, tip); - - return (PyObject *) but; + but= newbutton(); + but->type= 1; + but->val.asint= def; + + block= Get_uiBlock(); + if(block) uiDefButI(block, TOG, event, name, x, y, w, h, + &but->val.asint, 0, 0, 0, 0, tip); + + return (PyObject *) but; } /*@DO NOT TOUCH THIS FUNCTION ! @@ -413,381 +413,401 @@ static PyObject *Method_Toggle (PyObject *self, PyObject *args) static void py_slider_update(void *butv, void *data2_unused) { - uiBut *but= butv; + uiBut *but= butv; - EXPP_disable_force_draw= 1; - /*@ - Disable forced drawing, otherwise the button object which - is still being used might be deleted - */ + EXPP_disable_force_draw= 1; + /*@ + Disable forced drawing, otherwise the button object which + is still being used might be deleted + */ -/*@ UIfrontbuf = 0; - spacetext_do_pywin_buttons(curarea->spacedata.first, but->retval); */ +/*@ UIfrontbuf = 0; + spacetext_do_pywin_buttons(curarea->spacedata.first, but->retval); */ - g_window_redrawn = 0; - curarea->win_swap= WIN_BACK_OK; - UIfrontbuf = 1; - spacetext_do_pywin_buttons(curarea->spacedata.first, uiButGetRetVal(but)); - UIfrontbuf = 0; + g_window_redrawn = 0; + curarea->win_swap= WIN_BACK_OK; + UIfrontbuf = 1; + spacetext_do_pywin_buttons(curarea->spacedata.first, uiButGetRetVal(but)); + UIfrontbuf = 0; - if (!g_window_redrawn) /*@ if Redraw already called */ - M_Window_Redraw(0, Py_BuildValue("(i)", SPACE_VIEW3D)); + if (!g_window_redrawn) /*@ if Redraw already called */ + M_Window_Redraw(0, Py_BuildValue("(i)", SPACE_VIEW3D)); - EXPP_disable_force_draw= 0; + EXPP_disable_force_draw= 0; } static PyObject *Method_Slider (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip= NULL; - int event; - int x, y, w, h, realtime=1; - Button *but; - PyObject *mino, *maxo, *inio; - - if (!PyArg_ParseTuple(args, "siiiiiOOO|is", &name, &event, - &x, &y, &w, &h, &inio, &mino, &maxo, &realtime, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, five ints, three PyObjects\n\ - and optionally another int and string as arguments"); + uiBlock *block; + char *name, *tip= NULL; + int event; + int x, y, w, h, realtime=1; + Button *but; + PyObject *mino, *maxo, *inio; + + if (!PyArg_ParseTuple(args, "siiiiiOOO|is", &name, &event, + &x, &y, &w, &h, &inio, &mino, &maxo, &realtime, &tip)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, five ints, three PyObjects\n\ + and optionally another int and string as arguments"); - but= newbutton(); - if (PyFloat_Check(inio)) { - float ini, min, max; + but= newbutton(); + if (PyFloat_Check(inio)) { + float ini, min, max; - ini= PyFloat_AsDouble(inio); - min= PyFloat_AsDouble(mino); - max= PyFloat_AsDouble(maxo); - - but->type= 2; - but->val.asfloat= ini; + ini= PyFloat_AsDouble(inio); + min= PyFloat_AsDouble(mino); + max= PyFloat_AsDouble(maxo); + + but->type= 2; + but->val.asfloat= ini; - block= Get_uiBlock(); - if(block) { - uiBut *ubut; - ubut= uiDefButF(block, NUMSLI, event, name, x, y, w, h, - &but->val.asfloat, min, max, 0, 0, tip); - if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); - } - } - else { - int ini, min, max; + block= Get_uiBlock(); + if(block) { + uiBut *ubut; + ubut= uiDefButF(block, NUMSLI, event, name, x, y, w, h, + &but->val.asfloat, min, max, 0, 0, tip); + if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); + } + } + else { + int ini, min, max; - ini= PyInt_AsLong(inio); - min= PyInt_AsLong(mino); - max= PyInt_AsLong(maxo); - - but->type= 1; - but->val.asint= ini; - - block= Get_uiBlock(); - if(block) { - uiBut *ubut; - ubut= uiDefButI(block, NUMSLI, event, name, x, y, w, h, - &but->val.asint, min, max, 0, 0, tip); - if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); - } - } - return (PyObject *) but; + ini= PyInt_AsLong(inio); + min= PyInt_AsLong(mino); + max= PyInt_AsLong(maxo); + + but->type= 1; + but->val.asint= ini; + + block= Get_uiBlock(); + if(block) { + uiBut *ubut; + ubut= uiDefButI(block, NUMSLI, event, name, x, y, w, h, + &but->val.asint, min, max, 0, 0, tip); + if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); + } + } + return (PyObject *) but; } static PyObject *Method_Scrollbar (PyObject *self, PyObject *args) { - char *tip= NULL; - uiBlock *block; - int event; - int x, y, w, h, realtime=1; - Button *but; - PyObject *mino, *maxo, *inio; - float ini, min, max; + char *tip= NULL; + uiBlock *block; + int event; + int x, y, w, h, realtime=1; + Button *but; + PyObject *mino, *maxo, *inio; + float ini, min, max; - if (!PyArg_ParseTuple(args, "iiiiiOOO|is", &event, &x, &y, &w, &h, - &inio, &mino, &maxo, &realtime, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected five ints, three PyObjects and optionally\n\ - another int and string as arguments"); + if (!PyArg_ParseTuple(args, "iiiiiOOO|is", &event, &x, &y, &w, &h, + &inio, &mino, &maxo, &realtime, &tip)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected five ints, three PyObjects and optionally\n\ + another int and string as arguments"); - if (!PyNumber_Check(inio) || !PyNumber_Check(inio) || !PyNumber_Check(inio)) - return EXPP_ReturnPyObjError (PyExc_AttributeError, - "expected numbers for initial, min, and max"); + if (!PyNumber_Check(inio) || !PyNumber_Check(inio) || !PyNumber_Check(inio)) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected numbers for initial, min, and max"); - but= newbutton(); + but= newbutton(); - if (PyFloat_Check(inio)) but->type= 2; - else but->type= 1; + if (PyFloat_Check(inio)) but->type= 2; + else but->type= 1; - ini= PyFloat_AsDouble(inio); - min= PyFloat_AsDouble(mino); - max= PyFloat_AsDouble(maxo); + ini= PyFloat_AsDouble(inio); + min= PyFloat_AsDouble(mino); + max= PyFloat_AsDouble(maxo); - if (but->type==2) { - but->val.asfloat= ini; - block= Get_uiBlock(); - if(block) { - uiBut *ubut; - ubut= uiDefButF(block, SCROLL, event, "", x, y, w, h, - &but->val.asfloat, min, max, 0, 0, tip); - if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); - } - } else { - but->val.asint= ini; - block= Get_uiBlock(); - if(block) { - uiBut *ubut; - ubut= uiDefButI(block, SCROLL, event, "", x, y, w, h, - &but->val.asint, min, max, 0, 0, tip); - if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); - } - } + if (but->type==2) { + but->val.asfloat= ini; + block= Get_uiBlock(); + if(block) { + uiBut *ubut; + ubut= uiDefButF(block, SCROLL, event, "", x, y, w, h, + &but->val.asfloat, min, max, 0, 0, tip); + if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); + } + } else { + but->val.asint= ini; + block= Get_uiBlock(); + if(block) { + uiBut *ubut; + ubut= uiDefButI(block, SCROLL, event, "", x, y, w, h, + &but->val.asint, min, max, 0, 0, tip); + if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); + } + } - return (PyObject *) but; + return (PyObject *) but; } static PyObject *Method_Number (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip= NULL; - int event; - 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)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, five ints, three PyObjects and\n\ - optionally another string as arguments"); + uiBlock *block; + char *name, *tip= NULL; + int event; + 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)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, five ints, three PyObjects and\n\ + optionally another string as arguments"); - but= newbutton(); - - if (PyFloat_Check(inio)) { - float ini, min, max; + but= newbutton(); + + if (PyFloat_Check(inio)) { + float ini, min, max; - ini= PyFloat_AsDouble(inio); - min= PyFloat_AsDouble(mino); - max= PyFloat_AsDouble(maxo); - - but->type= 2; - but->val.asfloat= ini; - - block= Get_uiBlock(); - if(block) uiDefButF(block, NUM, event, name, x, y, w, h, - &but->val.asfloat, min, max, 0, 0, tip); - } else { - int ini, min, max; + ini= PyFloat_AsDouble(inio); + min= PyFloat_AsDouble(mino); + max= PyFloat_AsDouble(maxo); + + but->type= 2; + but->val.asfloat= ini; + + block= Get_uiBlock(); + if(block) uiDefButF(block, NUM, event, name, x, y, w, h, + &but->val.asfloat, min, max, 0, 0, tip); + } else { + int ini, min, max; - ini= PyInt_AsLong(inio); - min= PyInt_AsLong(mino); - max= PyInt_AsLong(maxo); - - but->type= 1; - but->val.asint= ini; - - block= Get_uiBlock(); - if(block) uiDefButI(block, NUM, event, name, x, y, w, h, - &but->val.asint, min, max, 0, 0, tip); - } + ini= PyInt_AsLong(inio); + min= PyInt_AsLong(mino); + max= PyInt_AsLong(maxo); + + but->type= 1; + but->val.asint= ini; + + block= Get_uiBlock(); + if(block) uiDefButI(block, NUM, event, name, x, y, w, h, + &but->val.asint, min, max, 0, 0, tip); + } - return (PyObject *) but; + return (PyObject *) but; } static PyObject *Method_String (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip= NULL, *newstr; - int event; - int x, y, w, h, len; - Button *but; - - if (!PyArg_ParseTuple(args, "siiiiisi|s", &name, &event, - &x, &y, &w, &h, &newstr, &len, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, five ints, a string, an int and\n\ - optionally another string as arguments"); + uiBlock *block; + char *name, *tip= NULL, *newstr; + int event; + int x, y, w, h, len; + Button *but; + + if (!PyArg_ParseTuple(args, "siiiiisi|s", &name, &event, + &x, &y, &w, &h, &newstr, &len, &tip)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, five ints, a string, an int and\n\ + optionally another string as arguments"); - but= newbutton(); - but->type= 3; - but->slen= len; - but->val.asstr= MEM_mallocN(len+1, "button string"); - - strncpy(but->val.asstr, newstr, len); - but->val.asstr[len]= 0; - - block= Get_uiBlock(); - if(block) uiDefBut(block, TEX, event, name, x, y, w, h, - but->val.asstr, 0, len, 0, 0, tip); + but= newbutton(); + but->type= 3; + but->slen= len; + but->val.asstr= MEM_mallocN(len+1, "button string"); + + strncpy(but->val.asstr, newstr, len); + but->val.asstr[len]= 0; + + block= Get_uiBlock(); + if(block) uiDefBut(block, TEX, event, name, x, y, w, h, + but->val.asstr, 0, len, 0, 0, tip); - return (PyObject *) but; + return (PyObject *) but; } static PyObject *Method_GetStringWidth (PyObject *self, PyObject *args) { - char *text; - PyObject *width; + char *text; + char *font_str = NULL; + struct BMF_Font *font; + PyObject *width; - if (!PyArg_ParseTuple (args, "s", &text)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected string argument"); + if (!PyArg_ParseTuple(args, "s|s", &text, &font_str)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected one or two string arguments"); - width = PyInt_FromLong(BMF_GetStringWidth (G.font, text)); + if (!font_str) font = (&G)->font; + else if (!strcmp (font_str, "normal")) font = (&G)->font; + else if (!strcmp (font_str, "small" )) font = (&G)->fonts; + else if (!strcmp (font_str, "tiny" )) font = (&G)->fontss; + else + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "\"font\" must be: 'normal' (same as None), 'small' or 'tiny'."); - if (!width) - return EXPP_ReturnPyObjError (PyExc_MemoryError, - "couldn't create PyInt"); + width = PyInt_FromLong(BMF_GetStringWidth (font, text)); - return width; + if (!width) + return EXPP_ReturnPyObjError (PyExc_MemoryError, + "couldn't create PyInt"); + + return width; } static PyObject *Method_Text (PyObject *self, PyObject *args) { - char *text; - - if (!PyArg_ParseTuple(args, "s", &text)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected string argument"); + char *text; + char *font_str = NULL; + struct BMF_Font *font; - BMF_DrawString(G.font, text); - - return EXPP_incr_ret(Py_None); + if (!PyArg_ParseTuple(args, "s|s", &text, &font_str)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected one or two string arguments"); + + if (!font_str) font = (&G)->font; + else if (!strcmp (font_str, "normal")) font = (&G)->font; + else if (!strcmp (font_str, "small" )) font = (&G)->fonts; + else if (!strcmp (font_str, "tiny" )) font = (&G)->fontss; + else + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "\"font\" must be: 'normal' (same as None), 'small' or 'tiny'."); + + BMF_DrawString(font, text); + + return EXPP_incr_ret(Py_None); } PyObject *Draw_Init (void) { - PyObject *submodule, *dict; + PyObject *submodule, *dict; Button_Type.ob_type = &PyType_Type; - submodule = Py_InitModule3("Blender.Draw", Draw_methods, Draw_doc); + submodule = Py_InitModule3("Blender.Draw", Draw_methods, Draw_doc); - dict= PyModule_GetDict(submodule); + dict= PyModule_GetDict(submodule); #define EXPP_ADDCONST(x) \ - PyDict_SetItemString(dict, #x, PyInt_FromLong(x)) + PyDict_SetItemString(dict, #x, PyInt_FromLong(x)) /* So, for example: * EXPP_ADDCONST(LEFTMOUSE) becomes * PyDict_SetItemString(dict, "LEFTMOUSE", PyInt_FromLong(LEFTMOUSE)) */ - EXPP_ADDCONST(LEFTMOUSE); - EXPP_ADDCONST(MIDDLEMOUSE); - EXPP_ADDCONST(RIGHTMOUSE); - EXPP_ADDCONST(MOUSEX); - EXPP_ADDCONST(MOUSEY); - EXPP_ADDCONST(TIMER0); - EXPP_ADDCONST(TIMER1); - EXPP_ADDCONST(TIMER2); - EXPP_ADDCONST(TIMER3); - EXPP_ADDCONST(KEYBD); - EXPP_ADDCONST(RAWKEYBD); - EXPP_ADDCONST(REDRAW); - EXPP_ADDCONST(INPUTCHANGE); - EXPP_ADDCONST(QFULL); - EXPP_ADDCONST(WINFREEZE); - EXPP_ADDCONST(WINTHAW); - EXPP_ADDCONST(WINCLOSE); - EXPP_ADDCONST(WINQUIT); + EXPP_ADDCONST(LEFTMOUSE); + EXPP_ADDCONST(MIDDLEMOUSE); + EXPP_ADDCONST(RIGHTMOUSE); + EXPP_ADDCONST(MOUSEX); + EXPP_ADDCONST(MOUSEY); + EXPP_ADDCONST(TIMER0); + EXPP_ADDCONST(TIMER1); + EXPP_ADDCONST(TIMER2); + EXPP_ADDCONST(TIMER3); + EXPP_ADDCONST(KEYBD); + EXPP_ADDCONST(RAWKEYBD); + EXPP_ADDCONST(REDRAW); + EXPP_ADDCONST(INPUTCHANGE); + EXPP_ADDCONST(QFULL); + EXPP_ADDCONST(WINFREEZE); + EXPP_ADDCONST(WINTHAW); + EXPP_ADDCONST(WINCLOSE); + EXPP_ADDCONST(WINQUIT); #ifndef IRISGL - EXPP_ADDCONST(Q_FIRSTTIME); + EXPP_ADDCONST(Q_FIRSTTIME); #endif - EXPP_ADDCONST(AKEY); - EXPP_ADDCONST(BKEY); - EXPP_ADDCONST(CKEY); - EXPP_ADDCONST(DKEY); - EXPP_ADDCONST(EKEY); - EXPP_ADDCONST(FKEY); - EXPP_ADDCONST(GKEY); - EXPP_ADDCONST(HKEY); - EXPP_ADDCONST(IKEY); - EXPP_ADDCONST(JKEY); - EXPP_ADDCONST(KKEY); - EXPP_ADDCONST(LKEY); - EXPP_ADDCONST(MKEY); - EXPP_ADDCONST(NKEY); - EXPP_ADDCONST(OKEY); - EXPP_ADDCONST(PKEY); - EXPP_ADDCONST(QKEY); - EXPP_ADDCONST(RKEY); - EXPP_ADDCONST(SKEY); - EXPP_ADDCONST(TKEY); - EXPP_ADDCONST(UKEY); - EXPP_ADDCONST(VKEY); - EXPP_ADDCONST(WKEY); - EXPP_ADDCONST(XKEY); - EXPP_ADDCONST(YKEY); - EXPP_ADDCONST(ZKEY); - EXPP_ADDCONST(ZEROKEY); - EXPP_ADDCONST(ONEKEY); - EXPP_ADDCONST(TWOKEY); - EXPP_ADDCONST(THREEKEY); - EXPP_ADDCONST(FOURKEY); - EXPP_ADDCONST(FIVEKEY); - EXPP_ADDCONST(SIXKEY); - EXPP_ADDCONST(SEVENKEY); - EXPP_ADDCONST(EIGHTKEY); - EXPP_ADDCONST(NINEKEY); - EXPP_ADDCONST(CAPSLOCKKEY); - EXPP_ADDCONST(LEFTCTRLKEY); - EXPP_ADDCONST(LEFTALTKEY); - EXPP_ADDCONST(RIGHTALTKEY); - EXPP_ADDCONST(RIGHTCTRLKEY); - EXPP_ADDCONST(RIGHTSHIFTKEY); - EXPP_ADDCONST(LEFTSHIFTKEY); - EXPP_ADDCONST(ESCKEY); - EXPP_ADDCONST(TABKEY); - EXPP_ADDCONST(RETKEY); - EXPP_ADDCONST(SPACEKEY); - EXPP_ADDCONST(LINEFEEDKEY); - EXPP_ADDCONST(BACKSPACEKEY); - EXPP_ADDCONST(DELKEY); - EXPP_ADDCONST(SEMICOLONKEY); - EXPP_ADDCONST(PERIODKEY); - EXPP_ADDCONST(COMMAKEY); - EXPP_ADDCONST(QUOTEKEY); - EXPP_ADDCONST(ACCENTGRAVEKEY); - EXPP_ADDCONST(MINUSKEY); - EXPP_ADDCONST(SLASHKEY); - EXPP_ADDCONST(BACKSLASHKEY); - EXPP_ADDCONST(EQUALKEY); - EXPP_ADDCONST(LEFTBRACKETKEY); - EXPP_ADDCONST(RIGHTBRACKETKEY); - EXPP_ADDCONST(LEFTARROWKEY); - EXPP_ADDCONST(DOWNARROWKEY); - EXPP_ADDCONST(RIGHTARROWKEY); - EXPP_ADDCONST(UPARROWKEY); - EXPP_ADDCONST(PAD2); - EXPP_ADDCONST(PAD4); - EXPP_ADDCONST(PAD6); - EXPP_ADDCONST(PAD8); - EXPP_ADDCONST(PAD1); - EXPP_ADDCONST(PAD3); - EXPP_ADDCONST(PAD5); - EXPP_ADDCONST(PAD7); - EXPP_ADDCONST(PAD9); - EXPP_ADDCONST(PADPERIOD); - EXPP_ADDCONST(PADSLASHKEY); - EXPP_ADDCONST(PADASTERKEY); - EXPP_ADDCONST(PAD0); - EXPP_ADDCONST(PADMINUS); - EXPP_ADDCONST(PADENTER); - EXPP_ADDCONST(PADPLUSKEY); - EXPP_ADDCONST(F1KEY); - EXPP_ADDCONST(F2KEY); - EXPP_ADDCONST(F3KEY); - EXPP_ADDCONST(F4KEY); - EXPP_ADDCONST(F5KEY); - EXPP_ADDCONST(F6KEY); - EXPP_ADDCONST(F7KEY); - EXPP_ADDCONST(F8KEY); - EXPP_ADDCONST(F9KEY); - EXPP_ADDCONST(F10KEY); - EXPP_ADDCONST(F11KEY); - EXPP_ADDCONST(F12KEY); - EXPP_ADDCONST(PAUSEKEY); - EXPP_ADDCONST(INSERTKEY); - EXPP_ADDCONST(HOMEKEY); - EXPP_ADDCONST(PAGEUPKEY); - EXPP_ADDCONST(PAGEDOWNKEY); - EXPP_ADDCONST(ENDKEY); + EXPP_ADDCONST(AKEY); + EXPP_ADDCONST(BKEY); + EXPP_ADDCONST(CKEY); + EXPP_ADDCONST(DKEY); + EXPP_ADDCONST(EKEY); + EXPP_ADDCONST(FKEY); + EXPP_ADDCONST(GKEY); + EXPP_ADDCONST(HKEY); + EXPP_ADDCONST(IKEY); + EXPP_ADDCONST(JKEY); + EXPP_ADDCONST(KKEY); + EXPP_ADDCONST(LKEY); + EXPP_ADDCONST(MKEY); + EXPP_ADDCONST(NKEY); + EXPP_ADDCONST(OKEY); + EXPP_ADDCONST(PKEY); + EXPP_ADDCONST(QKEY); + EXPP_ADDCONST(RKEY); + EXPP_ADDCONST(SKEY); + EXPP_ADDCONST(TKEY); + EXPP_ADDCONST(UKEY); + EXPP_ADDCONST(VKEY); + EXPP_ADDCONST(WKEY); + EXPP_ADDCONST(XKEY); + EXPP_ADDCONST(YKEY); + EXPP_ADDCONST(ZKEY); + EXPP_ADDCONST(ZEROKEY); + EXPP_ADDCONST(ONEKEY); + EXPP_ADDCONST(TWOKEY); + EXPP_ADDCONST(THREEKEY); + EXPP_ADDCONST(FOURKEY); + EXPP_ADDCONST(FIVEKEY); + EXPP_ADDCONST(SIXKEY); + EXPP_ADDCONST(SEVENKEY); + EXPP_ADDCONST(EIGHTKEY); + EXPP_ADDCONST(NINEKEY); + EXPP_ADDCONST(CAPSLOCKKEY); + EXPP_ADDCONST(LEFTCTRLKEY); + EXPP_ADDCONST(LEFTALTKEY); + EXPP_ADDCONST(RIGHTALTKEY); + EXPP_ADDCONST(RIGHTCTRLKEY); + EXPP_ADDCONST(RIGHTSHIFTKEY); + EXPP_ADDCONST(LEFTSHIFTKEY); + EXPP_ADDCONST(ESCKEY); + EXPP_ADDCONST(TABKEY); + EXPP_ADDCONST(RETKEY); + EXPP_ADDCONST(SPACEKEY); + EXPP_ADDCONST(LINEFEEDKEY); + EXPP_ADDCONST(BACKSPACEKEY); + EXPP_ADDCONST(DELKEY); + EXPP_ADDCONST(SEMICOLONKEY); + EXPP_ADDCONST(PERIODKEY); + EXPP_ADDCONST(COMMAKEY); + EXPP_ADDCONST(QUOTEKEY); + EXPP_ADDCONST(ACCENTGRAVEKEY); + EXPP_ADDCONST(MINUSKEY); + EXPP_ADDCONST(SLASHKEY); + EXPP_ADDCONST(BACKSLASHKEY); + EXPP_ADDCONST(EQUALKEY); + EXPP_ADDCONST(LEFTBRACKETKEY); + EXPP_ADDCONST(RIGHTBRACKETKEY); + EXPP_ADDCONST(LEFTARROWKEY); + EXPP_ADDCONST(DOWNARROWKEY); + EXPP_ADDCONST(RIGHTARROWKEY); + EXPP_ADDCONST(UPARROWKEY); + EXPP_ADDCONST(PAD2); + EXPP_ADDCONST(PAD4); + EXPP_ADDCONST(PAD6); + EXPP_ADDCONST(PAD8); + EXPP_ADDCONST(PAD1); + EXPP_ADDCONST(PAD3); + EXPP_ADDCONST(PAD5); + EXPP_ADDCONST(PAD7); + EXPP_ADDCONST(PAD9); + EXPP_ADDCONST(PADPERIOD); + EXPP_ADDCONST(PADSLASHKEY); + EXPP_ADDCONST(PADASTERKEY); + EXPP_ADDCONST(PAD0); + EXPP_ADDCONST(PADMINUS); + EXPP_ADDCONST(PADENTER); + EXPP_ADDCONST(PADPLUSKEY); + EXPP_ADDCONST(F1KEY); + EXPP_ADDCONST(F2KEY); + EXPP_ADDCONST(F3KEY); + EXPP_ADDCONST(F4KEY); + EXPP_ADDCONST(F5KEY); + EXPP_ADDCONST(F6KEY); + EXPP_ADDCONST(F7KEY); + EXPP_ADDCONST(F8KEY); + EXPP_ADDCONST(F9KEY); + EXPP_ADDCONST(F10KEY); + EXPP_ADDCONST(F11KEY); + EXPP_ADDCONST(F12KEY); + EXPP_ADDCONST(PAUSEKEY); + EXPP_ADDCONST(INSERTKEY); + EXPP_ADDCONST(HOMEKEY); + EXPP_ADDCONST(PAGEUPKEY); + EXPP_ADDCONST(PAGEDOWNKEY); + EXPP_ADDCONST(ENDKEY); - return submodule; + return submodule; }