modal python operator support.
This commit is contained in:
@@ -683,6 +683,31 @@ static int operator_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* same as invoke */
|
||||
static int operator_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
{
|
||||
PointerRNA opr;
|
||||
ParameterList list;
|
||||
FunctionRNA *func;
|
||||
void *ret;
|
||||
int result;
|
||||
|
||||
RNA_pointer_create(&CTX_wm_screen(C)->id, op->type->ext.srna, op, &opr);
|
||||
func= RNA_struct_find_function(&opr, "modal");
|
||||
|
||||
RNA_parameter_list_create(&list, &opr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
RNA_parameter_set_lookup(&list, "event", &event);
|
||||
op->type->ext.call(&opr, func, &list);
|
||||
|
||||
RNA_parameter_get_lookup(&list, "result", &ret);
|
||||
result= *(int*)ret;
|
||||
|
||||
RNA_parameter_list_free(&list);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void operator_draw(bContext *C, wmOperator *op)
|
||||
{
|
||||
PointerRNA opr;
|
||||
@@ -711,7 +736,7 @@ static StructRNA *rna_Operator_register(const bContext *C, ReportList *reports,
|
||||
wmOperatorType dummyot = {0};
|
||||
wmOperator dummyop= {0};
|
||||
PointerRNA dummyotr;
|
||||
int have_function[4];
|
||||
int have_function[5];
|
||||
|
||||
/* setup dummy operator & operator type to store static properties in */
|
||||
dummyop.type= &dummyot;
|
||||
@@ -762,7 +787,8 @@ static StructRNA *rna_Operator_register(const bContext *C, ReportList *reports,
|
||||
dummyot.pyop_poll= (have_function[0])? operator_poll: NULL;
|
||||
dummyot.exec= (have_function[1])? operator_exec: NULL;
|
||||
dummyot.invoke= (have_function[2])? operator_invoke: NULL;
|
||||
dummyot.ui= (have_function[3])? operator_draw: NULL;
|
||||
dummyot.modal= (have_function[3])? operator_modal: NULL;
|
||||
dummyot.ui= (have_function[4])? operator_draw: NULL;
|
||||
|
||||
WM_operatortype_append_ptr(operator_wrapper, (void *)&dummyot);
|
||||
|
||||
|
||||
@@ -151,6 +151,11 @@ static void rna_Operator_enum_search_invoke(bContext *C, wmOperator *op)
|
||||
|
||||
}
|
||||
|
||||
static int rna_event_add_modal_handler(struct bContext *C, struct wmOperator *operator)
|
||||
{
|
||||
return WM_event_add_modal_handler(C, operator) != NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void rna_generic_op_invoke(FunctionRNA *func, int use_event, int use_ret)
|
||||
@@ -192,6 +197,12 @@ void RNA_api_wm(StructRNA *srna)
|
||||
parm= RNA_def_pointer(func, "keyconfig", "KeyConfig", "Key Configuration", "Removed key configuration.");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
|
||||
func= RNA_def_function(srna, "add_modal_handler", "rna_event_add_modal_handler");
|
||||
RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
|
||||
parm= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call.");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
RNA_def_function_return(func, RNA_def_boolean(func, "handle", 1, "", ""));
|
||||
|
||||
/* invoke functions, for use with python */
|
||||
func= RNA_def_function(srna, "invoke_props_popup", "WM_operator_props_popup");
|
||||
RNA_def_function_ui_description(func, "Operator popup invoke.");
|
||||
@@ -252,6 +263,16 @@ void RNA_api_operator(StructRNA *srna)
|
||||
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
func= RNA_def_function(srna, "modal", NULL); /* same as invoke */
|
||||
RNA_def_function_ui_description(func, "Modal operator function.");
|
||||
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
|
||||
RNA_def_pointer(func, "context", "Context", "", "");
|
||||
RNA_def_pointer(func, "event", "Event", "", "");
|
||||
|
||||
parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name?
|
||||
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
/* draw */
|
||||
func= RNA_def_function(srna, "draw", NULL);
|
||||
RNA_def_function_ui_description(func, "Draw function for the operator.");
|
||||
|
||||
Reference in New Issue
Block a user