From 2e10af047ee507cc9b57ddbbccc1c14b673d7e49 Mon Sep 17 00:00:00 2001 From: Oliver Hensby Date: Thu, 23 Nov 2023 11:07:22 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Show=20bn=5Fadd=5Ffrom=5Fzer?= =?UTF-8?q?o=20when=20removing=20last=20box?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipyautoui/custom/iterable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipyautoui/custom/iterable.py b/src/ipyautoui/custom/iterable.py index 54e25477..24d82360 100644 --- a/src/ipyautoui/custom/iterable.py +++ b/src/ipyautoui/custom/iterable.py @@ -369,7 +369,7 @@ def remove_row(self, key=None, fn_onremove=None): ) return None if len(self.boxes) <= 1: - pass + self.display_bn_add_from_zero(display=True) if key is None: print("key is None") key = self.iterable[-1].key From 52aae7cb6df1bd8cad30e86bd848131353fddec4 Mon Sep 17 00:00:00 2001 From: Oliver Hensby Date: Thu, 23 Nov 2023 11:07:38 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20Format=20with=20black?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipyautoui/custom/iterable.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ipyautoui/custom/iterable.py b/src/ipyautoui/custom/iterable.py index 24d82360..6d046e95 100644 --- a/src/ipyautoui/custom/iterable.py +++ b/src/ipyautoui/custom/iterable.py @@ -188,7 +188,10 @@ def _type(self, proposal): @tr.observe("length") def _length(self, on_change): if self.length == 0: - if self.add_remove_controls == ItemControl.append_only or self.add_remove_controls == ItemControl.append_only: + if ( + self.add_remove_controls == ItemControl.append_only + or self.add_remove_controls == ItemControl.append_only + ): self.display_bn_add_from_zero(True) else: pass @@ -223,9 +226,16 @@ def _add_remove_controls(self, on_change): def _align_horizontal(self, on_change): flip(self.bx_boxes, self.align_horizontal) - @property + @property def map_key_value(self): - return {b.key: (lambda w: w.value if hasattr(w, "value") or hasattr(w, "_value") else None)(b.widget.value) for b in self.boxes} + return { + b.key: ( + lambda w: w.value + if hasattr(w, "value") or hasattr(w, "_value") + else None + )(b.widget.value) + for b in self.boxes + } def display_bn_add_from_zero(self, display: bool): if display: @@ -254,7 +264,7 @@ def __init__(self, **kwargs): self._post_init(**kwargs) def _post_init(self, **kwargs): - pass # NOTE: this can be overwritten to provide customisation + pass # NOTE: this can be overwritten to provide customisation def _init_controls(self): [self._init_row_controls(key=i.key) for i in self.boxes] @@ -383,7 +393,6 @@ def remove_row(self, key=None, fn_onremove=None): self._watch_validate_change("") - class AutoArray(Array): allOf = tr.List(allow_none=True, default_value=None) items = tr.Dict(allow_none=True, default_value=None)