Clicking on the arrows of a python float button did not change the value :/ - (Click step was zero) Fixed in Draw.c

Added a comment to interface.c on how a1 and a2 are used with float buttons.
Added an example to Draw.py epydocs of a script using a float button.
This commit is contained in:
2006-06-05 01:23:56 +00:00
parent 233348197e
commit ce202f7540
3 changed files with 34 additions and 3 deletions

View File

@@ -1137,19 +1137,28 @@ static PyObject *Method_Number( PyObject * self, PyObject * args )
but = newbutton( );
if( PyFloat_Check( inio ) ) {
float ini, min, max;
float ini, min, max, range, precission=0;
ini = (float)PyFloat_AsDouble( inio );
min = (float)PyFloat_AsDouble( mino );
max = (float)PyFloat_AsDouble( maxo );
range= 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>=100.0f) precission=1.0f;
else if (range>=10.0f) precission=2.0f;
else if (range>1.0f) precission=3.0f;
else precission=4.0f;
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,
&but->val.asfloat, min, max, 0, 0, tip );
&but->val.asfloat, min, max, 10*range, precission, tip );
} else {
int ini, min, max;

View File

@@ -631,6 +631,19 @@ def Number(name, event, x, y, width, height, initial, min, max, tooltip = None):
is kept over the button).
@rtype: Blender Button
@return: The Button created.
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')
Draw.Register(gui, None, bevent) # we are not going to worry about keyboard and mouse events
"""