Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-04-17 16:47:20 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-04-17 16:47:20 +0400
commit0862abf68bf1c9601080d4fb142c8f7edc6b300f (patch)
tree02a3c6fa59a2a78b0c6c1254fd22ac9bd9b18af5
parentd00f664ee0c042569900110db21d567c21c391db (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.
-rw-r--r--source/blender/editors/interface/interface.c33
-rw-r--r--source/blender/python/BPY_extern.h2
-rw-r--r--source/blender/python/intern/bpy_interface.c10
3 files changed, 30 insertions, 15 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
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index 7901957e5e4..e8796a6f8dd 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -86,7 +86,7 @@ void BPY_modules_load_user(struct bContext *C);
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() */
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 83c52464c9c..555b42eb6fb 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -471,7 +471,8 @@ void BPY_DECREF(void *pyob_ptr)
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 @@ int BPY_button_exec(bContext *C, const char *expr, double *value)
}
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);