From a8c9a0376dd0be12542b65d67cff3c5a62decfdc Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Thu, 26 Feb 2026 16:30:20 +0100 Subject: [PATCH] Fix number inputs saving whole numbers as floats in JSON NiceGUI's ui.number returns float values, so seeds, steps, dimensions etc. were being stored as floats (e.g. 42.0) instead of integers. Co-Authored-By: Claude Opus 4.6 --- tab_batch_ng.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tab_batch_ng.py b/tab_batch_ng.py index 257dd97..4a23c9d 100644 --- a/tab_batch_ng.py +++ b/tab_batch_ng.py @@ -88,8 +88,16 @@ def dict_number(label, seq, key, **kwargs): except (ValueError, TypeError): val = 0 el = ui.number(label, value=val, **kwargs) - el.on('blur', lambda e, k=key: seq.__setitem__( - k, e.sender.value if e.sender.value is not None else 0)) + + def _on_blur(e, k=key): + v = e.sender.value + if v is None: + v = 0 + elif isinstance(v, float) and v == int(v): + v = int(v) + seq[k] = v + + el.on('blur', _on_blur) return el