Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-12-27 17:52:49 +0300
committerCampbell Barton <ideasman42@gmail.com>2008-12-27 17:52:49 +0300
commit0714d28236e66b258de90bcbb8a1a821ee424a71 (patch)
treef7b99bdec9e093e0e2ecf1b00229f37d1ca2687c /source/blender/windowmanager
parent86886cbc55c036af44833fd861cfd276fbec256a (diff)
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
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h2
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c26
2 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index be1297880f6..75b3d5316fd 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -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);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 34b7cb02122..e29741e4d02 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -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)