added an option for python Draw.UIBlock(func, mouse_exit) so moving the mouse outside the popup wont close it.
Stops FBX Export and OBJ I/O from flickering a lot.
This commit is contained in:
@@ -2952,7 +2952,7 @@ def write_ui():
|
||||
#fbx_ui_write('/test.fbx')
|
||||
break
|
||||
|
||||
Draw.UIBlock(fbx_ui)
|
||||
Draw.UIBlock(fbx_ui, 0)
|
||||
|
||||
|
||||
# GLOBALS.clear()
|
||||
|
||||
@@ -694,7 +694,7 @@ def write_ui(filename):
|
||||
|
||||
# hack so the toggle buttons redraw. this is not nice at all
|
||||
while GLOBALS['EVENT'] not in (EVENT_EXIT, EVENT_EXPORT):
|
||||
Draw.UIBlock(obj_ui)
|
||||
Draw.UIBlock(obj_ui, 0)
|
||||
|
||||
if GLOBALS['EVENT'] != EVENT_EXPORT:
|
||||
return
|
||||
|
||||
@@ -878,7 +878,7 @@ def load_obj_ui(filepath, BATCH_LOAD= False):
|
||||
|
||||
# hack so the toggle buttons redraw. this is not nice at all
|
||||
while GLOBALS['EVENT'] not in (EVENT_EXIT, EVENT_IMPORT):
|
||||
Draw.UIBlock(obj_ui)
|
||||
Draw.UIBlock(obj_ui, 0)
|
||||
|
||||
if GLOBALS['EVENT'] != EVENT_IMPORT:
|
||||
return
|
||||
|
||||
@@ -216,7 +216,7 @@ def main():
|
||||
|
||||
# hack so the toggle buttons redraw. this is not nice at all
|
||||
while GLOBALS['EVENT'] == EVENT_REDRAW:
|
||||
Draw.UIBlock(terain_clamp_ui)
|
||||
Draw.UIBlock(terain_clamp_ui, 0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -141,7 +141,7 @@ static uiBlock *uiblock=NULL;
|
||||
|
||||
static char Draw_doc[] = "The Blender.Draw submodule";
|
||||
|
||||
static char Method_UIBlock_doc[] = "(drawfunc, x,y) - Popup dialog where buttons can be drawn (expemental)";
|
||||
static char Method_UIBlock_doc[] = "(drawfunc, mouse_exit) - Popup dialog where buttons can be drawn (expemental)";
|
||||
|
||||
static char Method_Register_doc[] =
|
||||
"(draw, event, button) - Register callbacks for windowing\n\n\
|
||||
@@ -290,9 +290,9 @@ static char Method_Text_doc[] =
|
||||
This function returns the width of the drawn string.";
|
||||
|
||||
static char Method_Label_doc[] =
|
||||
"(text, x, y) - Draw a text label onscreen\n\n\
|
||||
"(text, x, y, w, h, tip, callback) - Draw a text label onscreen\n\n\
|
||||
(text) The text to draw\n\
|
||||
(x, y) The lower left coordinate of the lable";
|
||||
(x, y, w, h) The lower left coordinate of the lable, width and height";
|
||||
|
||||
static char Method_PupMenu_doc[] =
|
||||
"(string, maxrow = None) - Display a pop-up menu at the screen.\n\
|
||||
@@ -1101,15 +1101,16 @@ static PyObject *Method_UIBlock( PyObject * self, PyObject * args )
|
||||
PyObject *val = NULL;
|
||||
PyObject *result = NULL;
|
||||
ListBase listb= {NULL, NULL};
|
||||
int mouse_exit = 1;
|
||||
|
||||
if (G.background) {
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"Can't run Draw.UIBlock() in background mode." );
|
||||
}
|
||||
|
||||
if ( !PyArg_ParseTuple( args, "O", &val ) || !PyCallable_Check( val ) )
|
||||
if ( !PyArg_ParseTuple( args, "O|i", &val, &mouse_exit ) || !PyCallable_Check( val ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"expected 1 python function and 2 ints" );
|
||||
"expected 1 python function and an optional int" );
|
||||
|
||||
if (uiblock)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
@@ -1121,7 +1122,7 @@ static PyObject *Method_UIBlock( PyObject * self, PyObject * args )
|
||||
uiblock= uiNewBlock(&listb, "numbuts", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
|
||||
|
||||
uiBlockSetFlag(uiblock, UI_BLOCK_LOOP|UI_BLOCK_REDRAW);
|
||||
result = PyObject_CallObject( val, Py_BuildValue( "()" ) );
|
||||
result = PyObject_CallObject( val, NULL );
|
||||
|
||||
if (!result) {
|
||||
PyErr_Print( );
|
||||
@@ -1146,7 +1147,7 @@ static PyObject *Method_UIBlock( PyObject * self, PyObject * args )
|
||||
/* Done clearing events */
|
||||
|
||||
uiBoundsBlock(uiblock, 5);
|
||||
uiDoBlocks(&listb, 0, 1);
|
||||
uiDoBlocks(&listb, 0, mouse_exit);
|
||||
}
|
||||
uiFreeBlocks(&listb);
|
||||
uiblock = NULL;
|
||||
|
||||
@@ -235,19 +235,21 @@ def EndAlign():
|
||||
Use after BeginAlign() to stop aligning the buttons (button layout only).
|
||||
"""
|
||||
|
||||
def UIBlock(draw):
|
||||
def UIBlock(draw, mouse_exit=1):
|
||||
"""
|
||||
This function creates a popup area where buttons, labels, sliders etc can be drawn.
|
||||
|
||||
@type mouse_exit: int
|
||||
@param mouse_exit: When zero the popup wont close when the mouse moves away from the popup.
|
||||
@type draw: function
|
||||
@param draw: A function to draw to the popup area, taking no arguments: draw().
|
||||
|
||||
@note: The size of the popup will expand to fit the bounds of the buttons created in the draw function.
|
||||
@note: Be sure to use the mouse coordinates to position the buttons under the mouse,
|
||||
@note: If mouse_exit is nonzero be sure to use the mouse coordinates if to position the buttons under the mouse,
|
||||
so the popup dosn't exit as soon as it opens.
|
||||
The coordinates for buttons start 0,0 at the bottom left hand side of the screen.
|
||||
@note: Within this popup, Redraw events and the registered button callback will not work.
|
||||
For buttons to run events, use per button callbacks.
|
||||
For buttons to run events, use per button callbacks instead.
|
||||
@note: OpenGL drawing functions wont work within this popup, for text use L{Label} rather then L{Text}
|
||||
@warning: L{Menu} will not work properly within a UIBlock, this is a limitation with blenders user interface internals.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user