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/util/numinput.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/util/numinput.c')
-rw-r--r--source/blender/editors/util/numinput.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c
index 3c747a29361..384da6fb931 100644
--- a/source/blender/editors/util/numinput.c
+++ b/source/blender/editors/util/numinput.c
@@ -26,6 +26,8 @@
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
+#include "BLT_translation.h"
+
#include "BKE_context.h"
#include "BKE_scene.h"
#include "BKE_unit.h"
@@ -277,8 +279,12 @@ static bool editstr_insert_at_cursor(NumInput *n, const char *buf, const int buf
return true;
}
-bool user_string_to_number(
- bContext *C, const char *str, const UnitSettings *unit, int type, double *r_value)
+bool user_string_to_number(bContext *C,
+ const char *str,
+ const UnitSettings *unit,
+ int type,
+ const char *error_prefix,
+ double *r_value)
{
#ifdef WITH_PYTHON
double unit_scale = BKE_scene_unit_scale(unit, type, 1.0);
@@ -288,10 +294,10 @@ bool user_string_to_number(
bUnit_ReplaceString(
str_unit_convert, sizeof(str_unit_convert), str, unit_scale, unit->system, type);
- return BPY_execute_string_as_number(C, NULL, str_unit_convert, true, r_value);
+ return BPY_execute_string_as_number(C, NULL, str_unit_convert, error_prefix, r_value);
}
- int success = BPY_execute_string_as_number(C, NULL, str, true, r_value);
+ int success = BPY_execute_string_as_number(C, NULL, str, error_prefix, r_value);
*r_value *= bUnit_PreferredInputUnitScalar(unit, type);
*r_value /= unit_scale;
return success;
@@ -573,7 +579,8 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
Scene *sce = CTX_data_scene(C);
double val;
- int success = user_string_to_number(C, n->str, &sce->unit, n->unit_type[idx], &val);
+ int success = user_string_to_number(
+ C, n->str, &sce->unit, n->unit_type[idx], IFACE_("Numeric input evaluation"), &val);
if (success) {
n->val[idx] = (float)val;