python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator. Python functions for invoke and exec can be registered with an operator name. keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults. def exec(size=2.0, text="blah"): ... is equivalent to... prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE); RNA_def_property_float_default(prop, 2.0f); prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE); RNA_def_property_string_default(prop, "blah"); TODO - * make use of events * return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc * add support for array args * more testing
This commit is contained in:
@@ -120,6 +120,8 @@ void WM_operator_free (struct wmOperator *op);
|
||||
wmOperatorType *WM_operatortype_find(const char *idname);
|
||||
wmOperatorType *WM_operatortype_first(void);
|
||||
void WM_operatortype_append (void (*opfunc)(wmOperatorType*));
|
||||
void WM_operatortype_append_ptr (void (*opfunc)(wmOperatorType*, void *), void *userdata);
|
||||
int WM_operatortype_remove(const char *idname);
|
||||
|
||||
int WM_operator_call (struct bContext *C, struct wmOperator *op);
|
||||
int WM_operator_name_call (struct bContext *C, const char *opstring, int context, struct IDProperty *properties);
|
||||
|
||||
@@ -96,6 +96,32 @@ void WM_operatortype_append(void (*opfunc)(wmOperatorType*))
|
||||
BLI_addtail(&global_ops, ot);
|
||||
}
|
||||
|
||||
void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType*, void*), void *userdata)
|
||||
{
|
||||
wmOperatorType *ot;
|
||||
|
||||
ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
|
||||
ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
|
||||
opfunc(ot, userdata);
|
||||
RNA_def_struct_ui_text(ot->srna, ot->name, "DOC_BROKEN"); /* TODO - add a discription to wmOperatorType? */
|
||||
RNA_def_struct_identifier(ot->srna, ot->idname);
|
||||
BLI_addtail(&global_ops, ot);
|
||||
}
|
||||
|
||||
int WM_operatortype_remove(const char *idname)
|
||||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(idname);
|
||||
|
||||
if (ot==NULL)
|
||||
return 0;
|
||||
|
||||
BLI_remlink(&global_ops, ot);
|
||||
RNA_struct_free(&BLENDER_RNA, ot->srna);
|
||||
MEM_freeN(ot);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* print a string representation of the operator, with the args that it runs
|
||||
* so python can run it again */
|
||||
char *WM_operator_pystring(wmOperator *op)
|
||||
|
||||
Reference in New Issue
Block a user