diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-04-24 21:28:40 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-04-24 21:28:40 +0400 |
commit | 77f08ddc12870b90064273fa314d462ccdd473ba (patch) | |
tree | 2b5cb29c3e57deae521d30d384ddbbe622d7cdcb /source/blender | |
parent | 46545ac575e500d46aae3fabb05f6d46a7fb1797 (diff) |
editface.c & buttons_logic.c & Draw.c & verse_session.c - added missing header
Bone.c - return an empty list rather then None for bone.children bone.getAllChildren()
Draw.c - per button callbacks are now have (event, value) passed
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/verse_session.c | 1 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Bone.c | 19 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Draw.c | 107 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Draw.py | 32 | ||||
-rw-r--r-- | source/blender/src/buttons_logic.c | 1 | ||||
-rw-r--r-- | source/blender/src/editface.c | 1 |
6 files changed, 106 insertions, 55 deletions
diff --git a/source/blender/blenkernel/intern/verse_session.c b/source/blender/blenkernel/intern/verse_session.c index 1b10a35c364..288bfd01a9d 100644 --- a/source/blender/blenkernel/intern/verse_session.c +++ b/source/blender/blenkernel/intern/verse_session.c @@ -39,6 +39,7 @@ #include "BLI_dynamiclist.h" #include "BLI_blenlib.h" +#include "BIF_screen.h" #include "BIF_verse.h" #include "BKE_global.h" diff --git a/source/blender/python/api2_2x/Bone.c b/source/blender/python/api2_2x/Bone.c index 0d4c0983a67..cd2e3bea099 100644 --- a/source/blender/python/api2_2x/Bone.c +++ b/source/blender/python/api2_2x/Bone.c @@ -910,16 +910,12 @@ static PyObject *Bone_hasChildren(BPy_Bone *self) //-------------------------Bone.getAllChildren() static PyObject *Bone_getAllChildren(BPy_Bone *self) { - PyObject *list = NULL; + PyObject *list = PyList_New(0); - if (self->bone->childbase.first){ - list = PyList_New(0); + if (self->bone->childbase.first) if (!PyBone_ChildrenAsList(list, &self->bone->childbase)) return NULL; - return EXPP_incr_ret(list); - }else{ - return EXPP_incr_ret(Py_None); - } + EXPP_incr_ret(list); } //------------------ATTRIBUTE IMPLEMENTATIONS----------------------------- //------------------------Bone.name (get) @@ -1077,12 +1073,11 @@ static int Bone_setParent(BPy_Bone *self, PyObject *value, void *closure) //------------------------Bone.children (get) static PyObject *Bone_getChildren(BPy_Bone *self, void *closure) { - PyObject *list = NULL; + PyObject *list = PyList_New(0); Bone *bone = NULL; PyObject *py_bone = NULL; if (self->bone->childbase.first){ - list = PyList_New(0); for (bone = self->bone->childbase.first; bone; bone = bone->next){ py_bone = PyBone_FromBone(bone); if (py_bone == NULL) @@ -1091,11 +1086,9 @@ static PyObject *Bone_getChildren(BPy_Bone *self, void *closure) goto RuntimeError; } } - return EXPP_incr_ret(list); - }else{ - return EXPP_incr_ret(Py_None); } - + return EXPP_incr_ret(list); + RuntimeError: return EXPP_objError(PyExc_RuntimeError, "%s%s", sBoneError, "Internal error trying to wrap blender bones!"); diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c index 8baf44ef356..7dbcf79a70c 100644 --- a/source/blender/python/api2_2x/Draw.c +++ b/source/blender/python/api2_2x/Draw.c @@ -45,7 +45,9 @@ #include "BKE_image.h" #include "BKE_object.h" #include "BKE_main.h" +#include "BKE_utildefines.h" #include "BIF_gl.h" +#include "BIF_mywindow.h" #include "BIF_screen.h" #include "BIF_space.h" #include "BIF_interface.h" @@ -733,14 +735,66 @@ void BPY_spacescript_do_pywin_event( SpaceScript * sc, unsigned short event, } } -static void exec_but_callback(PyObject *callback, int event) +static void exec_but_callback(PyObject *callback, uiBut *but) { PyObject *result; - + PyObject * pyvalue; + PyObject *arg = PyTuple_New( 2 ); + + double value = ui_get_but_val(but); + if (callback==NULL || callback == Py_None) return; - - result = PyObject_CallObject( callback, Py_BuildValue( "(i)", event ) ); + + /* Button types support + case MENU: + case TEX: + case TOG: + case NUMSLI: + case NUM: + case COL: + case BUT_NORMAL: + case BUT */ + switch (but->type) { + case TEX: + /*printf("TEX\n");*/ + pyvalue = PyString_FromString( (char *)but->poin ); + break; + case NUM: + case NUMSLI: + case TOG: + case MENU: + if (but->pointype==FLO) { + /*printf("FLO\n");*/ + pyvalue = PyFloat_FromDouble( (float)value ); + } else if (but->pointype==INT) { + /*printf("INT\n");*/ + pyvalue = PyInt_FromLong( (int)value ); + } else if (but->pointype==SHO) { + /*printf("SHO\n");*/ + pyvalue = PyInt_FromLong( (short)value ); + } + break; + case COL: + case BUT_NORMAL: + { + float vec[3]; + VECCOPY(vec, (float *)but->poin); + pyvalue = Py_BuildValue("(fff)", vec[0], vec[1], vec[2]); + break; + } + case BUT: + pyvalue = Py_None; + break; + default: + pyvalue = Py_None; + printf("Error, no button type matched."); + } + + PyTuple_SetItem( arg, 0, PyInt_FromLong(but->retval - EXPP_BUTTON_EVENTS_OFFSET) ); + PyTuple_SetItem( arg, 1, pyvalue ); + + result = PyObject_CallObject( callback, arg ); if (!result) { PyErr_Print( ); error( "Python script error: check console" ); @@ -748,10 +802,10 @@ static void exec_but_callback(PyObject *callback, int event) Py_XDECREF( result ); } -static void set_pycallback(uiBut *ubut, PyObject *callback, int event) +static void set_pycallback(uiBut *ubut, PyObject *callback) { if (!callback || !PyCallable_Check(callback)) return; - uiButSetFunc(ubut, exec_but_callback, callback, event); + uiButSetFunc(ubut, exec_but_callback, callback, ubut); } static PyObject *Method_Exit( PyObject * self, PyObject * args ) @@ -764,7 +818,7 @@ static PyObject *Method_Exit( PyObject * self, PyObject * args ) if( curarea->spacetype == SPACE_SCRIPT ) sc = curarea->spacedata.first; else - return EXPP_incr_ret( Py_None ); + Py_RETURN_NONE; if( !PyArg_ParseTuple( args, "" ) ) return EXPP_ReturnPyObjError( PyExc_AttributeError, @@ -777,7 +831,7 @@ static PyObject *Method_Exit( PyObject * self, PyObject * args ) /* remove our lock to the current namespace */ script->flags &= ~SCRIPT_GUI; - return EXPP_incr_ret( Py_None ); + Py_RETURN_NONE; } /* Method_Register (Draw.Register) registers callbacks for drawing, events @@ -805,7 +859,7 @@ static PyObject *Method_Register( PyObject * self, PyObject * args ) newbuttonc = NULL; if( !( newdrawc || neweventc || newbuttonc ) ) - return EXPP_incr_ret( Py_None ); + Py_RETURN_NONE; startspace = curarea->spacetype; @@ -865,7 +919,7 @@ static PyObject *Method_Register( PyObject * self, PyObject * args ) scrarea_queue_redraw( sc->area ); - return EXPP_incr_ret( Py_None ); + Py_RETURN_NONE; } static PyObject *Method_Redraw( PyObject * self, PyObject * args ) @@ -881,7 +935,7 @@ static PyObject *Method_Redraw( PyObject * self, PyObject * args ) else scrarea_queue_winredraw( curarea ); - return EXPP_incr_ret( Py_None ); + Py_RETURN_NONE; } static PyObject *Method_Draw( PyObject * self, PyObject * args ) @@ -889,7 +943,7 @@ 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 ); + Py_RETURN_NONE; } if( !PyArg_ParseTuple( args, "" ) ) @@ -900,7 +954,7 @@ static PyObject *Method_Draw( PyObject * self, PyObject * args ) screen_swapbuffers( ); - return EXPP_incr_ret( Py_None ); + Py_RETURN_NONE; } static PyObject *Method_Create( PyObject * self, PyObject * args ) @@ -1017,7 +1071,7 @@ static PyObject *Method_BeginAlign( PyObject * self, PyObject * args ) if (block) uiBlockBeginAlign(block); - return EXPP_incr_ret( Py_None ); + Py_RETURN_NONE; } static PyObject *Method_EndAlign( PyObject * self, PyObject * args ) @@ -1027,7 +1081,7 @@ static PyObject *Method_EndAlign( PyObject * self, PyObject * args ) if (block) uiBlockEndAlign(block); - return EXPP_incr_ret( Py_None ); + Py_RETURN_NONE; } static PyObject *Method_Button( PyObject * self, PyObject * args ) @@ -1048,9 +1102,9 @@ static PyObject *Method_Button( PyObject * self, PyObject * args ) 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); + set_pycallback(ubut, callback); } - return EXPP_incr_ret( Py_None ); + Py_RETURN_NONE; } static PyObject *Method_Menu( PyObject * self, PyObject * args ) @@ -1077,7 +1131,7 @@ static PyObject *Method_Menu( PyObject * self, PyObject * args ) 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); + set_pycallback(ubut, callback); } return ( PyObject * ) but; } @@ -1106,7 +1160,7 @@ static PyObject *Method_Toggle( PyObject * self, PyObject * args ) 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); + set_pycallback(ubut, callback); } return ( PyObject * ) but; } @@ -1185,8 +1239,9 @@ static PyObject *Method_Slider( PyObject * self, PyObject * args ) (short)h, &but->val.asfloat, min, 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); } } else { int ini, min, max; @@ -1207,7 +1262,7 @@ static PyObject *Method_Slider( PyObject * self, PyObject * args ) if( realtime ) uiButSetFunc( ubut, py_slider_update, ubut, NULL ); else - set_pycallback(ubut, callback, event); + set_pycallback(ubut, callback); } } return ( PyObject * ) but; @@ -1311,7 +1366,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); + set_pycallback(ubut, callback); } return ( PyObject * ) but; @@ -1355,7 +1410,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); + set_pycallback(ubut, callback); } return ( PyObject * ) but; @@ -1421,7 +1476,7 @@ static PyObject *Method_Number( PyObject * self, PyObject * args ) &but->val.asint, (float)min, (float)max, 0, 0, tip ); } - if (ubut) set_pycallback(ubut, callback, event); + if (ubut) set_pycallback(ubut, callback); return ( PyObject * ) but; } @@ -1466,7 +1521,7 @@ static PyObject *Method_String( PyObject * self, PyObject * args ) 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); + set_pycallback(ubut, callback); } return ( PyObject * ) but; } diff --git a/source/blender/python/api2_2x/doc/Draw.py b/source/blender/python/api2_2x/doc/Draw.py index 6e9a0ae572c..3b8a0d02eae 100644 --- a/source/blender/python/api2_2x/doc/Draw.py +++ b/source/blender/python/api2_2x/doc/Draw.py @@ -204,14 +204,14 @@ have been caused by an ignored return value from one of the button types. To avoid this, assign created buttons return values to B{global} variables, instead of ignoring them. Examples:: - # avoid this, it can cause memory leaks: - Draw.Toggle(...) - Draw.Number(...) - Draw.String(...) - # this is correct -- assuming the variables are globals: - my_toggle_button = Draw.Toggle(...) - my_int_button = Draw.Number(...) - my_str_button = Draw.String(...) + # avoid this, it can cause memory leaks: + Draw.Toggle(...) + Draw.Number(...) + Draw.String(...) + # this is correct -- assuming the variables are globals: + my_toggle_button = Draw.Toggle(...) + my_int_button = Draw.Number(...) + my_str_button = Draw.String(...) @warn: Inside the windowing loop (after Draw.Register() has been executed and @@ -320,7 +320,7 @@ def PushButton(name, event, x, y, width, height, tooltip = None, callback = None @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. + This function must accept 2 arguments (event, val). @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 @@ -521,7 +521,7 @@ def Menu(name, event, x, y, width, height, default, tooltip = None, callback = N @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. + This function must accept 2 arguments (event, val). @rtype: Blender Button @return: The Button created. """ @@ -551,7 +551,7 @@ def Toggle(name, event, x, y, width, height, default, tooltip = None, callback = @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. + This function must accept 2 arguments (event, val). @rtype: Blender Button @return: The Button created. """ @@ -589,7 +589,7 @@ def Slider(name, event, x, y, width, height, initial, min, max, realtime = 1, @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. + This function must accept 2 arguments (event, val). @rtype: Blender Button @return: The Button created. @note: slider callbacks will not work if the realtime setting is enabled. @@ -648,7 +648,7 @@ def ColorPicker(event, x, y, width, height, initial, tooltip = None, callback = @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. + This function must accept 2 arguments (event, val). @rtype: Blender Button @return: The Button created. @note: The color picker will not work if the Register's event function is None. @@ -677,7 +677,7 @@ def Normal(event, x, y, width, height, initial, tooltip = None, callback = None) @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. + This function must accept 2 arguments (event, val). @rtype: Blender Button @return: The Button created. @note: The normal button will not work if the Register's event function is None. @@ -712,7 +712,7 @@ def Number(name, event, x, y, width, height, initial, min, max, tooltip = None, @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. + This function must accept 2 arguments (event, val). @rtype: Blender Button @return: The Button created. @@ -757,7 +757,7 @@ def String(name, event, x, y, width, height, initial, length, tooltip = None, ca @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. + This function must accept 2 arguments (event, val). @rtype: Blender Button @return: The Button created. """ diff --git a/source/blender/src/buttons_logic.c b/source/blender/src/buttons_logic.c index 1a1d7828ef0..ee1b5737410 100644 --- a/source/blender/src/buttons_logic.c +++ b/source/blender/src/buttons_logic.c @@ -81,6 +81,7 @@ #include "BDR_editcurve.h" +#include "BDR_editobject.h" #include "BSE_headerbuttons.h" #include "BSE_filesel.h" diff --git a/source/blender/src/editface.c b/source/blender/src/editface.c index 895a081a18a..2c14e53eff8 100644 --- a/source/blender/src/editface.c +++ b/source/blender/src/editface.c @@ -95,6 +95,7 @@ #include "BSE_trans_types.h" #include "BDR_unwrapper.h" +#include "BDR_editobject.h" #include "BPY_extern.h" #include "BPY_menus.h" |