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 <noreply@anthropic.com>
This commit is contained in:
1 parent
9c171627d8
commit
a8c9a0376d
1 file changed
+10
-2
+10
-2
@@ -88,8 +88,16 @@ def dict_number(label, seq, key, **kwargs):
|
|||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
val = 0
|
val = 0
|
||||||
el = ui.number(label, value=val, **kwargs)
|
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
|
return el
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user