diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-09-02 23:28:44 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-09-02 23:28:44 +0400 |
commit | c0ca93c9b26cf3f248ba11d86ef47e9e0ca5e84d (patch) | |
tree | 5b27e7689b7e6e1782c454d5bdb42e5619b08235 /source | |
parent | 37bad42b9ddb22b923287ca0f09388d2355b2c65 (diff) |
Add poll message when poll fails because of window missing from the context.
This means calling invoke operators from python in states that dont support will give a meaningful error message.
also reduce context lookups when polling.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 8 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 20 |
2 files changed, 19 insertions, 9 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index feffea20553..dc1f5828c15 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -821,8 +821,12 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult * } if (done == false) { - if (item) printf("PyContext '%s' not a valid type\n", member); - else printf("PyContext '%s' not found\n", member); + if (item) { + printf("PyContext '%s' not a valid type\n", member); + } + else { + printf("PyContext '%s' not found\n", member); + } } else { if (G.debug & G_DEBUG_PYTHON) { diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 184b0db41ae..72cd794489b 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -89,7 +89,7 @@ static void wm_notifier_clear(wmNotifier *note); static void update_tablet_data(wmWindow *win, wmEvent *event); static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA *properties, ReportList *reports, - short context, short poll_only); + const short context, const bool poll_only); /* ************ event management ************** */ @@ -963,9 +963,8 @@ int WM_operator_last_properties_store(wmOperator *UNUSED(op)) #endif static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, - PointerRNA *properties, ReportList *reports, short poll_only) + PointerRNA *properties, ReportList *reports, const bool poll_only) { - wmWindowManager *wm = CTX_wm_manager(C); int retval = OPERATOR_PASS_THROUGH; /* this is done because complicated setup is done to call this function that is better not duplicated */ @@ -973,6 +972,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, return WM_operator_poll(C, ot); if (WM_operator_poll(C, ot)) { + wmWindowManager *wm = CTX_wm_manager(C); wmOperator *op = wm_operator_create(wm, ot, properties, reports); /* if reports == NULL, they'll be initialized */ const short is_nested_call = (wm->op_undo_depth != 0); @@ -1101,9 +1101,8 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, * * invokes operator in context */ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA *properties, ReportList *reports, - short context, short poll_only) + const short context, const bool poll_only) { - wmWindow *window = CTX_wm_window(C); wmEvent *event; int retval; @@ -1112,16 +1111,23 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA /* dummie test */ if (ot && C) { + wmWindow *window = CTX_wm_window(C); + switch (context) { case WM_OP_INVOKE_DEFAULT: case WM_OP_INVOKE_REGION_WIN: case WM_OP_INVOKE_AREA: case WM_OP_INVOKE_SCREEN: /* window is needed for invoke, cancel operator */ - if (window == NULL) + if (window == NULL) { + if (poll_only) { + CTX_wm_operator_poll_msg_set(C, "missing 'window' in context"); + } return 0; - else + } + else { event = window->eventstate; + } break; default: event = NULL; |