[Bf-python] Python Dialogs

Campbell Barton cbarton at metavr.com
Sat Mar 17 14:48:55 CET 2007


Hi, Iv just managed to get a python popup dialog working.

before people jump to say that blender shouldnt do dialogs, take note 
that this is similar to the color picker, game framing settings and a 
good replacement for PupBlock popup at times.

Iv called Draw.UIBlock() and it works like this...


val = Create(10)
val = Create(0.1)
def draw():
	val = Draw.Number...
	val2 = Draw... etc


Draw.UIBlock(draw, x,y)



The annoying thing about it is that I cant get it to support a button 
event function - (function that runs when a button is pressed)

Its a bit of a hack to get it working but I tried realy hard to make it 
worth without using a while loop and the UI block would always exit when 
anything was clicked on...

The upshot is that even though theres no button event functions, draw() 
will be called each time a button is clicked, so its possible to have a 
UI that has things like tabs or menu's that change other areas of the 
UI... a basic file chooser would be possible though I dont recommend that.

Feedback welcome...

Heres the function, neither ret or event are set to the button event.
PyObject_CallObject needs to check for exceptios too..


static PyObject *Method_UIBlock( PyObject * self, PyObject * args )
{
	PyObject *val;
	int w,h;
	PyObject *result;
	ListBase listb= {NULL, NULL};
	
	int ret, event;
	
	if ( !PyArg_ParseTuple( args, "Oii", &val, &w, &h ) || 
!PyCallable_Check( val ) )
		return EXPP_ReturnPyObjError( PyExc_AttributeError,
					      "expected 1 python function and 2 ints" );
	
	mywinset(G.curscreen->mainwin);
	
	while (1) {
		event = 0;
		uiFreeBlocks(&listb);
		uiblock= uiNewBlock(&listb, "numbuts", UI_EMBOSS, UI_HELV, 
G.curscreen->mainwin);
		uiBlockSetFlag(uiblock, 
UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_ENTER_OK);
		result = PyObject_CallObject( val, Py_BuildValue( "()" ) );
		uiBoundsBlock(uiblock, 5);
		ret = uiDoBlocks(&listb, event);
		printf("event %i\n", event);
		printf("ret %i\n", ret);
		if (ret == UI_RETURN_OUT)
			break;
	}
	
	uiblock = NULL;
	Py_RETURN_NONE;
}






More information about the Bf-python mailing list