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>2020-07-27 06:46:58 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-07-27 14:00:50 +0300
commit565d7f75ccfe955821991793fcd6335e58b6825b (patch)
treef5526fc547c112a6694d187504ae1ac739e1933c /source/blender/editors/interface/interface.c
parent7beef1fd33b37f62d14a7de7150cfc7b0d88f159 (diff)
UI: improve errors when evaluating a number button fails
Showing the Python error without any explanation is often not enough information and doesn't hint that the error was in the user input. The error report from a invalid expression such as '..1' used to be: ('invalid syntax', ('<string>', 1, 1, '..1')) Now reads: Error evaluating number, see Info editor for details: invalid syntax Address issue raised by T78913.
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r--source/blender/editors/interface/interface.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 8c4f337f2d9..9441e48ef24 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2800,10 +2800,16 @@ char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size)
return str;
}
+/**
+ * Report a generic error prefix when evaluating a string with #BPY_execute_string_as_number
+ * as the Python error on it's own doesn't provide enough context.
+ */
+#define UI_NUMBER_EVAL_ERROR_PREFIX IFACE_("Error evaluating number, see Info editor for details")
+
static bool ui_number_from_string_units(
bContext *C, const char *str, const int unit_type, const UnitSettings *unit, double *r_value)
{
- return user_string_to_number(C, str, unit, unit_type, r_value);
+ return user_string_to_number(C, str, unit, unit_type, UI_NUMBER_EVAL_ERROR_PREFIX, r_value);
}
static bool ui_number_from_string_units_with_but(bContext *C,
@@ -2820,7 +2826,7 @@ static bool ui_number_from_string(bContext *C, const char *str, double *r_value)
{
bool ok;
#ifdef WITH_PYTHON
- ok = BPY_execute_string_as_number(C, NULL, str, true, r_value);
+ ok = BPY_execute_string_as_number(C, NULL, str, UI_NUMBER_EVAL_ERROR_PREFIX, r_value);
#else
UNUSED_VARS(C);
*r_value = atof(str);