calling operators from python was raising an error without returning an error value.
brecht, switched the order back to fix this, added an argument for WM_operatortype_find() to fail without printing an error.
This commit is contained in:
@@ -2273,7 +2273,7 @@ uiBut *ui_def_but_operator(uiBlock *block, int type, char *opname, int opcontext
|
||||
uiBut *but;
|
||||
wmOperatorType *ot;
|
||||
|
||||
ot= WM_operatortype_find(opname);
|
||||
ot= WM_operatortype_find(opname, 0);
|
||||
|
||||
if(!str) {
|
||||
if(ot) str= ot->name;
|
||||
|
||||
@@ -515,7 +515,7 @@ static void ui_item_disabled(uiLayout *layout, char *name)
|
||||
void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDProperty *properties, int context)
|
||||
{
|
||||
uiBlock *block= layout->root->block;
|
||||
wmOperatorType *ot= WM_operatortype_find(idname);
|
||||
wmOperatorType *ot= WM_operatortype_find(idname, 0);
|
||||
uiBut *but;
|
||||
int w;
|
||||
|
||||
@@ -550,7 +550,7 @@ void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDPropert
|
||||
|
||||
static char *ui_menu_enumpropname(uiLayout *layout, char *opname, char *propname, int retval)
|
||||
{
|
||||
wmOperatorType *ot= WM_operatortype_find(opname);
|
||||
wmOperatorType *ot= WM_operatortype_find(opname, 0);
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
|
||||
@@ -593,7 +593,7 @@ void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char *pro
|
||||
|
||||
void uiItemsEnumO(uiLayout *layout, char *opname, char *propname)
|
||||
{
|
||||
wmOperatorType *ot= WM_operatortype_find(opname);
|
||||
wmOperatorType *ot= WM_operatortype_find(opname, 0);
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
|
||||
@@ -1213,7 +1213,7 @@ static void menu_item_enum_opname_menu(bContext *C, uiLayout *layout, void *arg)
|
||||
|
||||
void uiItemMenuEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname)
|
||||
{
|
||||
wmOperatorType *ot= WM_operatortype_find(opname);
|
||||
wmOperatorType *ot= WM_operatortype_find(opname, 0);
|
||||
MenuItemLevel *lvl;
|
||||
|
||||
if(!ot || !ot->srna) {
|
||||
|
||||
@@ -2812,7 +2812,7 @@ void uiPupBlockO(bContext *C, uiBlockCreateFunc func, void *arg, char *opname, i
|
||||
|
||||
handle= ui_popup_block_create(C, NULL, NULL, func, NULL, arg);
|
||||
handle->popup= 1;
|
||||
handle->optype= (opname)? WM_operatortype_find(opname): NULL;
|
||||
handle->optype= (opname)? WM_operatortype_find(opname, 0): NULL;
|
||||
handle->opcontext= opcontext;
|
||||
|
||||
UI_add_popup_handlers(C, &window->handlers, handle);
|
||||
|
||||
@@ -286,7 +286,8 @@ static void text_keymap(struct wmWindowManager *wm)
|
||||
|
||||
WM_keymap_add_item(keymap, "TEXT_OT_line_break", RETKEY, KM_PRESS, 0, 0);
|
||||
#ifndef DISABLE_PYTHON
|
||||
WM_keymap_add_item(keymap, "TEXT_OT_line_console", RETKEY, KM_PRESS, KM_SHIFT, 0); /* python operator - space_text.py */
|
||||
WM_keymap_add_item(keymap, "TEXT_OT_console_exec", RETKEY, KM_PRESS, KM_SHIFT, 0); /* python operator - space_text.py */
|
||||
WM_keymap_add_item(keymap, "TEXT_OT_console_autocomplete", RETKEY, KM_PRESS, KM_ALT, 0); /* python operator - space_text.py */
|
||||
#endif
|
||||
|
||||
WM_keymap_add_item(keymap, "TEXT_OT_line_number", KM_TEXTINPUT, KM_ANY, KM_ANY, 0);
|
||||
|
||||
@@ -68,7 +68,7 @@ static PyObject *pyop_base_call( PyObject * self, PyObject * args, PyObject * k
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ot= WM_operatortype_find(opname);
|
||||
ot= WM_operatortype_find(opname, 1);
|
||||
if (ot == NULL) {
|
||||
PyErr_Format( PyExc_SystemError, "Operator \"%s\"could not be found", opname);
|
||||
return NULL;
|
||||
@@ -130,12 +130,19 @@ static PyObject *pyop_base_getattro( BPy_OperatorBase * self, PyObject *pyname )
|
||||
PyObject *ret;
|
||||
wmOperatorType *ot;
|
||||
|
||||
if ((ret = PyObject_GenericGetAttr((PyObject *)self, pyname))) {
|
||||
/* do nothing, this accounts for methoddef's add and remove */
|
||||
}
|
||||
else if ((ot= WM_operatortype_find(name))) {
|
||||
/* First look for the operator, then our own methods if that fails.
|
||||
* when methods are searched first, PyObject_GenericGetAttr will raise an error
|
||||
* each time we want to call an operator, we could clear the error but I prefer
|
||||
* not to since calling operators is a lot more common then adding and removing. - Campbell */
|
||||
|
||||
if ((ot= WM_operatortype_find(name, 1))) {
|
||||
ret = PyCFunction_New( pyop_base_call_meth, pyname); /* set the name string as self, PyCFunction_New incref's self */
|
||||
}
|
||||
else if ((ret = PyObject_GenericGetAttr((PyObject *)self, pyname))) {
|
||||
/* do nothing, this accounts for methoddef's add and remove
|
||||
* An exception is raised when PyObject_GenericGetAttr fails
|
||||
* but its ok because its overwritten below */
|
||||
}
|
||||
else {
|
||||
PyErr_Format( PyExc_AttributeError, "Operator \"%s\" not found", name);
|
||||
ret= NULL;
|
||||
@@ -170,7 +177,7 @@ static PyObject *pyop_base_rna(PyObject *self, PyObject *pyname)
|
||||
char *name = _PyUnicode_AsString(pyname);
|
||||
wmOperatorType *ot;
|
||||
|
||||
if ((ot= WM_operatortype_find(name))) {
|
||||
if ((ot= WM_operatortype_find(name, 1))) {
|
||||
BPy_StructRNA *pyrna;
|
||||
PointerRNA ptr;
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ int WM_operator_redo_popup (struct bContext *C, struct wmOperator *op);
|
||||
void WM_operator_free (struct wmOperator *op);
|
||||
void WM_operator_stack_clear(struct bContext *C);
|
||||
|
||||
wmOperatorType *WM_operatortype_find(const char *idname);
|
||||
wmOperatorType *WM_operatortype_find(const char *idnamem, int quiet);
|
||||
wmOperatorType *WM_operatortype_exists(const char *idname);
|
||||
wmOperatorType *WM_operatortype_first(void);
|
||||
void WM_operatortype_append (void (*opfunc)(wmOperatorType*));
|
||||
|
||||
@@ -393,7 +393,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P
|
||||
/* invokes operator in context */
|
||||
int WM_operator_name_call(bContext *C, const char *opstring, int context, PointerRNA *properties)
|
||||
{
|
||||
wmOperatorType *ot= WM_operatortype_find(opstring);
|
||||
wmOperatorType *ot= WM_operatortype_find(opstring, 0);
|
||||
wmWindow *window= CTX_wm_window(C);
|
||||
wmEvent *event;
|
||||
|
||||
@@ -723,7 +723,7 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
|
||||
printf("wm_handler_operator_call error\n");
|
||||
}
|
||||
else {
|
||||
wmOperatorType *ot= WM_operatortype_find(event->keymap_idname);
|
||||
wmOperatorType *ot= WM_operatortype_find(event->keymap_idname, 0);
|
||||
|
||||
if(ot)
|
||||
retval= wm_operator_invoke(C, ot, event, properties);
|
||||
|
||||
@@ -82,7 +82,7 @@ static ListBase global_ops= {NULL, NULL};
|
||||
|
||||
/* ************ operator API, exported ********** */
|
||||
|
||||
wmOperatorType *WM_operatortype_find(const char *idname)
|
||||
wmOperatorType *WM_operatortype_find(const char *idname, int quiet)
|
||||
{
|
||||
wmOperatorType *ot;
|
||||
|
||||
@@ -90,7 +90,10 @@ wmOperatorType *WM_operatortype_find(const char *idname)
|
||||
if(strncmp(ot->idname, idname, OP_MAX_TYPENAME)==0)
|
||||
return ot;
|
||||
}
|
||||
printf("search for unknown operator %s\n", idname);
|
||||
|
||||
if(!quiet)
|
||||
printf("search for unknown operator %s\n", idname);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -137,7 +140,7 @@ void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType*, void*), void *us
|
||||
|
||||
int WM_operatortype_remove(const char *idname)
|
||||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(idname);
|
||||
wmOperatorType *ot = WM_operatortype_find(idname, 0);
|
||||
|
||||
if (ot==NULL)
|
||||
return 0;
|
||||
@@ -190,7 +193,7 @@ char *WM_operator_pystring(wmOperator *op)
|
||||
|
||||
void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
|
||||
{
|
||||
wmOperatorType *ot= WM_operatortype_find(opstring);
|
||||
wmOperatorType *ot= WM_operatortype_find(opstring, 0);
|
||||
|
||||
if(ot)
|
||||
RNA_pointer_create(NULL, ot->srna, NULL, ptr);
|
||||
|
||||
Reference in New Issue
Block a user