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>2009-09-04 02:37:09 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-09-04 02:37:09 +0400
commit02f951c3a05f6586f12d129c70adffd8315ec3b7 (patch)
treefea0ba96dffe2ee86a781046c57c52863532f73f /source/blender/windowmanager
parentfc975a91484a1346049071fa9c6c8877820245cd (diff)
allow execution mode to be given as an argument to operators from python (requested by algorith)
example. bpy.ops.tfm.rotate('INVOKE_REGION_WIN', pivot=(0,1,2), ......) bpy_array.c - was too strict with types, 0 should be allowed as well as 0.0 in a float array.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h3
-rw-r--r--source/blender/windowmanager/intern/wm.c2
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c54
3 files changed, 37 insertions, 22 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 0f5558382c4..544804b26d6 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -165,7 +165,7 @@ wmOperatorTypeMacro *WM_operatortype_macro_define(wmOperatorType *ot, const char
int WM_operator_call (struct bContext *C, struct wmOperator *op);
int WM_operator_repeat (struct bContext *C, struct wmOperator *op);
int WM_operator_name_call (struct bContext *C, const char *opstring, int context, struct PointerRNA *properties);
-int WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, struct PointerRNA *properties, struct ReportList *reports);
+int WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, int context, struct PointerRNA *properties, struct ReportList *reports);
void WM_operator_properties_create(struct PointerRNA *ptr, const char *opstring);
void WM_operator_properties_free(struct PointerRNA *ptr);
@@ -245,6 +245,5 @@ void WM_jobs_stop_all(struct wmWindowManager *wm);
char *WM_clipboard_text_get(int selection);
void WM_clipboard_text_set(char *buf, int selection);
-
#endif /* WM_API_H */
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index 85f8a647826..fecd5c20a15 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -69,7 +69,7 @@ void WM_operator_free(wmOperator *op)
MEM_freeN(op->properties);
}
- if(op->reports) {
+ if(op->reports && (op->flag & OPERATOR_REPORT_FREE)) {
BKE_reports_clear(op->reports);
MEM_freeN(op->reports);
}
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 6c34ed6f902..717c2d25261 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -345,11 +345,12 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, P
/* initialize error reports */
if (reports) {
- op->reports= reports; /* must be initialized alredy */
+ op->reports= reports; /* must be initialized already */
}
else {
op->reports= MEM_mallocN(sizeof(ReportList), "wmOperatorReportList");
BKE_reports_init(op->reports, RPT_STORE);
+ op->flag |= OPERATOR_REPORT_FREE;
}
/* recursive filling of operator macro list */
@@ -392,13 +393,13 @@ static void wm_region_mouse_co(bContext *C, wmEvent *event)
}
}
-static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerRNA *properties)
+static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerRNA *properties, ReportList *reports)
{
wmWindowManager *wm= CTX_wm_manager(C);
int retval= OPERATOR_PASS_THROUGH;
if(wm_operator_poll(C, ot)) {
- wmOperator *op= wm_operator_create(wm, ot, properties, NULL);
+ wmOperator *op= wm_operator_create(wm, ot, properties, reports); /* if reports==NULL, theyll be initialized */
if((G.f & G_DEBUG) && event && event->type!=MOUSEMOVE)
printf("handle evt %d win %d op %s\n", event?event->type:0, CTX_wm_screen(C)->subwinactive, ot->idname);
@@ -442,10 +443,12 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P
return retval;
}
-/* invokes operator in context */
-int WM_operator_name_call(bContext *C, const char *opstring, int context, PointerRNA *properties)
+/* WM_operator_name_call is the main accessor function
+ * this is for python to access since its done the operator lookup
+ *
+ * invokes operator in context */
+static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int context, PointerRNA *properties, ReportList *reports)
{
- wmOperatorType *ot= WM_operatortype_find(opstring, 0);
wmWindow *window= CTX_wm_window(C);
wmEvent *event;
@@ -473,7 +476,7 @@ int WM_operator_name_call(bContext *C, const char *opstring, int context, Pointe
CTX_wm_region_set(C, ar1);
}
- retval= wm_operator_invoke(C, ot, event, properties);
+ retval= wm_operator_invoke(C, ot, event, properties, reports);
/* set region back */
CTX_wm_region_set(C, ar);
@@ -488,7 +491,7 @@ int WM_operator_name_call(bContext *C, const char *opstring, int context, Pointe
ARegion *ar= CTX_wm_region(C);
CTX_wm_region_set(C, NULL);
- retval= wm_operator_invoke(C, ot, event, properties);
+ retval= wm_operator_invoke(C, ot, event, properties, reports);
CTX_wm_region_set(C, ar);
return retval;
@@ -503,7 +506,7 @@ int WM_operator_name_call(bContext *C, const char *opstring, int context, Pointe
CTX_wm_region_set(C, NULL);
CTX_wm_area_set(C, NULL);
- retval= wm_operator_invoke(C, ot, event, properties);
+ retval= wm_operator_invoke(C, ot, event, properties, reports);
CTX_wm_region_set(C, ar);
CTX_wm_area_set(C, area);
@@ -512,32 +515,45 @@ int WM_operator_name_call(bContext *C, const char *opstring, int context, Pointe
case WM_OP_EXEC_DEFAULT:
event= NULL; /* pass on without break */
case WM_OP_INVOKE_DEFAULT:
- return wm_operator_invoke(C, ot, event, properties);
+ return wm_operator_invoke(C, ot, event, properties, reports);
}
}
return 0;
}
+
+/* invokes operator in context */
+int WM_operator_name_call(bContext *C, const char *opstring, int context, PointerRNA *properties)
+{
+ wmOperatorType *ot= WM_operatortype_find(opstring, 0);
+ if(ot)
+ return wm_operator_call_internal(C, ot, context, properties, NULL);
+
+ return 0;
+}
+
/* Similar to WM_operator_name_call called with WM_OP_EXEC_DEFAULT context.
- wmOperatorType is used instead of operator name since python alredy has the operator type
- poll() must be called by python before this runs.
- reports can be passed to this function (so python can report them as exceptions)
*/
-int WM_operator_call_py(bContext *C, wmOperatorType *ot, PointerRNA *properties, ReportList *reports)
+int WM_operator_call_py(bContext *C, wmOperatorType *ot, int context, PointerRNA *properties, ReportList *reports)
{
- wmWindowManager *wm= CTX_wm_manager(C);
- wmOperator *op= wm_operator_create(wm, ot, properties, reports);
int retval= OPERATOR_CANCELLED;
-
+
+#if 0
+ wmOperator *op;
+ wmWindowManager *wm= CTX_wm_manager(C);
+ op= wm_operator_create(wm, ot, properties, reports);
+
if (op->type->exec)
retval= op->type->exec(C, op);
else
printf("error \"%s\" operator has no exec function, python cannot call it\n", op->type->name);
-
- if (reports)
- op->reports= NULL; /* dont let the operator free reports passed to this function */
- WM_operator_free(op);
+#endif
+
+ retval= wm_operator_call_internal(C, ot, context, properties, reports);
return retval;
}
@@ -820,7 +836,7 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
wmOperatorType *ot= WM_operatortype_find(event->keymap_idname, 0);
if(ot)
- retval= wm_operator_invoke(C, ot, event, properties);
+ retval= wm_operator_invoke(C, ot, event, properties, NULL);
}
if(retval & OPERATOR_PASS_THROUGH)