2.5: File Selector: display operator properties in the side region,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 24 Jun 2009 21:27:10 +0000 (21:27 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 24 Jun 2009 21:27:10 +0000 (21:27 +0000)
check Save Image or Export PLY operator for example.

Also these code changes:

* Added some RNA collection iterator macros to simplify code.
* Fix bpy.props.BoolProperty not working correct.
* Merge uiDefAutoButsRNA/uiDefAutoButsRNA_single into one.

15 files changed:
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/interface_utils.c
source/blender/editors/space_file/file_draw.c
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/editors/space_view3d/view3d_toolbar.c
source/blender/makesrna/RNA_access.h
source/blender/makesrna/RNA_define.h
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_define.c
source/blender/python/intern/bpy_operator_wrap.c
source/blender/python/intern/bpy_rna.c
source/blender/windowmanager/intern/wm_operators.c

index 2f054f7a08a90c9535403ee76fc33a1bf16b264b..f5e2b45d41ea824ac6ef214c608bceb488172a3a 100644 (file)
@@ -417,7 +417,7 @@ void uiBlockPickerButtons(struct uiBlock *block, float *col, float *hsv, float *
 void uiBlockColorbandButtons(struct uiBlock *block, struct ColorBand *coba, struct rctf *butr, int event);
 
 uiBut *uiDefAutoButR(uiBlock *block, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, char *name, int icon, int x1, int y1, int x2, int y2);
-void uiDefAutoButsRNA(const struct bContext *C, uiLayout *layout, struct PointerRNA *ptr);
+void uiDefAutoButsRNA(const struct bContext *C, uiLayout *layout, struct PointerRNA *ptr, int columns);
 
 /* Links
  *
index 892a126feb66615f554e13fbdb6b87606a08296d..73425eac0e16e1d4dfd2dbf50065dcfb3c186b6e 100644 (file)
@@ -1336,20 +1336,14 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen)
 
 static void ui_rna_ID_collection(bContext *C, uiBut *but, PointerRNA *ptr, PropertyRNA **prop)
 {
-       CollectionPropertyIterator iter;
-       PropertyRNA *iterprop, *iprop;
        StructRNA *srna;
 
        /* look for collection property in Main */
        RNA_pointer_create(NULL, &RNA_Main, CTX_data_main(C), ptr);
 
-       iterprop= RNA_struct_iterator_property(ptr->type);
-       RNA_property_collection_begin(ptr, iterprop, &iter);
        *prop= NULL;
 
-       for(; iter.valid; RNA_property_collection_next(&iter)) {
-               iprop= iter.ptr.data;
-
+       RNA_STRUCT_BEGIN(ptr, iprop) {
                /* if it's a collection and has same pointer type, we've got it */
                if(RNA_property_type(iprop) == PROP_COLLECTION) {
                        srna= RNA_property_pointer_type(ptr, iprop);
@@ -1360,8 +1354,7 @@ static void ui_rna_ID_collection(bContext *C, uiBut *but, PointerRNA *ptr, Prope
                        }
                }
        }
-
-       RNA_property_collection_end(&iter);
+       RNA_STRUCT_END;
 }
 
 /* autocomplete callback for RNA pointers */
@@ -1369,7 +1362,6 @@ static void ui_rna_ID_autocomplete(bContext *C, char *str, void *arg_but)
 {
        uiBut *but= arg_but;
        AutoComplete *autocpl;
-       CollectionPropertyIterator iter;
        PointerRNA ptr;
        PropertyRNA *prop;
        char *name;
@@ -1381,11 +1373,10 @@ static void ui_rna_ID_autocomplete(bContext *C, char *str, void *arg_but)
        if(prop==NULL) return;
 
        autocpl= autocomplete_begin(str, ui_get_but_string_max_length(but));
-       RNA_property_collection_begin(&ptr, prop, &iter);
 
        /* loop over items in collection */
-       for(; iter.valid; RNA_property_collection_next(&iter)) {
-               name= RNA_struct_name_get_alloc(&iter.ptr, NULL, 0);
+       RNA_PROP_BEGIN(&ptr, itemptr, prop) {
+               name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
 
                /* test item name */
                if(name) {
@@ -1393,8 +1384,8 @@ static void ui_rna_ID_autocomplete(bContext *C, char *str, void *arg_but)
                        MEM_freeN(name);
                }
        }
+       RNA_PROP_END;
 
-       RNA_property_collection_end(&iter);
        autocomplete_end(autocpl, str);
 }
 
index 4dcf1590a6519993e47f7ffcd85ed622ba24c1f0..dd87ee154748839ee73a46a62508b1c3b8b9a4d0 100644 (file)
@@ -1620,7 +1620,7 @@ void uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, char *act
        scroll= MIN2(scroll, len-items+1);
        scroll= MAX2(scroll, 1);
 
-       RNA_BEGIN(ptr, itemptr, propname) {
+       RNA_PROP_BEGIN(ptr, itemptr, prop) {
                if(i >= scroll && i<scroll+items) {
                        name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
 
@@ -1634,13 +1634,13 @@ void uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, char *act
                                item->activei= i;
 
                                if(activetype == PROP_POINTER)
-                                       item->selected= (activeptr.data == itemptr.data);
+                                       item->selected= (activeptr.data == itemptr.data)? i: -1;
                                else if(activetype == PROP_INT)
-                                       item->selected= (activei == i);
+                                       item->selected= (activei == i)? i: -1;
                                else if(activetype == PROP_STRING)
-                                       item->selected= (strcmp(activename, name) == 0);
+                                       item->selected= (strcmp(activename, name) == 0)? i: -1;
 
-                               but= uiDefIconTextButI(block, TOG, 0, RNA_struct_ui_icon(itemptr.type), name, 0,0,UI_UNIT_X*10,UI_UNIT_Y, &item->selected, 0, 0, 0, 0, "");
+                               but= uiDefIconTextButI(block, ROW, 0, RNA_struct_ui_icon(itemptr.type), name, 0,0,UI_UNIT_X*10,UI_UNIT_Y, &item->selected, 0, i, 0, 0, "");
                                uiButSetFlag(but, UI_ICON_LEFT|UI_TEXT_LEFT);
                                uiButSetNFunc(but, list_item_cb, item, NULL);
 
@@ -1650,7 +1650,7 @@ void uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, char *act
 
                i++;
        }
-       RNA_END;
+       RNA_PROP_END;
 
        while(i < scroll+items) {
                if(i >= scroll)
index 69104c87e646387c8480baa470939bc58c9512f8..e67e5b5a871dd94d771f43cc7cf58cbd715ea748 100644 (file)
@@ -142,69 +142,39 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind
        return but;
 }
 
-void uiDefAutoButsRNA(const bContext *C, uiLayout *layout, PointerRNA *ptr)
+void uiDefAutoButsRNA(const bContext *C, uiLayout *layout, PointerRNA *ptr, int columns)
 {
-       CollectionPropertyIterator iter;
-       PropertyRNA *iterprop, *prop;
-       uiLayout *split;
+       uiLayout *split, *col;
        char *name;
 
        uiItemL(layout, (char*)RNA_struct_ui_name(ptr->type), 0);
 
-       iterprop= RNA_struct_iterator_property(ptr->type);
-       RNA_property_collection_begin(ptr, iterprop, &iter);
-
-       for(; iter.valid; RNA_property_collection_next(&iter)) {
-               prop= iter.ptr.data;
-
+       RNA_STRUCT_BEGIN(ptr, prop) {
                if(strcmp(RNA_property_identifier(prop), "rna_type") == 0)
                        continue;
 
-               split = uiLayoutSplit(layout, 0.5f);
-
                name= (char*)RNA_property_ui_name(prop);
 
-               uiItemL(uiLayoutColumn(split, 0), name, 0);
-               uiItemFullR(uiLayoutColumn(split, 0), "", 0, ptr, prop, -1, 0, 0, 0, 0);
-       }
+               if(columns == 1) {
+                       col= uiLayoutColumn(layout, 1);
+                       uiItemL(col, name, 0);
+               }
+               else if(columns == 2) {
+                       split = uiLayoutSplit(layout, 0.5f);
 
-       RNA_property_collection_end(&iter);
-}
+                       uiItemL(uiLayoutColumn(split, 0), name, 0);
+                       col= uiLayoutColumn(split, 0);
+               }
 
-/* temp call, single collumn, test for toolbar only */
-void uiDefAutoButsRNA_single(const bContext *C, uiLayout *layout, PointerRNA *ptr)
-{
-       CollectionPropertyIterator iter;
-       PropertyRNA *iterprop, *prop;
-       uiLayout *col;
-       char *name;
-       
-       uiItemL(layout, (char*)RNA_struct_ui_name(ptr->type), 0);
-       
-       iterprop= RNA_struct_iterator_property(ptr->type);
-       RNA_property_collection_begin(ptr, iterprop, &iter);
-       
-       for(; iter.valid; RNA_property_collection_next(&iter)) {
-               prop= iter.ptr.data;
-               
-               if(strcmp(RNA_property_identifier(prop), "rna_type") == 0)
-                       continue;
-               
-               name= (char*)RNA_property_ui_name(prop);
-               col= uiLayoutColumn(layout, 1);
-               uiItemL(col, name, 0);
-               
                /* temp hack to show normal button for spin/screw */
                if(strcmp(name, "Axis")==0) {
-                       uiDefButR(uiLayoutGetBlock(layout), BUT_NORMAL, 0, name, 0, 0, 100, 100, ptr, "axis", -1, 0, 0, -1, -1, NULL);
+                       uiDefButR(uiLayoutGetBlock(col), BUT_NORMAL, 0, name, 0, 0, 100, 100, ptr, "axis", -1, 0, 0, -1, -1, NULL);
                }
                else uiItemFullR(col, "", 0, ptr, prop, -1, 0, 0, 0, 0);
        }
-       
-       RNA_property_collection_end(&iter);
+       RNA_STRUCT_END;
 }
 
-
 /***************************** ID Utilities *******************************/
 /* note, C code version, will be replaced with version in interface_templates.c */
 
index 6ed8f87d987ef8855015b7454f1468ec868a7e69..bb47d3458feeba54178185b27ef8fefd76a39dde 100644 (file)
@@ -550,7 +550,24 @@ void file_draw_list(const bContext *C, ARegion *ar)
        }
 }
 
-static void file_draw_fsmenu_category(const bContext *C, ARegion *ar, FSMenuCategory category, const char* category_name, short *starty)
+static void file_draw_fsmenu_category_name(ARegion *ar, const char *category_name, short *starty)
+{
+       short sx, sy;
+       int bmwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*TILE_BORDER_X - ICON_DEFAULT_WIDTH - 4;
+       int fontsize = file_font_pointsize();
+
+       sx = ar->v2d.cur.xmin + TILE_BORDER_X;
+       sy = *starty;
+
+       UI_ThemeColor(TH_TEXT_HI);
+       file_draw_string(sx, sy, category_name, bmwidth, fontsize, FILE_SHORTEN_END);
+       
+       sy -= fontsize*2.0f;
+
+       *starty= sy;
+}
+
+static void file_draw_fsmenu_category(const bContext *C, ARegion *ar, FSMenuCategory category, short *starty)
 {
        struct FSMenu* fsmenu = fsmenu_get();
        char bookmark[FILE_MAX];
@@ -565,11 +582,6 @@ static void file_draw_fsmenu_category(const bContext *C, ARegion *ar, FSMenuCate
        sx = ar->v2d.cur.xmin + TILE_BORDER_X;
        sy = *starty;
 
-       UI_ThemeColor(TH_TEXT_HI);
-       file_draw_string(sx, sy, category_name, bmwidth, fontsize, FILE_SHORTEN_END);
-       
-       sy -= fontsize*2.0f;
-
        switch(category) {
                case FS_CATEGORY_SYSTEM:
                        cat_icon = ICON_DISK_DRIVE; break;
@@ -616,15 +628,54 @@ static void file_draw_fsmenu_category(const bContext *C, ARegion *ar, FSMenuCate
        *starty = sy;
 }
 
+void file_draw_fsmenu_operator(const bContext *C, ARegion *ar, wmOperator *op, short *starty)
+{
+       uiStyle *style= U.uistyles.first;
+       uiBlock *block;
+       uiLayout *layout;
+       int sy;
+
+       sy= *starty;
+       
+       block= uiBeginBlock(C, ar, "file_options", UI_EMBOSS);
+       layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, TILE_BORDER_X, sy, ar->winx-2*TILE_BORDER_X, 20, style);
+
+    RNA_STRUCT_BEGIN(op->ptr, prop) {
+        if(strcmp(RNA_property_identifier(prop), "rna_type") == 0)
+            continue;
+        if(strcmp(RNA_property_identifier(prop), "filename") == 0)
+            continue;
+
+        uiItemFullR(layout, NULL, 0, op->ptr, prop, -1, 0, 0, 0, 0);
+    }
+    RNA_STRUCT_END;
+
+       uiBlockLayoutResolve(C, block, NULL, &sy);
+       uiEndBlock(C, block);
+       uiDrawBlock(C, block);
+
+       *starty= sy;
+}
+
 void file_draw_fsmenu(const bContext *C, ARegion *ar)
 {
+       SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
        int linestep = file_font_pointsize()*2.0f;
        short sy= ar->v2d.cur.ymax-2*TILE_BORDER_Y;
 
-       file_draw_fsmenu_category(C, ar, FS_CATEGORY_SYSTEM, "SYSTEM", &sy);
+       file_draw_fsmenu_category_name(ar, "SYSTEM", &sy);
+       file_draw_fsmenu_category(C, ar, FS_CATEGORY_SYSTEM, &sy);
        sy -= linestep;
-       file_draw_fsmenu_category(C, ar, FS_CATEGORY_BOOKMARKS, "BOOKMARKS", &sy);
+       file_draw_fsmenu_category_name(ar, "BOOKMARKS", &sy);
+       file_draw_fsmenu_category(C, ar, FS_CATEGORY_BOOKMARKS, &sy);
        sy -= linestep;
-       file_draw_fsmenu_category(C, ar, FS_CATEGORY_RECENT, "RECENT", &sy);
-       
+       file_draw_fsmenu_category_name(ar, "RECENT", &sy);
+       file_draw_fsmenu_category(C, ar, FS_CATEGORY_RECENT, &sy);
+
+       if(sfile->op) {
+               sy -= linestep;
+               file_draw_fsmenu_category_name(ar, "OPTIONS", &sy);
+               file_draw_fsmenu_operator(C, ar, sfile->op, &sy);
+       }
 }
+
index 537996601b8c60f1ee39e08f45dcb74b6b744171..8f9bb0d05fe8c3d5c5ea61097645f8a6d9d6387a 100644 (file)
@@ -577,34 +577,30 @@ void IMAGE_OT_view_zoom_ratio(wmOperatorType *ot)
 
 /**************** load/replace/save callbacks ******************/
 
-static char *filesel_imagetype_string(Image *ima)
-{
-       char *strp, *str= MEM_callocN(15*32, "menu for filesel");
-       
-       strp= str;
-       str += sprintf(str, "Save Image as: %%t|");
-       str += sprintf(str, "Targa %%x%d|", R_TARGA);
-       str += sprintf(str, "Targa Raw %%x%d|", R_RAWTGA);
-       str += sprintf(str, "PNG %%x%d|", R_PNG);
-       str += sprintf(str, "BMP %%x%d|", R_BMP);
-       str += sprintf(str, "Jpeg %%x%d|", R_JPEG90);
+/* XXX make dynamic */
+static const EnumPropertyItem image_file_type_items[] = {
+               {R_TARGA, "TARGA", 0, "Targa", ""},
+               {R_RAWTGA, "TARGA RAW", 0, "Targa Raw", ""},
+               {R_PNG, "PNG", 0, "PNG", ""},
+               {R_BMP, "BMP", 0, "BMP", ""},
+               {R_JPEG90, "JPEG", 0, "Jpeg", ""},
 #ifdef WITH_OPENJPEG
-       str += sprintf(str, "Jpeg 2000 %%x%d|", R_JP2);
+               {R_JP2, "JPEG_2000", 0, "Jpeg 2000", ""},
 #endif
-       str += sprintf(str, "Iris %%x%d|", R_IRIS);
-       if(G.have_libtiff)
-               str += sprintf(str, "Tiff %%x%d|", R_TIFF);
-       str += sprintf(str, "Radiance HDR %%x%d|", R_RADHDR);
-       str += sprintf(str, "Cineon %%x%d|", R_CINEON);
-       str += sprintf(str, "DPX %%x%d|", R_DPX);
+               {R_IRIS, "IRIS", 0, "Iris", ""},
+       //if(G.have_libtiff)
+               {R_TIFF, "TIFF", 0, "Tiff", ""},
+               {R_RADHDR, "RADIANCE_HDR", 0, "Radiance HDR", ""},
+               {R_CINEON, "CINEON", 0, "Cineon", ""},
+               {R_DPX, "DPX", 0, "DPX", ""},
 #ifdef WITH_OPENEXR
-       str += sprintf(str, "OpenEXR %%x%d|", R_OPENEXR);
+               {R_OPENEXR, "OPENEXR", 0, "OpenEXR", ""},
        /* saving sequences of multilayer won't work, they copy buffers  */
-       if(ima->source==IMA_SRC_SEQUENCE && ima->type==IMA_TYPE_MULTILAYER);
-       else str += sprintf(str, "MultiLayer %%x%d|", R_MULTILAYER);
+       /*if(ima->source==IMA_SRC_SEQUENCE && ima->type==IMA_TYPE_MULTILAYER);
+       else*/
+               {R_MULTILAYER, "MULTILAYER", 0, "MultiLayer", ""},
 #endif 
-       return strp;
-}
+               {0, NULL, 0, NULL, NULL}};
 
 static void image_filesel(bContext *C, wmOperator *op, const char *path)
 {
@@ -799,7 +795,9 @@ static int save_as_exec(bContext *C, wmOperator *op)
        if(!ima)
                return OPERATOR_CANCELLED;
 
+       sima->imtypenr= RNA_enum_get(op->ptr, "file_type");
        RNA_string_get(op->ptr, "filename", str);
+
        save_image_doit(C, sima, scene, op, str);
 
        return OPERATOR_FINISHED;
@@ -820,10 +818,6 @@ static int save_as_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
        /* always opens fileselect */
        if(ibuf) {
-               char *strp;
-               
-               strp= filesel_imagetype_string(ima); // XXX unused still
-               
                /* cant save multilayer sequence, ima->rr isn't valid for a specific frame */
                if(ima->rr && !(ima->source==IMA_SRC_SEQUENCE && ima->type==IMA_TYPE_MULTILAYER))
                        sima->imtypenr= R_MULTILAYER;
@@ -831,14 +825,14 @@ static int save_as_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        sima->imtypenr= scene->r.imtype;
                else
                        sima->imtypenr= BKE_ftype_to_imtype(ibuf->ftype);
+
+               RNA_enum_set(op->ptr, "file_type", sima->imtypenr);
                
                if(ibuf->name[0]==0)
                        BLI_strncpy(ibuf->name, G.ima, FILE_MAX);
                
                // XXX note: we can give default menu enums to operator for this 
                image_filesel(C, op, ibuf->name);
-
-               MEM_freeN(strp);
                
                return OPERATOR_RUNNING_MODAL;
        }
@@ -862,6 +856,7 @@ void IMAGE_OT_save_as(wmOperatorType *ot)
 
        /* properties */
        RNA_def_string_file_path(ot->srna, "filename", "", FILE_MAX, "Filename", "File path to save image to.");
+       RNA_def_enum(ot->srna, "file_type", image_file_type_items, R_PNG, "File Type", "File type to save image as.");
 }
 
 /******************** save image operator ********************/
index ca911876c891a8854efb26ea3996516fc0d5bb18..915652355918201d7ec12d179d3e2889e16cb4dd 100644 (file)
@@ -1710,7 +1710,7 @@ static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
        }
        
        RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
-       uiDefAutoButsRNA(C, pa->layout, &ptr);
+       uiDefAutoButsRNA(C, pa->layout, &ptr, 2);
 }
 
 void view3d_buttons_register(ARegionType *art)
index 1e55f2e4a9adace6b2047cd650a8a7010617460f..15254ba505edfe958c6a76c47dba6a1c7bdd1018 100644 (file)
@@ -120,8 +120,6 @@ static void redo_cb(bContext *C, void *arg_op, void *arg2)
 
 static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
 {
-       /* XXX temp */
-       extern void uiDefAutoButsRNA_single(const bContext *C, uiLayout *layout, PointerRNA *ptr);
        wmWindowManager *wm= CTX_wm_manager(C);
        wmOperator *op;
        PointerRNA ptr;
@@ -147,7 +145,7 @@ static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
        }
        
        RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
-       uiDefAutoButsRNA_single(C, pa->layout, &ptr);
+       uiDefAutoButsRNA(C, pa->layout, &ptr, 1);
 }
 
 void view3d_toolbar_register(ARegionType *art)
index bab6982abd96687fcacf4c5ad89a7f990146e061..9f7559312eda2884d82ef96441b6826005b62b48 100644 (file)
@@ -695,6 +695,28 @@ void RNA_collection_clear(PointerRNA *ptr, const char *name);
                RNA_property_collection_end(&rna_macro_iter); \
        }
 
+#define RNA_PROP_BEGIN(sptr, itemptr, prop) \
+       { \
+               CollectionPropertyIterator rna_macro_iter; \
+               for(RNA_property_collection_begin(sptr, prop, &rna_macro_iter); rna_macro_iter.valid; RNA_property_collection_next(&rna_macro_iter)) { \
+                       PointerRNA itemptr= rna_macro_iter.ptr;
+
+#define RNA_PROP_END \
+               } \
+               RNA_property_collection_end(&rna_macro_iter); \
+       }
+
+#define RNA_STRUCT_BEGIN(sptr, prop) \
+       { \
+               CollectionPropertyIterator rna_macro_iter; \
+               for(RNA_property_collection_begin(sptr, RNA_struct_iterator_property(sptr->type), &rna_macro_iter); rna_macro_iter.valid; RNA_property_collection_next(&rna_macro_iter)) { \
+                       PropertyRNA *prop= rna_macro_iter.ptr.data;
+
+#define RNA_STRUCT_END \
+               } \
+               RNA_property_collection_end(&rna_macro_iter); \
+       }
+
 /* check if the idproperty exists, for operators */
 int RNA_property_is_set(PointerRNA *ptr, const char *name);
 
index b620a31508532134d936ef4dc8843fd7d43820a2..85a148be2e2d12f9fda47b29258771aea1a0d596 100644 (file)
@@ -80,7 +80,7 @@ PropertyRNA *RNA_def_string(StructOrFunctionRNA *cont, const char *identifier, c
 PropertyRNA *RNA_def_string_file_path(StructOrFunctionRNA *cont, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description);
 PropertyRNA *RNA_def_string_dir_path(StructOrFunctionRNA *cont, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description);
 
-PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont, const char *identifier, EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description);
+PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description);
 
 PropertyRNA *RNA_def_float(StructOrFunctionRNA *cont, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax);
 PropertyRNA *RNA_def_float_vector(StructOrFunctionRNA *cont, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax);
index a2954d43e0effd5d569c4c0680d47de94d78991e..66127ebc6df3c225640c490aa3decb4f4835116b 100644 (file)
@@ -426,23 +426,16 @@ PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
 /* Find the property which uses the given nested struct */
 PropertyRNA *RNA_struct_find_nested(PointerRNA *ptr, StructRNA *srna)
 {
-       CollectionPropertyIterator iter;
-       PropertyRNA *iterprop, *prop;
-       int i = 0;
+       PropertyRNA *prop= NULL;
 
-       iterprop= RNA_struct_iterator_property(ptr->type);
-       RNA_property_collection_begin(ptr, iterprop, &iter);
-       prop= NULL;
-
-       for(; iter.valid; RNA_property_collection_next(&iter), i++) {
+       RNA_STRUCT_BEGIN(ptr, iprop) {
                /* This assumes that there can only be one user of this nested struct */
-               if (RNA_property_pointer_type(ptr, iter.ptr.data) == srna) {
-                       prop= iter.ptr.data;
+               if (RNA_property_pointer_type(ptr, iprop) == srna) {
+                       prop= iprop;
                        break;
                }
        }
-
-       RNA_property_collection_end(&iter);
+       RNA_PROP_END;
 
        return prop;
 }
@@ -455,25 +448,21 @@ const struct ListBase *RNA_struct_defined_properties(StructRNA *srna)
 FunctionRNA *RNA_struct_find_function(PointerRNA *ptr, const char *identifier)
 {
        PointerRNA tptr;
-       CollectionPropertyIterator iter;
        PropertyRNA *iterprop;
        FunctionRNA *func;
-       int i = 0;
 
        RNA_pointer_create(NULL, &RNA_Struct, ptr->type, &tptr);
        iterprop= RNA_struct_find_property(&tptr, "functions");
 
-       RNA_property_collection_begin(&tptr, iterprop, &iter);
        func= NULL;
 
-       for(; iter.valid; RNA_property_collection_next(&iter), i++) {
-               if(strcmp(identifier, RNA_function_identifier(iter.ptr.data)) == 0) {
-                       func= iter.ptr.data;
+       RNA_PROP_BEGIN(&tptr, funcptr, iterprop) {
+               if(strcmp(identifier, RNA_function_identifier(funcptr.data)) == 0) {
+                       func= funcptr.data;
                        break;
                }
        }
-
-       RNA_property_collection_end(&iter);
+       RNA_PROP_END;
 
        return func;
 }
@@ -2256,17 +2245,12 @@ char *RNA_pointer_as_string(PointerRNA *ptr)
        DynStr *dynstr= BLI_dynstr_new();
        char *cstring;
        
-       PropertyRNA *prop, *iterprop;
-       CollectionPropertyIterator iter;
        const char *propname;
        int first_time = 1;
        
        BLI_dynstr_append(dynstr, "{");
        
-       iterprop= RNA_struct_iterator_property(ptr->type);
-
-       for(RNA_property_collection_begin(ptr, iterprop, &iter); iter.valid; RNA_property_collection_next(&iter)) {
-               prop= iter.ptr.data;
+       RNA_STRUCT_BEGIN(ptr, prop) {
                propname = RNA_property_identifier(prop);
                
                if(strcmp(propname, "rna_type")==0)
@@ -2280,8 +2264,8 @@ char *RNA_pointer_as_string(PointerRNA *ptr)
                BLI_dynstr_appendf(dynstr, "\"%s\":%s", propname, cstring);
                MEM_freeN(cstring);
        }
+       RNA_STRUCT_END;
 
-       RNA_property_collection_end(&iter);
        BLI_dynstr_append(dynstr, "}"); 
        
        
index 51c1818eed98c0e43c53f79de1b8aed3ee9b5602..bd449acc050bfb2c1e99670cee483485c573205c 100644 (file)
@@ -1946,7 +1946,7 @@ PropertyRNA *RNA_def_string_dir_path(StructOrFunctionRNA *cont_, const char *ide
        return prop;
 }
 
-PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, EnumPropertyItem *items, int default_value, 
+PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, 
        const char *ui_name, const char *ui_description)
 {
        ContainerRNA *cont= cont_;
index 542de6bd9b84f4f653d83b48a655c331e6d7eac3..b7e3c86dd91bef8394fd9ee11f43e465d27e3f33 100644 (file)
@@ -107,15 +107,9 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve
                
                /* Assign instance attributes from operator properties */
                {
-                       PropertyRNA *prop, *iterprop;
-                       CollectionPropertyIterator iter;
                        const char *arg_name;
 
-                       iterprop= RNA_struct_iterator_property(op->ptr->type);
-                       RNA_property_collection_begin(op->ptr, iterprop, &iter);
-
-                       for(; iter.valid; RNA_property_collection_next(&iter)) {
-                               prop= iter.ptr.data;
+                       RNA_STRUCT_BEGIN(op->ptr, prop) {
                                arg_name= RNA_property_identifier(prop);
 
                                if (strcmp(arg_name, "rna_type")==0) continue;
@@ -124,8 +118,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve
                                PyObject_SetAttrString(py_class_instance, arg_name, item);
                                Py_DECREF(item);
                        }
-
-                       RNA_property_collection_end(&iter);
+                       RNA_STRUCT_END;
                }
 
                /* set operator pointer RNA as instance "__operator__" attribute */
index 1fd60a8ff2796cc60b5942e3421e4989861cbb2d..3cef6e148616402479cec0b8afd59ed49245a144 100644 (file)
@@ -328,17 +328,9 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefi
        const char *arg_name= NULL;
        PyObject *item;
 
-       PropertyRNA *prop, *iterprop;
-       CollectionPropertyIterator iter;
-
-       iterprop= RNA_struct_iterator_property(ptr->type);
-       RNA_property_collection_begin(ptr, iterprop, &iter);
-
        totkw = kw ? PyDict_Size(kw):0;
 
-       for(; iter.valid; RNA_property_collection_next(&iter)) {
-               prop= iter.ptr.data;
-
+       RNA_STRUCT_BEGIN(ptr, prop) {
                arg_name= RNA_property_identifier(prop);
 
                if (strcmp(arg_name, "rna_type")==0) continue;
@@ -364,8 +356,7 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefi
 
                totkw--;
        }
-
-       RNA_property_collection_end(&iter);
+       RNA_STRUCT_END;
 
        if (error_val==0 && totkw > 0) { /* some keywords were given that were not used :/ */
                PyObject *key, *value;
@@ -941,7 +932,6 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
        PyObject *pystring;
        
        /* for looping over attrs and funcs */
-       CollectionPropertyIterator iter;
        PropertyRNA *iterprop;
        
        /* Include this incase this instance is a subtype of a python class
@@ -973,10 +963,9 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
                char name[256], *nameptr;
 
                iterprop= RNA_struct_iterator_property(self->ptr.type);
-               RNA_property_collection_begin(&self->ptr, iterprop, &iter);
 
-               for(; iter.valid; RNA_property_collection_next(&iter)) {
-                       nameptr= RNA_struct_name_get_alloc(&iter.ptr, name, sizeof(name));
+               RNA_PROP_BEGIN(&self->ptr, itemptr, iterprop) {
+                       nameptr= RNA_struct_name_get_alloc(&itemptr, name, sizeof(name));
 
                        if(nameptr) {
                                pystring = PyUnicode_FromString(nameptr);
@@ -987,8 +976,7 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
                                        MEM_freeN(nameptr);
                        }
                }
-               RNA_property_collection_end(&iter);
-       
+               RNA_PROP_END;
        }
        
        
@@ -1001,15 +989,12 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
                RNA_pointer_create(NULL, &RNA_Struct, self->ptr.type, &tptr);
                iterprop= RNA_struct_find_property(&tptr, "functions");
 
-               RNA_property_collection_begin(&tptr, iterprop, &iter);
-
-               for(; iter.valid; RNA_property_collection_next(&iter)) {
-                       pystring = PyUnicode_FromString(RNA_function_identifier(iter.ptr.data));
+               RNA_PROP_BEGIN(&tptr, itemptr, iterprop) {
+                       pystring = PyUnicode_FromString(RNA_function_identifier(itemptr.data));
                        PyList_Append(ret, pystring);
                        Py_DECREF(pystring);
                }
-
-               RNA_property_collection_end(&iter);
+               RNA_PROP_END;
        }
 
        if(self->ptr.type == &RNA_Context) {
@@ -1122,19 +1107,14 @@ PyObject *pyrna_prop_keys(BPy_PropertyRNA *self)
                ret = NULL;
        } else {
                PyObject *item;
-               CollectionPropertyIterator iter;
-               PropertyRNA *nameprop;
                char name[256], *nameptr;
 
                ret = PyList_New(0);
                
-               RNA_property_collection_begin(&self->ptr, self->prop, &iter);
-               for(; iter.valid; RNA_property_collection_next(&iter)) {
-                       nameptr= RNA_struct_name_get_alloc(&iter.ptr, name, sizeof(name));
+               RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) {
+                       nameptr= RNA_struct_name_get_alloc(&itemptr, name, sizeof(name));
 
                        if(nameptr) {
-                               nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));                                
-                               
                                /* add to python list */
                                item = PyUnicode_FromString( nameptr );
                                PyList_Append(ret, item);
@@ -1145,7 +1125,7 @@ PyObject *pyrna_prop_keys(BPy_PropertyRNA *self)
                                        MEM_freeN(nameptr);
                        }
                }
-               RNA_property_collection_end(&iter);
+               RNA_PROP_END;
        }
        
        return ret;
@@ -1159,18 +1139,16 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self)
                ret = NULL;
        } else {
                PyObject *item;
-               CollectionPropertyIterator iter;
                char name[256], *nameptr;
                int i= 0;
 
                ret = PyList_New(0);
                
-               RNA_property_collection_begin(&self->ptr, self->prop, &iter);
-               for(; iter.valid; RNA_property_collection_next(&iter)) {
-                       if(iter.ptr.data) {
+               RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) {
+                       if(itemptr.data) {
                                /* add to python list */
                                item= PyTuple_New(2);
-                               nameptr= RNA_struct_name_get_alloc(&iter.ptr, name, sizeof(name));
+                               nameptr= RNA_struct_name_get_alloc(&itemptr, name, sizeof(name));
                                if(nameptr) {
                                        PyTuple_SET_ITEM(item, 0, PyUnicode_FromString( nameptr ));
                                        if(name != nameptr)
@@ -1179,7 +1157,7 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self)
                                else {
                                        PyTuple_SET_ITEM(item, 0, PyLong_FromSsize_t(i)); /* a bit strange but better then returning an empty list */
                                }
-                               PyTuple_SET_ITEM(item, 1, pyrna_struct_CreatePyObject(&iter.ptr));
+                               PyTuple_SET_ITEM(item, 1, pyrna_struct_CreatePyObject(&itemptr));
                                
                                PyList_Append(ret, item);
                                Py_DECREF(item);
@@ -1187,7 +1165,7 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self)
                                i++;
                        }
                }
-               RNA_property_collection_end(&iter);
+               RNA_PROP_END;
        }
        
        return ret;
@@ -1203,16 +1181,14 @@ PyObject *pyrna_prop_values(BPy_PropertyRNA *self)
                ret = NULL;
        } else {
                PyObject *item;
-               CollectionPropertyIterator iter;
                ret = PyList_New(0);
                
-               RNA_property_collection_begin(&self->ptr, self->prop, &iter);
-               for(; iter.valid; RNA_property_collection_next(&iter)) {
-                       item = pyrna_struct_CreatePyObject(&iter.ptr);
+               RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) {
+                       item = pyrna_struct_CreatePyObject(&itemptr);
                        PyList_Append(ret, item);
                        Py_DECREF(item);
                }
-               RNA_property_collection_end(&iter);
+               RNA_PROP_END;
        }
        
        return ret;
@@ -2023,7 +1999,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
        char *id, *name="", *description="";
        int def=0;
        
-       if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssi:IntProperty", kwlist, &id, &name, &description, &def))
+       if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssi:BoolProperty", kwlist, &id, &name, &description, &def))
                return NULL;
        
        if (PyTuple_Size(args) > 0) {
@@ -2037,7 +2013,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
                Py_RETURN_NONE;
        } else {
                PyObject *ret = PyTuple_New(2);
-               PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_IntProperty, NULL));
+               PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_BoolProperty, NULL));
                PyTuple_SET_ITEM(ret, 1, kw);
                Py_INCREF(kw);
                return ret;
index 76a7b18fa1243720a15dd966c9786516dbbc954b..410cd11f1bf41e16722ce8a1d0f4198f95c686a6 100644 (file)
@@ -145,7 +145,6 @@ char *WM_operator_pystring(wmOperator *op)
        const char *arg_name= NULL;
 
        PropertyRNA *prop, *iterprop;
-       CollectionPropertyIterator iter;
 
        /* for building the string */
        DynStr *dynstr= BLI_dynstr_new();
@@ -155,10 +154,9 @@ char *WM_operator_pystring(wmOperator *op)
        BLI_dynstr_appendf(dynstr, "%s(", op->idname);
 
        iterprop= RNA_struct_iterator_property(op->ptr->type);
-       RNA_property_collection_begin(op->ptr, iterprop, &iter);
 
-       for(; iter.valid; RNA_property_collection_next(&iter)) {
-               prop= iter.ptr.data;
+       RNA_PROP_BEGIN(op->ptr, propptr, iterprop) {
+               prop= propptr.data;
                arg_name= RNA_property_identifier(prop);
 
                if (strcmp(arg_name, "rna_type")==0) continue;
@@ -170,8 +168,7 @@ char *WM_operator_pystring(wmOperator *op)
                MEM_freeN(buf);
                first_iter = 0;
        }
-
-       RNA_property_collection_end(&iter);
+       RNA_PROP_END;
 
        BLI_dynstr_append(dynstr, ")");
 
@@ -291,7 +288,7 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
 
        RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
        layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
-       uiDefAutoButsRNA(C, layout, &ptr);
+       uiDefAutoButsRNA(C, layout, &ptr, 2);
 
        uiPopupBoundsBlock(block, 4.0f, 0, 0);
        uiEndBlock(C, block);
@@ -333,7 +330,7 @@ static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
        uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
        
        layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
-       uiDefAutoButsRNA(C, layout, op->ptr);
+       uiDefAutoButsRNA(C, layout, op->ptr, 2);
        
        uiPopupBoundsBlock(block, 4.0f, 0, 0);
        uiEndBlock(C, block);