diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-04-17 16:47:20 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-04-17 16:47:20 +0400 |
commit | 0862abf68bf1c9601080d4fb142c8f7edc6b300f (patch) | |
tree | 02a3c6fa59a2a78b0c6c1254fd22ac9bd9b18af5 /source/blender/editors | |
parent | d00f664ee0c042569900110db21d567c21c391db (diff) |
change unit evaluation only to do try the units replacements if evaluating with python fails, in rare cases its possible a valid python expression could get units applied to it.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/interface/interface.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 166046aa64e..5b59baf9ea2 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1601,25 +1601,34 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str) double value; #ifdef WITH_PYTHON - { - char str_unit_convert[256]; - int unit_type= uiButGetUnitType(but); - Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); + int ok= FALSE; - BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert)); + if(str[0] != '\0') { + int is_unit_but= ui_is_but_unit(but); + /* only enable verbose if we won't run again with units */ + if(BPY_button_exec(C, str, &value, is_unit_but==FALSE) != -1) { + ok= TRUE; /* parse normal string via py (no unit conversion needed) */ + } + else if(is_unit_but) { + /* parse failed, this is a unit but so run replacements and parse again */ + char str_unit_convert[256]; + const int unit_type= uiButGetUnitType(but); + Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); + + BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert)); - if(ui_is_but_unit(but)) { /* ugly, use the draw string to get the value, this could cause problems if it includes some text which resolves to a unit */ bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), scene->unit.system, unit_type>>16); - } - - if(BPY_button_exec(C, str_unit_convert, &value)) { - value = ui_get_but_val(but); /* use its original value */ - if(str[0]) - return 0; + if(BPY_button_exec(C, str_unit_convert, &value, TRUE) != -1) { + ok= TRUE; + } } } + + if(ok == FALSE) { + return 0; + } #else value= atof(str); #endif // WITH_PYTHON |