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>2021-04-12 14:39:56 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-04-13 08:28:43 +0300
commitf5060bc90118c88593fd213728bf58894fa6394c (patch)
treed58797c31faea554ee2075fcfc21d734d541083a /source/blender/editors/util/numinput.c
parent8d9fd0427dd6cf9556f2bb4415ead82c73300d32 (diff)
PyAPI: support retrieving the exception when running a string
- Optionally get the error as a single line. - Support access the error as an allocated string. - PyC_ExceptionBuffer_Simple was always printing to the `stdout` while PyC_ExceptionBuffer didn't, now either print to the output. Without this, callers are unable to do anything with the error string.
Diffstat (limited to 'source/blender/editors/util/numinput.c')
-rw-r--r--source/blender/editors/util/numinput.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c
index 91ec8546225..15d672dea56 100644
--- a/source/blender/editors/util/numinput.c
+++ b/source/blender/editors/util/numinput.c
@@ -29,6 +29,7 @@
#include "BLT_translation.h"
#include "BKE_context.h"
+#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_unit.h"
@@ -283,10 +284,15 @@ bool user_string_to_number(bContext *C,
const char *str,
const UnitSettings *unit,
int type,
- const char *error_prefix,
- double *r_value)
+ double *r_value,
+ const bool use_single_line_error,
+ char **r_error)
{
#ifdef WITH_PYTHON
+ struct BPy_RunErrInfo err_info = {
+ .use_single_line_error = use_single_line_error,
+ .r_string = r_error,
+ };
double unit_scale = BKE_scene_unit_scale(unit, type, 1.0);
if (BKE_unit_string_contains_unit(str, type)) {
char str_unit_convert[256];
@@ -294,10 +300,10 @@ bool user_string_to_number(bContext *C,
BKE_unit_replace_string(
str_unit_convert, sizeof(str_unit_convert), str, unit_scale, unit->system, type);
- return BPY_run_string_as_number(C, NULL, str_unit_convert, error_prefix, r_value);
+ return BPY_run_string_as_number(C, NULL, str_unit_convert, &err_info, r_value);
}
- int success = BPY_run_string_as_number(C, NULL, str, error_prefix, r_value);
+ int success = BPY_run_string_as_number(C, NULL, str, &err_info, r_value);
*r_value = BKE_unit_apply_preferred_unit(unit, type, *r_value);
*r_value /= unit_scale;
return success;
@@ -577,10 +583,19 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
if (n->str[0]) {
const float val_prev = n->val[idx];
Scene *sce = CTX_data_scene(C);
+ char *error = NULL;
double val;
int success = user_string_to_number(
- C, n->str, &sce->unit, n->unit_type[idx], IFACE_("Numeric input evaluation"), &val);
+ C, n->str, &sce->unit, n->unit_type[idx], &val, false, &error);
+
+ if (error) {
+ ReportList *reports = CTX_wm_reports(C);
+ printf("%s\n", error);
+ BKE_report(reports, RPT_ERROR, error);
+ BKE_report(reports, RPT_ERROR, IFACE_("Numeric input evaluation"));
+ MEM_freeN(error);
+ }
if (success) {
n->val[idx] = (float)val;