Revision: 36206
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36206
Author:   campbellbarton
Date:     2011-04-18 03:27:15 +0000 (Mon, 18 Apr 2011)
Log Message:
-----------
fix for own mistake in recent commit: [#27000] Spotlight spot shape size, lamp 
object data - numerical entries are interpreted as radians though displayed in 
degrees in SVN 36199

now apply units after python evaluation for unit buttons.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface.c

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c  2011-04-18 
01:45:28 UTC (rev 36205)
+++ trunk/blender/source/blender/editors/interface/interface.c  2011-04-18 
03:27:15 UTC (rev 36206)
@@ -1541,6 +1541,52 @@
        }
 }
 
+#ifdef WITH_PYTHON
+
+static int ui_set_but_string_eval_num_unit(bContext *C, uiBut *but, const char 
*str, double *value)
+{
+       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));
+
+       /* 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);
+
+       return (BPY_button_exec(C, str_unit_convert, value, TRUE) != -1);
+}
+
+static int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char 
*str, double *value)
+{
+       int ok= FALSE;
+
+       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) {
+                       /* if the value parsed ok without unit conversion this 
button may still need a unit multiplier */
+                       if(is_unit_but) {
+                               char str_new[128];
+
+                               BLI_snprintf(str_new, sizeof(str_new), "%f", 
*value);
+                               ok= ui_set_but_string_eval_num_unit(C, but, 
str_new, value);
+                       }
+                       else {
+                               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 */
+                       ok= ui_set_but_string_eval_num_unit(C, but, str, value);
+               }
+       }
+
+       return ok;
+}
+
+#endif // WITH_PYTHON
+
 int ui_set_but_string(bContext *C, uiBut *but, const char *str)
 {
        if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
@@ -1601,32 +1647,7 @@
                double value;
 
 #ifdef WITH_PYTHON
-               int ok= FALSE;
-
-               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));
-
-                               /* 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, 
TRUE) != -1) {
-                                       ok= TRUE;
-                               }
-                       }
-               }
-
-               if(ok == FALSE) {
+               if(ui_set_but_string_eval_num(C, but, str, &value) == FALSE) {
                        return 0;
                }
 #else

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to