ex4nicegui 0.7.1__py3-none-any.whl → 0.8.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. ex4nicegui/reactive/EChartsComponent/ECharts.js +2 -3
  2. ex4nicegui/reactive/EChartsComponent/ECharts.py +2 -4
  3. ex4nicegui/reactive/__init__.py +2 -1
  4. ex4nicegui/reactive/base.py +108 -50
  5. ex4nicegui/reactive/mermaid/mermaid.py +2 -5
  6. ex4nicegui/reactive/mixins/backgroundColor.py +4 -8
  7. ex4nicegui/reactive/mixins/disableable.py +4 -8
  8. ex4nicegui/reactive/mixins/flexLayout.py +51 -0
  9. ex4nicegui/reactive/mixins/textColor.py +8 -10
  10. ex4nicegui/reactive/mixins/value_element.py +27 -0
  11. ex4nicegui/reactive/officials/card.py +32 -2
  12. ex4nicegui/reactive/officials/checkbox.py +7 -12
  13. ex4nicegui/reactive/officials/chip.py +11 -1
  14. ex4nicegui/reactive/officials/circular_progress.py +7 -11
  15. ex4nicegui/reactive/officials/color_picker.py +4 -10
  16. ex4nicegui/reactive/officials/column.py +19 -11
  17. ex4nicegui/reactive/officials/date.py +4 -11
  18. ex4nicegui/reactive/officials/dialog.py +4 -11
  19. ex4nicegui/reactive/officials/echarts.py +9 -7
  20. ex4nicegui/reactive/officials/expansion.py +4 -11
  21. ex4nicegui/reactive/officials/input.py +13 -13
  22. ex4nicegui/reactive/officials/knob.py +4 -13
  23. ex4nicegui/reactive/officials/linear_progress.py +6 -11
  24. ex4nicegui/reactive/officials/number.py +7 -11
  25. ex4nicegui/reactive/officials/radio.py +4 -12
  26. ex4nicegui/reactive/officials/row.py +18 -11
  27. ex4nicegui/reactive/officials/slider.py +4 -12
  28. ex4nicegui/reactive/officials/switch.py +5 -12
  29. ex4nicegui/reactive/officials/tab_panels.py +4 -8
  30. ex4nicegui/reactive/officials/tabs.py +4 -9
  31. ex4nicegui/reactive/officials/textarea.py +6 -12
  32. ex4nicegui/reactive/services/reactive_service.py +2 -1
  33. ex4nicegui/reactive/vfor.py +4 -0
  34. ex4nicegui/reactive/view_model.py +147 -6
  35. ex4nicegui/utils/proxy/__init__.py +19 -0
  36. ex4nicegui/utils/proxy/base.py +9 -0
  37. ex4nicegui/utils/proxy/bool.py +58 -0
  38. ex4nicegui/utils/proxy/date.py +88 -0
  39. ex4nicegui/utils/proxy/descriptor.py +126 -0
  40. ex4nicegui/utils/proxy/dict.py +110 -0
  41. ex4nicegui/utils/proxy/float.py +153 -0
  42. ex4nicegui/utils/proxy/int.py +223 -0
  43. ex4nicegui/utils/proxy/list.py +147 -0
  44. ex4nicegui/utils/proxy/string.py +430 -0
  45. ex4nicegui/utils/proxy/utils.py +6 -0
  46. ex4nicegui/utils/signals.py +9 -1
  47. {ex4nicegui-0.7.1.dist-info → ex4nicegui-0.8.1.dist-info}/METADATA +497 -244
  48. {ex4nicegui-0.7.1.dist-info → ex4nicegui-0.8.1.dist-info}/RECORD +50 -37
  49. {ex4nicegui-0.7.1.dist-info → ex4nicegui-0.8.1.dist-info}/LICENSE +0 -0
  50. {ex4nicegui-0.7.1.dist-info → ex4nicegui-0.8.1.dist-info}/WHEEL +0 -0
@@ -6,15 +6,18 @@ from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
6
6
  from ex4nicegui.utils.signals import (
7
7
  TGetterOrReadonlyRef,
8
8
  _TMaybeRef as TMaybeRef,
9
- to_value,
10
9
  )
11
10
  from nicegui import ui
12
11
  from .base import BindableUi, DisableableMixin
13
12
  from ex4nicegui.reactive.mixins.backgroundColor import BackgroundColorableMixin
13
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
14
14
 
15
15
 
16
16
  class CircularProgressBindableUi(
17
- BindableUi[ui.circular_progress], DisableableMixin, BackgroundColorableMixin
17
+ BindableUi[ui.circular_progress],
18
+ DisableableMixin,
19
+ BackgroundColorableMixin,
20
+ ValueElementMixin[float],
18
21
  ):
19
22
  def __init__(
20
23
  self,
@@ -50,16 +53,9 @@ class CircularProgressBindableUi(
50
53
  return self.element.value
51
54
 
52
55
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
53
- if prop == "value":
54
- return self.bind_value(value)
56
+ if ValueElementMixin._bind_specified_props(self, prop, value):
57
+ return self
55
58
  if prop == "color":
56
59
  return self.bind_color(value)
57
60
 
58
61
  return super().bind_prop(prop, value)
59
-
60
- def bind_value(self, value: TGetterOrReadonlyRef[float]):
61
- @self._ui_signal_on(value)
62
- def _():
63
- self.element.set_value(to_value(value))
64
-
65
- return self
@@ -5,6 +5,7 @@ from typing import (
5
5
  cast,
6
6
  )
7
7
  from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
8
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
8
9
 
9
10
  from ex4nicegui.utils.signals import (
10
11
  TGetterOrReadonlyRef,
@@ -18,7 +19,7 @@ from nicegui.events import handle_event
18
19
  from .base import BindableUi
19
20
 
20
21
 
21
- class ColorPickerBindableUi(BindableUi[ui.color_picker]):
22
+ class ColorPickerBindableUi(BindableUi[ui.color_picker], ValueElementMixin[bool]):
22
23
  def __init__(
23
24
  self,
24
25
  color: TMaybeRef[str] = "",
@@ -69,8 +70,8 @@ class ColorPickerBindableUi(BindableUi[ui.color_picker]):
69
70
  return self.element.value
70
71
 
71
72
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
72
- if prop == "value":
73
- return self.bind_value(value)
73
+ if ValueElementMixin._bind_specified_props(self, prop, value):
74
+ return self
74
75
 
75
76
  return super().bind_prop(prop, value)
76
77
 
@@ -81,13 +82,6 @@ class ColorPickerBindableUi(BindableUi[ui.color_picker]):
81
82
 
82
83
  return self
83
84
 
84
- def bind_value(self, value: TGetterOrReadonlyRef[bool]):
85
- @self._ui_signal_on(value)
86
- def _():
87
- self.element.set_value(to_value(value))
88
-
89
- return self
90
-
91
85
 
92
86
  class ColorPickerLazyBindableUi(ColorPickerBindableUi):
93
87
  def __init__(
@@ -1,18 +1,27 @@
1
1
  from typing import (
2
2
  Any,
3
+ Literal,
4
+ Optional,
3
5
  )
4
6
  from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
7
+ from ex4nicegui.reactive.mixins.flexLayout import FlexAlignItemsMixin, FlexWrapMixin
5
8
  from ex4nicegui.utils.signals import (
6
- TGetterOrReadonlyRef,
7
- _TMaybeRef as TMaybeRef,
9
+ TMaybeRef,
8
10
  )
9
11
  from nicegui import ui
10
12
  from .base import BindableUi
11
13
 
12
14
 
13
- class ColumnBindableUi(BindableUi[ui.column]):
14
- def __init__(self, *, wrap: TMaybeRef[bool] = True) -> None:
15
- pc = ParameterClassifier(locals(), maybeRefs=["wrap"], events=[])
15
+ class ColumnBindableUi(BindableUi[ui.column], FlexAlignItemsMixin, FlexWrapMixin):
16
+ def __init__(
17
+ self,
18
+ *,
19
+ wrap: TMaybeRef[bool] = True,
20
+ align_items: Optional[
21
+ TMaybeRef[Literal["start", "end", "center", "baseline", "stretch"]]
22
+ ] = None,
23
+ ) -> None:
24
+ pc = ParameterClassifier(locals(), maybeRefs=["wrap", "align_items"], events=[])
16
25
  element = ui.column(**pc.get_values_kws())
17
26
 
18
27
  super().__init__(element)
@@ -20,15 +29,14 @@ class ColumnBindableUi(BindableUi[ui.column]):
20
29
  for key, value in pc.get_bindings().items():
21
30
  self.bind_prop(key, value) # type: ignore
22
31
 
23
- def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
24
- if prop == "wrap":
25
- return self.bind_wrap(value)
32
+ def bind_prop(self, prop: str, value: TMaybeRef):
33
+ if FlexAlignItemsMixin._bind_specified_props(self, prop, value):
34
+ return self
35
+ if FlexWrapMixin._bind_specified_props(self, prop, value):
36
+ return self
26
37
 
27
38
  return super().bind_prop(prop, value)
28
39
 
29
- def bind_wrap(self, value: TGetterOrReadonlyRef):
30
- self.bind_classes({"wrap": value})
31
-
32
40
  def __enter__(self):
33
41
  self.element.__enter__()
34
42
  return self
@@ -1,11 +1,11 @@
1
1
  from typing import Any, Callable, List, Optional, TypeVar
2
2
  from typing_extensions import TypedDict
3
3
  from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
4
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
4
5
 
5
6
  from ex4nicegui.utils.signals import (
6
7
  TGetterOrReadonlyRef,
7
8
  _TMaybeRef as TMaybeRef,
8
- to_value,
9
9
  )
10
10
  from nicegui import ui
11
11
  from .base import BindableUi
@@ -18,7 +18,7 @@ _TDateValue = TypeVar(
18
18
  )
19
19
 
20
20
 
21
- class DateBindableUi(BindableUi[ui.date]):
21
+ class DateBindableUi(BindableUi[ui.date], ValueElementMixin[_TDateValue]):
22
22
  def __init__(
23
23
  self,
24
24
  value: Optional[TMaybeRef[_TDateValue]] = None,
@@ -63,14 +63,7 @@ class DateBindableUi(BindableUi[ui.date]):
63
63
  return self.element.value
64
64
 
65
65
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
66
- if prop == "value":
67
- return self.bind_value(value)
66
+ if ValueElementMixin._bind_specified_props(self, prop, value):
67
+ return self
68
68
 
69
69
  return super().bind_prop(prop, value)
70
-
71
- def bind_value(self, value: TGetterOrReadonlyRef[bool]):
72
- @self._ui_signal_on(value)
73
- def _():
74
- self.element.set_value(to_value(value))
75
-
76
- return self
@@ -1,15 +1,15 @@
1
1
  from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
2
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
2
3
  from ex4nicegui.utils.signals import (
3
4
  _TMaybeRef as TMaybeRef,
4
5
  is_setter_ref,
5
- to_value,
6
6
  TGetterOrReadonlyRef,
7
7
  )
8
8
  from nicegui import ui
9
9
  from .base import BindableUi
10
10
 
11
11
 
12
- class DialogBindableUi(BindableUi[ui.dialog]):
12
+ class DialogBindableUi(BindableUi[ui.dialog], ValueElementMixin[bool]):
13
13
  def __init__(
14
14
  self,
15
15
  *,
@@ -36,14 +36,7 @@ class DialogBindableUi(BindableUi[ui.dialog]):
36
36
  return self.element.value
37
37
 
38
38
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
39
- if prop == "value":
40
- return self.bind_value(value)
39
+ if ValueElementMixin._bind_specified_props(self, prop, value):
40
+ return self
41
41
 
42
42
  return super().bind_prop(prop, value)
43
-
44
- def bind_value(self, value: TGetterOrReadonlyRef[float]):
45
- @self._ui_signal_on(value)
46
- def _():
47
- self.element.set_value(to_value(value))
48
-
49
- return self
@@ -34,7 +34,7 @@ class EChartsBindableUi(BindableUi[echarts]):
34
34
 
35
35
  value_kws = pc.get_values_kws()
36
36
 
37
- element = echarts(**value_kws).classes("grow self-stretch h-[16rem]")
37
+ element = echarts(**value_kws).classes("nicegui-echart")
38
38
 
39
39
  super().__init__(element) # type: ignore
40
40
 
@@ -94,13 +94,14 @@ class EChartsBindableUi(BindableUi[echarts]):
94
94
 
95
95
  @classmethod
96
96
  def from_pyecharts(cls, chart: TMaybeRef):
97
- if is_ref(chart):
97
+ if is_ref(chart) or callable(chart):
98
98
 
99
99
  @ref_computed
100
100
  def chart_opt():
101
- if not bool(chart.value):
101
+ chart_value = to_value(chart)
102
+ if not bool(chart_value):
102
103
  return {}
103
- return PyechartsUtils._chart2opts(chart.value)
104
+ return PyechartsUtils._chart2opts(chart_value)
104
105
 
105
106
  return cls(chart_opt)
106
107
 
@@ -228,7 +229,10 @@ class EChartsBindableUi(BindableUi[echarts]):
228
229
  return self
229
230
 
230
231
  def run_chart_method(
231
- self, name: str, *args, timeout: float = 1, check_interval: float = 0.01
232
+ self,
233
+ name: str,
234
+ *args,
235
+ timeout: float = 1,
232
236
  ) -> AwaitableResponse:
233
237
  """Run a method of the JSONEditor instance.
234
238
 
@@ -240,7 +244,6 @@ class EChartsBindableUi(BindableUi[echarts]):
240
244
  :param name: name of the method (a prefix ":" indicates that the arguments are JavaScript expressions)
241
245
  :param args: arguments to pass to the method (Python objects or JavaScript expressions)
242
246
  :param timeout: timeout in seconds (default: 1 second)
243
- :param check_interval: interval in seconds to check for a response (default: 0.01 seconds)
244
247
 
245
248
  :return: AwaitableResponse that can be awaited to get the result of the method call
246
249
  """
@@ -248,7 +251,6 @@ class EChartsBindableUi(BindableUi[echarts]):
248
251
  name,
249
252
  *args,
250
253
  timeout=timeout,
251
- check_interval=check_interval,
252
254
  )
253
255
 
254
256
 
@@ -1,15 +1,15 @@
1
1
  from typing import Any, Optional, Callable
2
2
  from nicegui import ui
3
3
  from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
4
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
4
5
  from ex4nicegui.utils.signals import (
5
6
  TGetterOrReadonlyRef,
6
7
  _TMaybeRef as TMaybeRef,
7
- to_value,
8
8
  )
9
9
  from .base import BindableUi
10
10
 
11
11
 
12
- class ExpansionBindableUi(BindableUi[ui.expansion]):
12
+ class ExpansionBindableUi(BindableUi[ui.expansion], ValueElementMixin[bool]):
13
13
  def __init__(
14
14
  self,
15
15
  text: Optional[TMaybeRef[str]] = None,
@@ -46,18 +46,11 @@ class ExpansionBindableUi(BindableUi[ui.expansion]):
46
46
  return self.element.value
47
47
 
48
48
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
49
- if prop == "value":
50
- return self.bind_value(value)
49
+ if ValueElementMixin._bind_specified_props(self, prop, value):
50
+ return self
51
51
 
52
52
  return super().bind_prop(prop, value)
53
53
 
54
- def bind_value(self, value: TGetterOrReadonlyRef):
55
- @self._ui_signal_on(value)
56
- def _():
57
- self.element.set_value(to_value(value))
58
-
59
- return self
60
-
61
54
  def __enter__(self):
62
55
  self.element.__enter__()
63
56
  return self
@@ -1,4 +1,4 @@
1
- from typing import Any, Callable, List, Optional, Dict, cast
1
+ from typing import Any, Callable, List, Optional, Dict, Union, cast
2
2
 
3
3
 
4
4
  from ex4nicegui.utils.signals import (
@@ -13,9 +13,14 @@ from nicegui import ui
13
13
  from nicegui.events import handle_event
14
14
  from .base import BindableUi, DisableableMixin
15
15
  from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
16
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
16
17
 
17
18
 
18
- class InputBindableUi(BindableUi[ui.input], DisableableMixin):
19
+ class InputBindableUi(
20
+ BindableUi[ui.input],
21
+ DisableableMixin,
22
+ ValueElementMixin[str],
23
+ ):
19
24
  def __init__(
20
25
  self,
21
26
  label: Optional[TMaybeRef[str]] = None,
@@ -26,7 +31,9 @@ class InputBindableUi(BindableUi[ui.input], DisableableMixin):
26
31
  password_toggle_button: TMaybeRef[bool] = False,
27
32
  on_change: Optional[Callable[..., Any]] = None,
28
33
  autocomplete: Optional[TMaybeRef[List[str]]] = None,
29
- validation: Dict[str, Callable[..., bool]] = {},
34
+ validation: Optional[
35
+ Union[Callable[..., Optional[str]], Dict[str, Callable[..., bool]]]
36
+ ] = None,
30
37
  ) -> None:
31
38
  pc = ParameterClassifier(
32
39
  locals(),
@@ -52,20 +59,13 @@ class InputBindableUi(BindableUi[ui.input], DisableableMixin):
52
59
  self.bind_prop(key, value) # type: ignore
53
60
 
54
61
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
55
- if prop == "value":
56
- return self.bind_value(value)
62
+ if ValueElementMixin._bind_specified_props(self, prop, value):
63
+ return self
57
64
  if prop == "password":
58
65
  return self.bind_password(value)
59
66
 
60
67
  return super().bind_prop(prop, value)
61
68
 
62
- def bind_value(self, value: TGetterOrReadonlyRef[str]):
63
- @self._ui_signal_on(value)
64
- def _():
65
- self.element.set_value(to_value(value))
66
-
67
- return self
68
-
69
69
  def bind_password(self, password: TGetterOrReadonlyRef[bool]):
70
70
  @self._ui_signal_on(password)
71
71
  def _():
@@ -90,7 +90,7 @@ class LazyInputBindableUi(InputBindableUi):
90
90
  password_toggle_button: TMaybeRef[bool] = False,
91
91
  on_change: Optional[Callable[..., Any]] = None,
92
92
  autocomplete: Optional[TMaybeRef[List[str]]] = None,
93
- validation: Dict[str, Callable[..., bool]] = {},
93
+ validation: Optional[Dict[str, Callable[..., bool]]] = None,
94
94
  ) -> None:
95
95
  org_value = value
96
96
  is_setter_value = is_setter_ref(value)
@@ -6,18 +6,16 @@ from typing import (
6
6
  from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
7
7
  from ex4nicegui.utils.signals import (
8
8
  _TMaybeRef as TMaybeRef,
9
- to_value,
10
9
  TGetterOrReadonlyRef,
11
10
  )
12
11
  from nicegui import ui
13
12
  from .base import BindableUi, DisableableMixin
14
13
  from ex4nicegui.reactive.mixins.textColor import TextColorableMixin
14
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
15
15
 
16
16
 
17
17
  class KnobBindableUi(
18
- BindableUi[ui.knob],
19
- DisableableMixin,
20
- TextColorableMixin,
18
+ BindableUi[ui.knob], DisableableMixin, TextColorableMixin, ValueElementMixin[float]
21
19
  ):
22
20
  def __init__(
23
21
  self,
@@ -62,16 +60,9 @@ class KnobBindableUi(
62
60
  return self.element.value
63
61
 
64
62
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
65
- if prop == "value":
66
- return self.bind_value(value)
63
+ if ValueElementMixin._bind_specified_props(self, prop, value):
64
+ return self
67
65
  if prop == "color":
68
66
  return self.bind_color(value)
69
67
 
70
68
  return super().bind_prop(prop, value)
71
-
72
- def bind_value(self, value: TGetterOrReadonlyRef[float]):
73
- @self._ui_signal_on(value)
74
- def _():
75
- self.element.set_value(to_value(value))
76
-
77
- return self
@@ -5,15 +5,17 @@ from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
5
5
  from ex4nicegui.utils.signals import (
6
6
  TGetterOrReadonlyRef,
7
7
  _TMaybeRef as TMaybeRef,
8
- to_value,
9
8
  )
10
9
  from nicegui import ui
11
10
 
12
11
  from .base import BindableUi
13
12
  from ex4nicegui.reactive.mixins.textColor import TextColorableMixin
13
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
14
14
 
15
15
 
16
- class LinearProgressBindableUi(BindableUi[ui.linear_progress], TextColorableMixin):
16
+ class LinearProgressBindableUi(
17
+ BindableUi[ui.linear_progress], TextColorableMixin, ValueElementMixin[float]
18
+ ):
17
19
  def __init__(
18
20
  self,
19
21
  value: TMaybeRef[float] = 0.0,
@@ -47,17 +49,10 @@ class LinearProgressBindableUi(BindableUi[ui.linear_progress], TextColorableMixi
47
49
  return self.element.value
48
50
 
49
51
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
50
- if prop == "value":
51
- return self.bind_value(value)
52
+ if ValueElementMixin._bind_specified_props(self, prop, value):
53
+ return self
52
54
 
53
55
  if prop == "color":
54
56
  return self.bind_color(value)
55
57
 
56
58
  return super().bind_prop(prop, value)
57
-
58
- def bind_value(self, value: TGetterOrReadonlyRef):
59
- @self._ui_signal_on(value)
60
- def _():
61
- self.element.set_value(to_value(value))
62
-
63
- return self
@@ -7,6 +7,7 @@ from typing import (
7
7
  Union,
8
8
  )
9
9
  from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
10
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
10
11
  from ex4nicegui.utils.signals import (
11
12
  TGetterOrReadonlyRef,
12
13
  _TMaybeRef as TMaybeRef,
@@ -22,7 +23,7 @@ def _default_vmodel_args_getter(e):
22
23
  return e.sender.value
23
24
 
24
25
 
25
- class NumberBindableUi(BindableUi[ui.number]):
26
+ class NumberBindableUi(BindableUi[ui.number], ValueElementMixin[Union[float, int]]):
26
27
  def __init__(
27
28
  self,
28
29
  label: Optional[TMaybeRef[str]] = None,
@@ -37,7 +38,9 @@ class NumberBindableUi(BindableUi[ui.number]):
37
38
  suffix: Optional[TMaybeRef[str]] = None,
38
39
  format: Optional[TMaybeRef[str]] = None,
39
40
  on_change: Optional[Callable[..., Any]] = None,
40
- validation: Dict[str, Callable[..., bool]] = {},
41
+ validation: Optional[
42
+ Union[Callable[..., Optional[str]], Dict[str, Callable[..., bool]]]
43
+ ] = None,
41
44
  ) -> None:
42
45
  pc = ParameterClassifier(
43
46
  locals(),
@@ -71,21 +74,14 @@ class NumberBindableUi(BindableUi[ui.number]):
71
74
  return self.element.value
72
75
 
73
76
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
74
- if prop == "value":
75
- return self.bind_value(value)
77
+ if ValueElementMixin._bind_specified_props(self, prop, value):
78
+ return self
76
79
 
77
80
  if prop == "precision":
78
81
  return self._bind_precision(value)
79
82
 
80
83
  return super().bind_prop(prop, value)
81
84
 
82
- def bind_value(self, value: TGetterOrReadonlyRef[float]):
83
- @self._ui_signal_on(value)
84
- def _():
85
- self.element.set_value(to_value(value))
86
-
87
- return self
88
-
89
85
  def _bind_precision(self, precision: TGetterOrReadonlyRef[int]):
90
86
  @self._ui_signal_on(precision)
91
87
  def _():
@@ -4,7 +4,6 @@ from typing import (
4
4
  List,
5
5
  Optional,
6
6
  TypeVar,
7
- cast,
8
7
  Dict,
9
8
  Union,
10
9
  )
@@ -15,13 +14,13 @@ from ex4nicegui.utils.signals import (
15
14
  to_value,
16
15
  )
17
16
  from nicegui import ui
18
- from nicegui.elements.mixins.value_element import ValueElement
17
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
19
18
  from .base import BindableUi
20
19
 
21
20
  T = TypeVar("T")
22
21
 
23
22
 
24
- class RadioBindableUi(BindableUi[ui.radio]):
23
+ class RadioBindableUi(BindableUi[ui.radio], ValueElementMixin[Any]):
25
24
  def __init__(
26
25
  self,
27
26
  options: Union[TMaybeRef[List], TMaybeRef[Dict]],
@@ -52,8 +51,8 @@ class RadioBindableUi(BindableUi[ui.radio]):
52
51
  return self.element.value
53
52
 
54
53
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
55
- if prop == "value":
56
- return self.bind_value(value)
54
+ if ValueElementMixin._bind_specified_props(self, prop, value):
55
+ return self
57
56
 
58
57
  if prop == "options":
59
58
  return self.bind_options(value)
@@ -66,10 +65,3 @@ class RadioBindableUi(BindableUi[ui.radio]):
66
65
  self.element.set_options(to_value(options))
67
66
 
68
67
  return self
69
-
70
- def bind_value(self, value: TGetterOrReadonlyRef):
71
- @self._ui_signal_on(value)
72
- def _():
73
- cast(ValueElement, self.element).set_value(to_value(value))
74
-
75
- return self
@@ -1,17 +1,25 @@
1
1
  from typing import (
2
2
  Any,
3
+ Literal,
4
+ Optional,
3
5
  )
4
6
  from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
5
- from ex4nicegui.utils.signals import (
6
- _TMaybeRef as TMaybeRef,
7
- )
7
+ from ex4nicegui.reactive.mixins.flexLayout import FlexAlignItemsMixin, FlexWrapMixin
8
+ from ex4nicegui.utils.signals import TMaybeRef
8
9
  from nicegui import ui
9
10
  from .base import BindableUi
10
11
 
11
12
 
12
- class RowBindableUi(BindableUi[ui.row]):
13
- def __init__(self, *, wrap: TMaybeRef[bool] = True) -> None:
14
- pc = ParameterClassifier(locals(), maybeRefs=["wrap"], events=[])
13
+ class RowBindableUi(BindableUi[ui.row], FlexAlignItemsMixin, FlexWrapMixin):
14
+ def __init__(
15
+ self,
16
+ *,
17
+ wrap: TMaybeRef[bool] = True,
18
+ align_items: Optional[
19
+ TMaybeRef[Literal["start", "end", "center", "baseline", "stretch"]]
20
+ ] = None,
21
+ ) -> None:
22
+ pc = ParameterClassifier(locals(), maybeRefs=["wrap", "align_items"], events=[])
15
23
  element = ui.row(**pc.get_values_kws())
16
24
 
17
25
  super().__init__(element)
@@ -19,14 +27,13 @@ class RowBindableUi(BindableUi[ui.row]):
19
27
  self.bind_prop(key, value) # type: ignore
20
28
 
21
29
  def bind_prop(self, prop: str, value: TMaybeRef):
22
- if prop == "wrap":
23
- return self.bind_wrap(value)
30
+ if FlexAlignItemsMixin._bind_specified_props(self, prop, value):
31
+ return self
32
+ if FlexWrapMixin._bind_specified_props(self, prop, value):
33
+ return self
24
34
 
25
35
  return super().bind_prop(prop, value)
26
36
 
27
- def bind_wrap(self, value: TMaybeRef):
28
- self.bind_classes({"wrap": value})
29
-
30
37
  def __enter__(self):
31
38
  self.element.__enter__()
32
39
  return self
@@ -16,14 +16,14 @@ from ex4nicegui.utils.signals import (
16
16
  from nicegui import ui
17
17
  from nicegui.events import handle_event
18
18
  from .base import BindableUi, DisableableMixin
19
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
19
20
 
20
21
 
21
22
  _TSliderValue = TypeVar("_TSliderValue", float, int, None)
22
23
 
23
24
 
24
25
  class SliderBindableUi(
25
- BindableUi[ui.slider],
26
- DisableableMixin,
26
+ BindableUi[ui.slider], DisableableMixin, ValueElementMixin[_TSliderValue]
27
27
  ):
28
28
  def __init__(
29
29
  self,
@@ -59,19 +59,11 @@ class SliderBindableUi(
59
59
  return self.element.value
60
60
 
61
61
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
62
- if prop == "value":
63
- return self.bind_value(value)
62
+ if ValueElementMixin._bind_specified_props(self, prop, value):
63
+ return self
64
64
 
65
65
  return super().bind_prop(prop, value)
66
66
 
67
- def bind_value(self, value: TGetterOrReadonlyRef[float]):
68
- @self._ui_signal_on(value)
69
- def _():
70
- self.element.set_value(to_value(value))
71
- self.element.update()
72
-
73
- return self
74
-
75
67
 
76
68
  class LazySliderBindableUi(SliderBindableUi):
77
69
  def __init__(
@@ -8,15 +8,16 @@ from ex4nicegui.reactive.services.reactive_service import ParameterClassifier
8
8
  from ex4nicegui.utils.signals import (
9
9
  TGetterOrReadonlyRef,
10
10
  _TMaybeRef as TMaybeRef,
11
- to_value,
12
11
  )
13
12
  from nicegui import ui
14
13
  from .base import BindableUi
14
+ from ex4nicegui.reactive.mixins.value_element import ValueElementMixin
15
+
15
16
 
16
17
  T = TypeVar("T")
17
18
 
18
19
 
19
- class SwitchBindableUi(BindableUi[ui.switch]):
20
+ class SwitchBindableUi(BindableUi[ui.switch], ValueElementMixin[bool]):
20
21
  def __init__(
21
22
  self,
22
23
  text: TMaybeRef[str] = "",
@@ -47,14 +48,6 @@ class SwitchBindableUi(BindableUi[ui.switch]):
47
48
  return self.element.value
48
49
 
49
50
  def bind_prop(self, prop: str, value: TGetterOrReadonlyRef):
50
- if prop == "value":
51
- return self.bind_value(value)
52
-
51
+ if ValueElementMixin._bind_specified_props(self, prop, value):
52
+ return self
53
53
  return super().bind_prop(prop, value)
54
-
55
- def bind_value(self, value: TGetterOrReadonlyRef[bool]):
56
- @self._ui_signal_on(value)
57
- def _():
58
- self.element.set_value(to_value(value))
59
-
60
- return self