make python operator instances subclasses of the wmOperator when called.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 2 Nov 2009 08:32:00 +0000 (08:32 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 2 Nov 2009 08:32:00 +0000 (08:32 +0000)
was subclassing the operator's type before.

Removes the need for passing self.__operator__, can pass self directly.

13 files changed:
release/scripts/io/export_3ds.py
release/scripts/io/export_fbx.py
release/scripts/io/export_mdd.py
release/scripts/io/export_obj.py
release/scripts/io/export_ply.py
release/scripts/io/export_x3d.py
release/scripts/io/import_3ds.py
release/scripts/io/import_obj.py
release/scripts/modules/bpy_ops.py
release/scripts/templates/operator.py
release/scripts/ui/space_userpref.py
release/scripts/ui/space_view3d.py
source/blender/python/intern/bpy_operator_wrap.c

index d3221d4c81c6c8608275754e8547eeb3bc4692a7..3e5d64a3e35e666daa273f8e2278d427b72724c9 100644 (file)
@@ -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
index 92a7286d4afdc78e610050ac248bb82912661228..b303e536b99dc22f34e248e2c46cbe2c94f38348 100644 (file)
@@ -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',)
 
 
index 28e6a325cbedf39014e6c790bca040939ec79df7..677361f33927ff56b7ddb3db9fbfcb33e3e82dbc 100644 (file)
@@ -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)
index 92e6841016a1e1576a01d550270837d4e6e3c407..72f1835fea8abd8f0b7d690a86e16ee7b420c352 100644 (file)
@@ -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
index 61f3484f97dde08cd828fca6a203b9b6c0e37f72..7235d51450e28792623966fe1b6c947f962ce083 100644 (file)
@@ -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',)
 
 
index 4b215ccdd9f5954324da08c791c64113df6f9cda..6de6725267650ccaf2f40756a3f977dedfc3ffa0 100644 (file)
@@ -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)
index ebb4ed59c3698517d270cf3a1712d43762ed5882..62612cc79d4ea03e174b63a4b084beaa7138be13 100644 (file)
@@ -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)
index 4fb7ada5d81fe83701ac7d9a63a6b96c0540a252..e5e0dc35995db7e529de402fbaf2b4ff520de830 100644 (file)
@@ -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',)
 
 
index 233c072867e6cce70da665c3b2c6244007ad0710..cfcaf3b608361fbd86ca23dbf26978076d34117a 100644 (file)
@@ -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',)
 
 
index b0c03045216f6df8c20bbce2c7d8ce69d53e4a61..88e6a3270962fa691ea73abbfc0c5c9fc59324f5 100644 (file)
@@ -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)
index fc9678a08475591b193e774fc6993e405741400e..9fd35e9588e407d3ae5ea3fac52395e917529fd7 100644 (file)
@@ -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',)
 
 
index f197e4cb8ed23ce61971f7fe28b586d15d0ae193..24484f84e44d2c47afcfb5426a6f07d0ddef2638 100644 (file)
@@ -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',)
     '''
 
index fcfea7db8857466f5392f9011a870f9ad8771444..b0754ee1cde58e03dc65e38ac6105db2b7515a1a 100644 (file)
@@ -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)