ex4nicegui 0.8.7__py3-none-any.whl → 0.8.8__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.
@@ -74,7 +74,7 @@ from .mermaid.mermaid import Mermaid as mermaid
74
74
  from .officials.dialog import DialogBindableUi as dialog
75
75
  from .vfor import vfor, VforStore
76
76
  from .vmodel import vmodel
77
- from .view_model import ViewModel, var, cached_var, list_var
77
+ from .view_model import ViewModel, var, cached_var, list_var, dict_var
78
78
 
79
79
  pagination = q_pagination
80
80
 
@@ -102,6 +102,7 @@ __all__ = [
102
102
  "var",
103
103
  "cached_var",
104
104
  "list_var",
105
+ "dict_var",
105
106
  "html",
106
107
  "aggrid",
107
108
  "button",
@@ -1,5 +1,5 @@
1
1
  from __future__ import annotations
2
- from typing import Any, Callable, List, Optional, Union, Type, TypeVar, overload
2
+ from typing import Any, Callable, Dict, List, Optional, Union, Type, TypeVar, overload
3
3
  from ex4nicegui.utils.signals import (
4
4
  deep_ref,
5
5
  is_ref,
@@ -23,6 +23,7 @@ from ex4nicegui.utils.proxy.descriptor import ProxyDescriptor
23
23
 
24
24
  _CACHED_VARS_FLAG = "__vm_cached__"
25
25
  _LIST_VAR_FLAG = "__vm_list_var__"
26
+ _DICT_VAR_FLAG = "__vm_dict_var__"
26
27
 
27
28
  _T = TypeVar("_T")
28
29
 
@@ -72,7 +73,8 @@ class ViewModel(NoProxy):
72
73
  if callable(value) and hasattr(value, _CACHED_VARS_FLAG):
73
74
  setattr(self, name, computed(partial(value, self)))
74
75
 
75
- def __init_subclass__(cls) -> None:
76
+ def __init_subclass__(cls, **kwargs) -> None:
77
+ super().__init_subclass__(**kwargs)
76
78
  need_vars = (
77
79
  (name, value)
78
80
  for name, value in vars(cls).items()
@@ -80,7 +82,7 @@ class ViewModel(NoProxy):
80
82
  )
81
83
 
82
84
  for name, value in need_vars:
83
- class_var_setter(cls, name, value, _LIST_VAR_FLAG)
85
+ class_var_setter(cls, name, value, _LIST_VAR_FLAG, _DICT_VAR_FLAG)
84
86
 
85
87
  @overload
86
88
  @staticmethod
@@ -280,6 +282,34 @@ def list_var(factory: Callable[[], List[_T_Var_Value]]) -> List[_T_Var_Value]:
280
282
  return factory # type: ignore
281
283
 
282
284
 
285
+ def dict_var(factory: Callable[[], Dict]) -> Dict:
286
+ """Create implicitly proxied reactive variables for dictionaries. Use them just like ordinary dictionaries while maintaining reactivity. Only use within rxui.ViewModel.
287
+
288
+ Args:
289
+ factory (Callable[[], Dict]): A factory function that returns a new dictionary.
290
+
291
+ Example:
292
+ .. code-block:: python
293
+ from ex4nicegui import rxui
294
+ class State(rxui.ViewModel):
295
+ data = rxui.dict_var(lambda: {"a": 1, "b": 2, "c": 3})
296
+
297
+ def update_data(self):
298
+ self.data["d"] = len(self.data) + 1
299
+
300
+ def display_data(self):
301
+ return ",".join(f"{k}:{v}" for k, v in self.data.items())
302
+
303
+ state = State()
304
+ ui.button("Update", on_click=state.update_data)
305
+ rxui.label(state.display_data)
306
+
307
+ """
308
+ assert callable(factory), "factory must be a callable"
309
+ setattr(factory, _DICT_VAR_FLAG, None)
310
+ return factory # type: ignore
311
+
312
+
283
313
  def cached_var(func: Callable[..., _T]) -> ReadonlyRef[_T]:
284
314
  """A decorator to cache the result of a function. Only use within rxui.ViewModel.
285
315
 
@@ -8,6 +8,7 @@ from .float import FloatProxy
8
8
  from .bool import BoolProxy
9
9
  from .date import DateProxy
10
10
  from .dict import DictProxy
11
+ from ex4nicegui.utils.signals import deep_ref
11
12
  import datetime
12
13
  import warnings
13
14
  from . import to_value_if_base_type_proxy
@@ -61,9 +62,34 @@ class ListDescriptor(ProxyDescriptor[Callable[[], List]]):
61
62
  super().__init__(name, value, lambda x: ListProxy(x() if callable(x) else x))
62
63
 
63
64
 
64
- class DictDescriptor(ProxyDescriptor[Dict]):
65
- def __init__(self, name: str, value: Dict) -> None:
66
- super().__init__(name, value, DictProxy)
65
+ class DictDescriptor:
66
+ def __init__(
67
+ self,
68
+ name: str,
69
+ factory: Callable[[], Dict],
70
+ ) -> None:
71
+ self.name = name
72
+ self._ref_builder = lambda: deep_ref(factory())
73
+
74
+ def __get__(self, instance: object, owner: Any):
75
+ if instance is None:
76
+ return self
77
+
78
+ proxy = instance.__dict__.get(self.name, None)
79
+ if proxy is None:
80
+ proxy = self._ref_builder()
81
+ instance.__dict__[self.name] = proxy
82
+
83
+ return proxy.value
84
+
85
+ def __set__(self, instance: object, value: T) -> None:
86
+ value = to_value_if_base_type_proxy(value)
87
+ proxy = instance.__dict__.get(self.name, None)
88
+ if proxy is None:
89
+ proxy = self._ref_builder()
90
+ instance.__dict__[self.name] = proxy
91
+
92
+ proxy.value = value # type: ignore
67
93
 
68
94
 
69
95
  class StringDescriptor(ProxyDescriptor[str]):
@@ -91,7 +117,9 @@ class DateDescriptor(ProxyDescriptor[datetime.date]):
91
117
  super().__init__(name, value, lambda x: DateProxy(x.year, x.month, x.day))
92
118
 
93
119
 
94
- def class_var_setter(cls: Type, name: str, value, list_var_flat: str) -> None:
120
+ def class_var_setter(
121
+ cls: Type, name: str, value, list_var_flat: str, dict_var_flat: str
122
+ ) -> None:
95
123
  if value is None or isinstance(value, str):
96
124
  setattr(cls, name, StringDescriptor(name, value))
97
125
  elif isinstance(value, bool):
@@ -111,9 +139,8 @@ def class_var_setter(cls: Type, name: str, value, list_var_flat: str) -> None:
111
139
  )
112
140
  setattr(cls, name, ListDescriptor(name, lambda: []))
113
141
 
114
- elif isinstance(value, dict):
115
- pass # TODO
116
- # setattr(cls, name, DictDescriptor(name, value))
142
+ elif callable(value) and hasattr(value, dict_var_flat):
143
+ setattr(cls, name, DictDescriptor(name, value))
117
144
  elif isinstance(value, float):
118
145
  setattr(cls, name, FloatDescriptor(name, value))
119
146
  elif isinstance(value, datetime.date):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ex4nicegui
3
- Version: 0.8.7
3
+ Version: 0.8.8
4
4
  Summary: Extension library based on nicegui, providing data responsive,BI functionality modules
5
5
  License: MIT
6
6
  Keywords: nicegui,ex4nicegui,webui
@@ -70,7 +70,7 @@ ex4nicegui/libs/gsap/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJ
70
70
  ex4nicegui/libs/gsap/utils/matrix.js,sha256=77scrxbQZXx4ex5HkvnT9IkhMG1rQoDNp4TSYgUeYVk,15235
71
71
  ex4nicegui/libs/gsap/utils/paths.js,sha256=2SPaRHQ7zgba9cH8hGhkTYPCZdrrEhE2qhh6ECAEvSA,49314
72
72
  ex4nicegui/libs/gsap/utils/strings.js,sha256=47G9slz5ltG9mDSwrfQDtWzzdV5QJ-AIMLRMNK0VSiM,10472
73
- ex4nicegui/reactive/__init__.py,sha256=I5GhhBCPBIVj3vhLE7Zf_UpjIK7ZOwCFFCC3YNPE4Rs,4668
73
+ ex4nicegui/reactive/__init__.py,sha256=Mzt4pXWcj5abJuUfqyy_oGex-jTmaXiH3fiB972JprY,4695
74
74
  ex4nicegui/reactive/base.py,sha256=CQmWhrKHNMF2ql7O6VOKEOBdEcc3-yagOcERpnUPYus,16323
75
75
  ex4nicegui/reactive/deferredTask.py,sha256=g78TTG1EIkBxjPih01xmrCZw9OxQG93veSVSELWKfcU,987
76
76
  ex4nicegui/reactive/dropZone/dropZone.js,sha256=7rSpFJX-Fk_W_NGZhOTyuEw0bzR-YUc8ZYPzQG9KzE0,2713
@@ -153,7 +153,7 @@ ex4nicegui/reactive/useMouse/UseMouse.py,sha256=cFNlso7_BneyAfGmWbl-N9vQwGleV2Ar
153
153
  ex4nicegui/reactive/usePagination.py,sha256=8YLqcZ_ecuX0FdQ0ct-XdEFfMAVkubAS_K02YOhg5oo,2584
154
154
  ex4nicegui/reactive/vfor.js,sha256=sCy3KR5Aeyx68yh9VI6I9Vj7bnVuir_LUYKZBe_ePTg,908
155
155
  ex4nicegui/reactive/vfor.py,sha256=SSu3X2DLZeCveTrcLANYNMNpLv34cJonLCp_9W0HFlY,7931
156
- ex4nicegui/reactive/view_model.py,sha256=1V5s_uBx9N_Iv2b0tJLsRA_7LNBi6ySlge-rbyQkCC8,8792
156
+ ex4nicegui/reactive/view_model.py,sha256=OSOnOTc86JgYqO6pb3J_IrOdDKP0MyEIeSHYX4P3EOI,9904
157
157
  ex4nicegui/reactive/vmodel.py,sha256=ymrUpC_68jaHF76ivKmgz-C4Xl6i65c_41uMc0ffEhY,5936
158
158
  ex4nicegui/toolbox/__init__.py,sha256=Q5pIvMJX5Ugf2dLcffU4wK6DFQW_qsKV5iTJPoALvTQ,235
159
159
  ex4nicegui/toolbox/core/vue_use.py,sha256=0wzNJTDuZ08BNEVs0ibXiinje8SQIpeqEJIoug25iwg,969
@@ -173,7 +173,7 @@ ex4nicegui/utils/proxy/__init__.py,sha256=L0SO_32i33Unue0fCFVpHdyZljuykWHjll3Dmd
173
173
  ex4nicegui/utils/proxy/base.py,sha256=g_7308xGAB3bB3EiEf_-0JKfUzImwt5_T9XVyT7zJJg,128
174
174
  ex4nicegui/utils/proxy/bool.py,sha256=KQ2Sp2r4nLScif9DhupDmkpRhbsuXdpXTkxSrtFYtDE,1774
175
175
  ex4nicegui/utils/proxy/date.py,sha256=wS0M4nfGVQ7A1u9tJkPqilEhDwcMKBjtTC9VjUsOqac,2356
176
- ex4nicegui/utils/proxy/descriptor.py,sha256=VuPBXAE7mHbJ3EUAsftr3mettDvju79bR-SlwczRrAs,4594
176
+ ex4nicegui/utils/proxy/descriptor.py,sha256=BG6KQGTSMX1QKpXDvkrMk9wvL__vzg6m2GSuaj1leeE,5384
177
177
  ex4nicegui/utils/proxy/dict.py,sha256=MPtx-09ylf_bHXnkr1c7PmJeaq2KpDp-_Shyw5YjOLU,3046
178
178
  ex4nicegui/utils/proxy/float.py,sha256=fdMUS7_xwypdDNscuZaUn3NA0vx8LGswAOc9kw0jK0c,5271
179
179
  ex4nicegui/utils/proxy/int.py,sha256=0Y7L924Zzq6LWRZEmaTmoXf0J6kC0o5EtW--2Lk7SNw,7381
@@ -186,7 +186,7 @@ ex4nicegui/utils/scheduler.py,sha256=1gyq7Y2BkbwmPK_Q9kpRpc1MOC9H7xcpxuix-RZhN9k
186
186
  ex4nicegui/utils/signals.py,sha256=Jz0jKFPrJIRV0Gye62Bgk2kGgod1KBvDhnF-W3lRm04,7373
187
187
  ex4nicegui/utils/types.py,sha256=pE5WOSbcTHxaAhnT24FaZEd1B2Z_lTcsd46w0OKiMyc,359
188
188
  ex4nicegui/version.py,sha256=NE7u1piESstg3xCtf5hhV4iedGs2qJQw9SiC3ZSpiio,90
189
- ex4nicegui-0.8.7.dist-info/LICENSE,sha256=0KDDElS2dl-HIsWvbpy8ywbLzJMBFzXLev57LnMIZXs,1094
190
- ex4nicegui-0.8.7.dist-info/METADATA,sha256=FKLsKPR5EJZnSGTitaJi8RpitJ1XbTfyosp_F8_JL3Y,46832
191
- ex4nicegui-0.8.7.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
192
- ex4nicegui-0.8.7.dist-info/RECORD,,
189
+ ex4nicegui-0.8.8.dist-info/LICENSE,sha256=0KDDElS2dl-HIsWvbpy8ywbLzJMBFzXLev57LnMIZXs,1094
190
+ ex4nicegui-0.8.8.dist-info/METADATA,sha256=F65K1T5Q-aq5j43kfUik17A08SdSUBNJnAsPWLLjTQk,46832
191
+ ex4nicegui-0.8.8.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
192
+ ex4nicegui-0.8.8.dist-info/RECORD,,