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-26 06:56:52 +0300
committerCampbell Barton <ideasman42@gmail.com>2008-12-26 06:56:52 +0300
commit0054e6d354f1b38a0788cc7716c52f07b16dd895 (patch)
treed1291cb9670e579ba41d128211ec505755b0f030 /source/blender/windowmanager
parent27d0394ba47fdc6c65ec2f3920b52c64264879c2 (diff)
* added RNA_property_as_string to rna_access.c - can print most types except for pointers and collections.
* WM_operator_pystring to print the python func+args for an operator * call WM_operator_print(op) in wm_operator_invoke(), simple echo mode should be moved later.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h3
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c14
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c43
3 files changed, 58 insertions, 2 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 3a550c75d59..1fe9da8b06c 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -124,6 +124,9 @@ void WM_operatortype_append (void (*opfunc)(wmOperatorType*));
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);
+/* operator as a python command (resultuing string must be free'd) */
+char *WM_operator_pystring(struct wmOperator *op);
+
/* default operator callbacks for border/circle/lasso */
int WM_border_select_invoke (struct bContext *C, wmOperator *op, struct wmEvent *event);
int WM_border_select_modal (struct bContext *C, wmOperator *op, struct wmEvent *event);
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 1342ebf78b9..e74cb9b573e 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -277,6 +277,13 @@ void wm_draw_update(bContext *C)
/* ********************* operators ******************* */
+static void WM_operator_print(wmOperator *op)
+{
+ char *buf = WM_operator_pystring(op);
+ printf("%s\n", buf);
+ MEM_freeN(buf);
+}
+
/* for running operators with frozen context (modal handlers, menus) */
int WM_operator_call(bContext *C, wmOperator *op)
{
@@ -289,8 +296,8 @@ int WM_operator_call(bContext *C, wmOperator *op)
wm_operator_register(CTX_wm_manager(C), op);
}
else
- WM_operator_free(op);
-
+ WM_operator_free(op);
+
return retval;
}
@@ -317,6 +324,9 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, I
else if(op->type->exec)
retval= op->type->exec(C, op);
+ /* only for testing, can remove any time */
+ WM_operator_print(op);
+
if((retval & OPERATOR_FINISHED) && (ot->flag & OPTYPE_REGISTER)) {
wm_operator_register(wm, op);
}
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index a446ddb9e82..34b7cb02122 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -36,6 +36,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
+#include "BLI_dynstr.h" /*for WM_operator_pystring */
#include "BKE_blender.h"
#include "BKE_context.h"
@@ -95,6 +96,48 @@ void WM_operatortype_append(void (*opfunc)(wmOperatorType*))
BLI_addtail(&global_ops, ot);
}
+/* 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)
+{
+ const char *arg_name= NULL;
+
+ PropertyRNA *prop, *iterprop;
+ CollectionPropertyIterator iter;
+
+ /* for building the string */
+ DynStr *dynstr= BLI_dynstr_new();
+ char *cstring, *buf;
+ int first_iter=1;
+
+ BLI_dynstr_appendf(dynstr, "%s(", op->idname);
+
+ iterprop= RNA_struct_iterator_property(op->ptr);
+ RNA_property_collection_begin(op->ptr, iterprop, &iter);
+
+ for(; iter.valid; RNA_property_collection_next(&iter)) {
+ prop= iter.ptr.data;
+ arg_name= RNA_property_identifier(&iter.ptr, prop);
+
+ if (strcmp(arg_name, "rna_type")==0) continue;
+
+ buf= RNA_property_as_string(op->ptr, prop);
+
+ BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
+
+ MEM_freeN(buf);
+ first_iter = 0;
+ }
+
+ RNA_property_collection_end(&iter);
+
+ BLI_dynstr_append(dynstr, ")");
+
+ cstring = BLI_dynstr_get_cstring(dynstr);
+ BLI_dynstr_free(dynstr);
+ return cstring;
+}
+
/* ************ default op callbacks, exported *********** */
/* invoke callback, uses enum property named "type" */