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.
This commit is contained in:
2013-09-02 19:28:44 +00:00
parent 37bad42b9d
commit c0ca93c9b2
2 changed files with 19 additions and 9 deletions

View File

@@ -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) {

View File

@@ -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;