Draw function for operators (just like panels), used for the redo popup, file selecto...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 29 Nov 2009 01:49:22 +0000 (01:49 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 29 Nov 2009 01:49:22 +0000 (01:49 +0000)
Used for ply export & select pattern.

release/scripts/io/export_ply.py
release/scripts/op/object.py
source/blender/editors/space_file/file_panels.c
source/blender/editors/space_view3d/view3d_toolbar.c
source/blender/makesdna/DNA_windowmanager_types.h
source/blender/python/intern/bpy_operator_wrap.c
source/blender/windowmanager/intern/wm_operators.c

index 50cb3134f83982f8f8f4a7f062b2059ff473e753..f9720be4646b7dd8705fd726d812a1022f2537ca 100644 (file)
@@ -263,9 +263,9 @@ class ExportPLY(bpy.types.Operator):
        
        path = StringProperty(name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "")
        use_modifiers = BoolProperty(name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True)
-       use_normals = BoolProperty(name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True)
-       use_uvs = BoolProperty(name="Export UVs", description="Exort the active UV layer", default= True)
-       use_colors = BoolProperty(name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
+       use_normals = BoolProperty(name="Normals", description="Export Normals for smooth and hard shaded faces", default= True)
+       use_uvs = BoolProperty(name="UVs", description="Exort the active UV layer", default= True)
+       use_colors = BoolProperty(name="Vertex Colors", description="Exort the active vertex color layer", default= True)
        
        
        def poll(self, context):
@@ -291,14 +291,25 @@ class ExportPLY(bpy.types.Operator):
                wm.add_fileselect(self)
                return ('RUNNING_MODAL',)
 
+       def draw(self, context):
+               layout = self.layout
+               props = self.properties
+
+               row = layout.row()
+               row.prop(props, "use_modifiers")
+               row.prop(props, "use_normals")
+               row = layout.row()
+               row.prop(props, "use_uvs")
+               row.prop(props, "use_colors")
+
 
 bpy.ops.add(ExportPLY)
 
 import dynamic_menu
 
 def menu_func(self, context):
-    default_path = bpy.data.filename.replace(".blend", ".ply")
-    self.layout.operator(ExportPLY.bl_idname, text="Stanford (.ply)...").path = default_path
+       default_path = bpy.data.filename.replace(".blend", ".ply")
+       self.layout.operator(ExportPLY.bl_idname, text="Stanford (.ply)...").path = default_path
 
 menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
 
index 50bbbf8158af6e1892c3782228b20d886a008b76..8823045e07d346a66b6706da7a3baec504335839 100644 (file)
@@ -52,6 +52,17 @@ class SelectPattern(bpy.types.Operator):
         wm = context.manager
         wm.invoke_props_popup(self, event)
         return ('RUNNING_MODAL',)
+    
+    def draw(self, context):
+        print("WoW")
+        layout = self.layout
+        props = self.properties
+        
+        layout.prop(props, "pattern")
+        row = layout.row()
+        row.prop(props, "case_sensitive")
+        row.prop(props, "extend")
+        
 
 
 class SubsurfSet(bpy.types.Operator):
index b6f37000afa5222b055869614ae5c871ea28f49a..fb52a36cdcfe235c81db8a7680978d4840305abc 100644 (file)
@@ -175,7 +175,7 @@ static void file_panel_operator(const bContext *C, Panel *pa)
        int empty= 1, flag;
 
        if(op->type->ui) {
-               op->type->ui((bContext*)C, op->ptr, pa->layout);
+               op->type->ui((bContext*)C, op, pa->layout);
        }
        else {
                RNA_STRUCT_BEGIN(op->ptr, prop) {
index 3249f26aff68bbd490ac2b2791d0d92c6384c1fa..5dbc6cc232c8344463bdadb2f3a63fef66359ed1 100644 (file)
@@ -143,7 +143,7 @@ static void view3d_panel_operator_redo_buts(const bContext *C, Panel *pa, wmOper
        
        RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
        if(op->type->ui)
-               op->type->ui((bContext*)C, &ptr, pa->layout);
+               op->type->ui((bContext*)C, op, pa->layout);
        else
                uiDefAutoButsRNA(C, pa->layout, &ptr, 1);
 }
index 5e5c98566695c65bc992c11ac7b166b65f002f96..1af1dd7a1589a28c599b72bcdb696cbc3a7059e7 100644 (file)
@@ -217,7 +217,7 @@ typedef struct wmOperatorType {
        int (*poll)(struct bContext *);
        
        /* optional panel for redo and repeat, autogenerated if not set */
-       void (*ui)(struct bContext *, struct PointerRNA *, struct uiLayout *);
+       void (*ui)(struct bContext *, struct wmOperator *, struct uiLayout *);
        
        /* rna for properties */
        struct StructRNA *srna;
index 0c0d043c4bea86c34fcc84ceff9f5f0f48edc18d..f12c7979f3e18bc94b01f38d611f7914569da489 100644 (file)
@@ -32,6 +32,7 @@
 #include "MEM_guardedalloc.h"
 #include "WM_api.h"
 #include "WM_types.h"
+#include "UI_interface.h"
 #include "ED_screen.h"
 
 #include "RNA_define.h"
@@ -78,10 +79,11 @@ static struct BPY_flag_def pyop_ret_flags[] = {
 #define PYOP_EXEC 1
 #define PYOP_INVOKE 2
 #define PYOP_POLL 3
+#define PYOP_DRAW 4
        
 extern void BPY_update_modules( void ); //XXX temp solution
 
-static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperator *op, wmEvent *event)
+static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperator *op, wmEvent *event, uiLayout *layout)
 {
        PyObject *py_class = ot->pyop_data;
        PyObject *args;
@@ -89,7 +91,6 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
        int ret_flag= (mode==PYOP_POLL ? 0:OPERATOR_CANCELLED);
        PointerRNA ptr_context;
        PointerRNA ptr_operator;
-       PointerRNA ptr_event;
 
        PyGILState_STATE gilstate;
 
@@ -113,6 +114,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
                RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context);
 
                if (mode==PYOP_INVOKE) {
+                       PointerRNA ptr_event;
                        item= PyObject_GetAttrString(py_class, "invoke");
                        args = PyTuple_New(3);
 
@@ -134,6 +136,36 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
                        args = PyTuple_New(2);
                        PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
                }
+               else if (mode==PYOP_DRAW) {
+                       PointerRNA ptr_layout;
+                       item= PyObject_GetAttrString(py_class, "draw");
+                       args = PyTuple_New(2);
+
+                       RNA_pointer_create(NULL, &RNA_UILayout, layout, &ptr_layout);
+
+                       // PyTuple_SET_ITEM "steals" object reference, it is
+                       // an object passed shouldn't be DECREF'ed
+                       PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
+#if 0
+                       PyTuple_SET_ITEM(args, 2, pyrna_struct_CreatePyObject(&ptr_layout));
+#else
+                       {
+                               /* mimic panels */
+                               PyObject *py_layout= pyrna_struct_CreatePyObject(&ptr_layout);
+                               PyObject *pyname= PyUnicode_FromString("layout");
+
+                               if(PyObject_GenericSetAttr(py_class_instance, pyname, py_layout)) {
+                                       PyErr_Print();
+                                       PyErr_Clear();
+                               }
+                               else {
+                                       Py_DECREF(py_layout);
+                               }
+
+                               Py_DECREF(pyname);
+                       }
+#endif
+               }
                PyTuple_SET_ITEM(args, 0, py_class_instance);
 
                ret = PyObject_Call(item, args, NULL);
@@ -155,7 +187,8 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
                        else {
                                ret_flag= ret==Py_True ? 1:0;
                        }
-                       
+               } else if(mode==PYOP_DRAW) {
+                       /* pass */
                } else if (BPY_flag_from_seq(pyop_ret_flags, ret, &ret_flag) == -1) {
                        /* the returned value could not be converted into a flag */
                        PyErr_Format(PyExc_ValueError, "Python operator, error using return value from \"%s\"\n", ot->idname);
@@ -209,19 +242,34 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
 
 static int PYTHON_OT_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       return PYTHON_OT_generic(PYOP_INVOKE, C, op->type, op, event);  
+       return PYTHON_OT_generic(PYOP_INVOKE, C, op->type, op, event, NULL);
 }
 
 static int PYTHON_OT_execute(bContext *C, wmOperator *op)
 {
-       return PYTHON_OT_generic(PYOP_EXEC, C, op->type, op, NULL);
+       return PYTHON_OT_generic(PYOP_EXEC, C, op->type, op, NULL, NULL);
 }
 
 static int PYTHON_OT_poll(bContext *C, wmOperatorType *ot)
 {
-       return PYTHON_OT_generic(PYOP_POLL, C, ot, NULL, NULL);
+       return PYTHON_OT_generic(PYOP_POLL, C, ot, NULL, NULL, NULL);
 }
 
+static void PYTHON_OT_draw(bContext *C, wmOperator *op, uiLayout *layout)
+{
+       PYTHON_OT_generic(PYOP_DRAW, C, op->type, op, NULL, layout);
+}
+
+// void (*ui)(struct bContext *, struct PointerRNA *, struct uiLayout *);
+//
+//static int PYTHON_OT_ui(bContext *C, PointerRNA *, uiLayout *layout)
+//{
+//     PointerRNA ptr_context, ptr_layout;
+//     RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context);
+//     RNA_pointer_create(NULL, &RNA_UILayout, layout, &ptr_layout);
+//
+//}
+
 void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
 {
        PyObject *py_class = (PyObject *)userdata;
@@ -256,6 +304,8 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
                ot->exec= PYTHON_OT_execute;
        if (PyObject_HasAttrString(py_class, "poll"))
                ot->pyop_poll= PYTHON_OT_poll;
+       if (PyObject_HasAttrString(py_class, "draw"))
+               ot->ui= PYTHON_OT_draw;
        
        ot->pyop_data= userdata;
        
@@ -320,6 +370,7 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
                {"execute",                             'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL},
                {"invoke",                              'f', 3, -1, BPY_CLASS_ATTR_OPTIONAL},
                {"poll",                                'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL},
+               {"draw",                                'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL},
                {NULL, 0, 0, 0}
        };
 
index 5820220f7803157c55be3587edb855e0163c7453..15e27f45d5e8ad0d1976373147c181c045769b48 100644 (file)
@@ -731,7 +731,7 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
        uiItemL(layout, op->type->name, 0);
 
        if(op->type->ui)
-               op->type->ui((bContext*)C, &ptr, layout);
+               op->type->ui((bContext*)C, op, layout);
        else
                uiDefAutoButsRNA(C, layout, &ptr, columns);
 
@@ -778,7 +778,7 @@ static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
        uiItemL(layout, op->type->name, 0);
 
        if(op->type->ui)
-               op->type->ui(C, op->ptr, layout);
+               op->type->ui(C, op, layout);
        else
                uiDefAutoButsRNA(C, layout, op->ptr, 2);