[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36199] trunk/blender/source/blender: 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 .
Campbell Barton
ideasman42 at gmail.com
Sun Apr 17 14:47:20 CEST 2011
Revision: 36199
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36199
Author: campbellbarton
Date: 2011-04-17 12:47:20 +0000 (Sun, 17 Apr 2011)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/source/blender/editors/interface/interface.c
trunk/blender/source/blender/python/BPY_extern.h
trunk/blender/source/blender/python/intern/bpy_interface.c
Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c 2011-04-17 12:13:02 UTC (rev 36198)
+++ trunk/blender/source/blender/editors/interface/interface.c 2011-04-17 12:47:20 UTC (rev 36199)
@@ -1601,25 +1601,34 @@
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);
- if(ui_is_but_unit(but)) {
+ 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)) {
- 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
Modified: trunk/blender/source/blender/python/BPY_extern.h
===================================================================
--- trunk/blender/source/blender/python/BPY_extern.h 2011-04-17 12:13:02 UTC (rev 36198)
+++ trunk/blender/source/blender/python/BPY_extern.h 2011-04-17 12:47:20 UTC (rev 36199)
@@ -86,7 +86,7 @@
void BPY_driver_reset(void);
float BPY_driver_exec(struct ChannelDriver *driver);
-int BPY_button_exec(struct bContext *C, const char *expr, double *value);
+int BPY_button_exec(struct bContext *C, const char *expr, double *value, const short verbose);
int BPY_string_exec(struct bContext *C, const char *expr);
void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c 2011-04-17 12:13:02 UTC (rev 36198)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c 2011-04-17 12:47:20 UTC (rev 36199)
@@ -471,7 +471,8 @@
PyGILState_Release(gilstate);
}
-int BPY_button_exec(bContext *C, const char *expr, double *value)
+/* return -1 on error, else 0 */
+int BPY_button_exec(bContext *C, const char *expr, double *value, const short verbose)
{
PyGILState_STATE gilstate;
PyObject *py_dict, *mod, *retval;
@@ -536,7 +537,12 @@
}
if(error_ret) {
- BPy_errors_to_report(CTX_wm_reports(C));
+ if(verbose) {
+ BPy_errors_to_report(CTX_wm_reports(C));
+ }
+ else {
+ PyErr_Clear();
+ }
}
PyC_MainModule_Backup(&main_mod);
More information about the Bf-blender-cvs
mailing list