make python operator instances subclasses of the wmOperator when called.

was subclassing the operator's type before.

Removes the need for passing self.__operator__, can pass self directly.
This commit is contained in:
Campbell Barton 2009-11-02 08:32:00 +00:00
parent ab7a174f92
commit dd130350d5
13 changed files with 23 additions and 23 deletions

@ -1128,7 +1128,7 @@ class EXPORT_OT_autodesk_3ds(bpy.types.Operator):
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self.__operator__)
wm.add_fileselect(self)
return ('RUNNING_MODAL',)
def poll(self, context): # Poll isnt working yet

@ -3429,7 +3429,7 @@ class EXPORT_OT_fbx(bpy.types.Operator):
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self.__operator__)
wm.add_fileselect(self)
return ('RUNNING_MODAL',)

@ -184,7 +184,7 @@ class EXPORT_OT_mdd(bpy.types.Operator):
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self.__operator__)
wm.add_fileselect(self)
return ('RUNNING_MODAL',)
bpy.ops.add(EXPORT_OT_mdd)

@ -995,7 +995,7 @@ class EXPORT_OT_obj(bpy.types.Operator):
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self.__operator__)
wm.add_fileselect(self)
return ('RUNNING_MODAL',)
def poll(self, context): # Poll isnt working yet

@ -288,7 +288,7 @@ class EXPORT_OT_ply(bpy.types.Operator):
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self.__operator__)
wm.add_fileselect(self)
return ('RUNNING_MODAL',)

@ -1235,7 +1235,7 @@ class EXPORT_OT_x3d(bpy.types.Operator):
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self.__operator__)
wm.add_fileselect(self)
return ('RUNNING_MODAL',)
bpy.ops.add(EXPORT_OT_x3d)

@ -1161,7 +1161,7 @@ class IMPORT_OT_autodesk_3ds(bpy.types.Operator):
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self.__operator__)
wm.add_fileselect(self)
return ('RUNNING_MODAL',)
bpy.ops.add(IMPORT_OT_autodesk_3ds)

@ -1618,7 +1618,7 @@ class IMPORT_OT_obj(bpy.types.Operator):
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self.__operator__)
wm.add_fileselect(self)
return ('RUNNING_MODAL',)

@ -528,7 +528,7 @@ class WM_OT_doc_edit(bpy.types.Operator):
def invoke(self, context, event):
wm = context.manager
wm.invoke_props_popup(self.__operator__, event)
wm.invoke_props_popup(self, event)
return ('RUNNING_MODAL',)

@ -51,11 +51,11 @@ class ExportSomeData(bpy.types.Operator):
if True:
# File selector
wm.add_fileselect(self.__operator__) # will run self.execute()
wm.add_fileselect(self) # will run self.execute()
return ('RUNNING_MODAL',)
else if 0:
# Redo popup
wm.invoke_props_popup(self.__operator__, event) #
wm.invoke_props_popup(self, event) #
return ('RUNNING_MODAL',)
else if 0:
return self.execute(context)

@ -678,7 +678,7 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self.__operator__)
wm.add_fileselect(self)
return ('RUNNING_MODAL',)

@ -1553,7 +1553,7 @@ class OBJECT_OT_select_pattern(bpy.types.Operator):
'''
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self.__operator__)
wm.add_fileselect(self)
return ('RUNNING_MODAL',)
'''

@ -90,14 +90,18 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
PointerRNA ptr_context;
PointerRNA ptr_operator;
PointerRNA ptr_event;
PyObject *py_operator;
PyGILState_STATE gilstate;
bpy_context_set(C, &gilstate);
args = PyTuple_New(1);
PyTuple_SET_ITEM(args, 0, PyObject_GetAttrString(py_class, "bl_rna")); // need to use an rna instance as the first arg
/* poll has no 'op', should be ok still */
/* use an rna instance as the first arg */
RNA_pointer_create(NULL, &RNA_Operator, op, &ptr_operator);
PyTuple_SET_ITEM(args, 0, pyrna_struct_CreatePyObject(&ptr_operator));
py_class_instance = PyObject_Call(py_class, args, NULL);
Py_DECREF(args);
@ -120,14 +124,6 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
RNA_STRUCT_END;
}
/* set operator pointer RNA as instance "__operator__" attribute */
if(op) {
RNA_pointer_create(NULL, &RNA_Operator, op, &ptr_operator);
py_operator= pyrna_struct_CreatePyObject(&ptr_operator);
PyDict_SetItemString(class_dict, "__operator__", py_operator);
Py_DECREF(py_operator);
}
RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context);
if (mode==PYOP_INVOKE) {
@ -160,6 +156,10 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
Py_DECREF(item);
Py_DECREF(class_dict);
}
else {
PyErr_Print();
PyErr_Clear();
}
if (ret == NULL) { /* covers py_class_instance failing too */
if(op)