From d1248ff6d8276d6a9566bb21f0ba2081e863b271 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Sat, 8 Nov 2008 13:38:21 +0000 Subject: === BPy API === * add two optional arguments to control click step and precision of Number buttons. --- source/blender/python/api2_2x/Draw.c | 47 ++++++++++++++++++++++--------- source/blender/python/api2_2x/doc/Draw.py | 7 ++++- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c index e0111f099aa..ffd2b1038fd 100644 --- a/source/blender/python/api2_2x/Draw.c +++ b/source/blender/python/api2_2x/Draw.c @@ -258,7 +258,7 @@ Normal button (a sphere that you can roll to change the normal)\n\n\ [tooltip=] The button's tooltip"; static char Method_Number_doc[] = - "(name, event, x, y, width, height, initial, min, max, [tooltip]) - Create a \ + "(name, event, x, y, width, height, initial, min, max, [tooltip], [callback], [range], [precision]) - Create a \ new Number button\n\n\ (name) A string to display on the button\n\ (event) The event number to pass to the button event function when activated\n\ @@ -266,7 +266,10 @@ new Number button\n\n\ (width, height) The button width and height\n\ (initial, min, max) Three values (int or float) specifying the initial and \ limit values.\n\ -[tooltip=] The button's tooltip"; +[tooltip=] The button's tooltip\n\ +[callback=] The button's callback\n\ +[clickstep=] Click step for the button\n\ +[precision=] How many decimal places to maintain, if not given, it is calculated depending on range, otherwise 1,2,3 or 4. Larger values are clamped to 4"; static char Method_String_doc[] = "(name, event, x, y, width, height, initial, length, [tooltip]) - Create a \ @@ -1600,6 +1603,8 @@ static PyObject *Method_Number( PyObject * self, PyObject * args ) Button *but; PyObject *mino, *maxo, *inio; PyObject *callback=NULL; + PyObject *a1=NULL; + PyObject *a2=NULL; uiBut *ubut= NULL; if (G.background) { @@ -1607,11 +1612,11 @@ static PyObject *Method_Number( PyObject * self, PyObject * args ) "Can't run Draw.Number() in background mode." ); } - if( !PyArg_ParseTuple( args, "siiiiiOOO|sO", &name, &event, - &x, &y, &w, &h, &inio, &mino, &maxo, &tip, &callback ) ) + if( !PyArg_ParseTuple( args, "siiiiiOOO|sOOO", &name, &event, + &x, &y, &w, &h, &inio, &mino, &maxo, &tip, &callback, &a1, &a2 ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, "expected a string, five ints, three PyObjects and\n\ - optionally string and callback arguments" ); + optionally string, callback, range and precision arguments" ); UI_METHOD_ERRORCHECK; @@ -1632,14 +1637,30 @@ static PyObject *Method_Number( PyObject * self, PyObject * args ) min = (float)PyFloat_AsDouble( mino ); max = (float)PyFloat_AsDouble( maxo ); - range= (float)fabs(max-min); /* Click step will be a 10th of the range. */ - if (!range) range= 1.0f; /* avoid any odd errors */ + if(a1 && PyNumber_Check(a1)) { + if(PyFloat_Check(a1)) + range= (float)PyFloat_AsDouble(a1); + else + range= (float)PyInt_AsLong(a1); + } else { + range= (float)fabs(max-min); /* Click step will be a 10th of the range. */ + if (!range) range= 1.0f; /* avoid any odd errors */ + } - /* set the precission to display*/ - if (range>=1000.0f) precission=1.0f; - else if (range>=100.0f) precission=2.0f; - else if (range>=10.0f) precission=3.0f; - else precission=4.0f; + if(a2 && PyNumber_Check(a2)) { + if(PyFloat_Check(a2)) + precission= (float)PyFloat_AsDouble(a2); + else + precission= (float)PyInt_AsLong(a2); + } else { + /* set the precission to display*/ + if (range>=1000.0f) precission=1.0f; + else if (range>=100.0f) precission=2.0f; + else if (range>=10.0f) precission=3.0f; + else precission=4.0f; + + range *= 10; + } but->type = BFLOAT_TYPE; but->val.asfloat = ini; @@ -1647,7 +1668,7 @@ static PyObject *Method_Number( PyObject * self, PyObject * args ) if( block ) ubut= uiDefButF( block, NUM, event, name, (short)x, (short)y, (short)w, (short)h, - &but->val.asfloat, min, max, 10*range, precission, but->tooltip ); + &but->val.asfloat, min, max, range, precission, but->tooltip ); } else { int ini, min, max; diff --git a/source/blender/python/api2_2x/doc/Draw.py b/source/blender/python/api2_2x/doc/Draw.py index 127f37bfbad..98e92196f8d 100644 --- a/source/blender/python/api2_2x/doc/Draw.py +++ b/source/blender/python/api2_2x/doc/Draw.py @@ -706,7 +706,7 @@ def Normal(event, x, y, width, height, initial, tooltip = None, callback = 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, callback = None): +def Number(name, event, x, y, width, height, initial, min, max, tooltip = None, callback = None, clickstep = None, precision = None): """ Create a new Number Button object. @type name: string @@ -735,6 +735,11 @@ def Number(name, event, x, y, width, height, initial, min, max, tooltip = None, @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 2 arguments (event, val). + @type clickstep: float + @param clickstep: an optional argument to control the amount of change per click on the button. + @type precision: float + @param precision: an optional argument to control the amount of places after the decimal. From 1 to 4 places with 1.0..4.0. + Larger values are clamped to 4 places. @rtype: Blender Button @return: The Button created. -- cgit v1.2.3