diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-06-25 01:27:10 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-06-25 01:27:10 +0400 |
commit | 7a357cba3994bee7d05c7a8bf5736eb94067d564 (patch) | |
tree | 942d61fdd1138867710ed41604c4d2947565f7b1 /source | |
parent | 169fdf9e9757a8c31d950f5902d7c4cfd1f96a88 (diff) |
2.5: File Selector: display operator properties in the side region,
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.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.c | 19 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 12 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_utils.c | 58 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 71 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 53 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_buttons.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_toolbar.c | 4 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 22 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_define.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 38 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator_wrap.c | 11 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 66 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 13 |
15 files changed, 176 insertions, 199 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 2f054f7a08a..f5e2b45d41e 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -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 * diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 892a126feb6..73425eac0e1 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -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); } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 4dcf1590a65..dd87ee15474 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -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) diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 69104c87e64..e67e5b5a871 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -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 */ diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 6ed8f87d987..bb47d3458fe 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -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); + } } + diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 537996601b8..8f9bb0d05fe 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -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 ********************/ diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c index ca911876c89..91565235591 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.c +++ b/source/blender/editors/space_view3d/view3d_buttons.c @@ -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) diff --git a/source/blender/editors/space_view3d/view3d_toolbar.c b/source/blender/editors/space_view3d/view3d_toolbar.c index 1e55f2e4a9a..15254ba505e 100644 --- a/source/blender/editors/space_view3d/view3d_toolbar.c +++ b/source/blender/editors/space_view3d/view3d_toolbar.c @@ -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) diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index bab6982abd9..9f7559312ed 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -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); diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index b620a315085..85a148be2e2 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -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); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index a2954d43e0e..66127ebc6df 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -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, "}"); diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 51c1818eed9..bd449acc050 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -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_; diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index 542de6bd9b8..b7e3c86dd91 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -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 */ diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 1fd60a8ff27..3cef6e14861 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -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; diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 76a7b18fa12..410cd11f1bf 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -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); |