# ntt-json-model
Library with model object which is observable and can be serialize and deserialize from json file
## Example
### With `primitive` data
```python
from ntt_json_model import *
class TestModel(ModelBase):
def __init__(self,
nValue: int = 3,
strName: str = "Hello",
fTemp: float = 3.1,
lstScores: List[int] = []) -> None:
super().__init__()
IntegerProperty(self, nValue, "_nValue")
FloatProperty(self, fTemp, "_fTemp")
StrProperty(self, strName, "_strName")
ListProperty(self, lstScores, "_lstScores")
@property
def Value(self) -> int:
return self._nValue.GetValue()
@Value.setter
def Value(self, nValue: int) -> None:
self._nValue.SetValue(nValue)
@property
def Temp(self) -> str:
return self._fTemp.GetValue()
@Temp.setter
def Temp(self, fTemp: float) -> None:
self._fTemp.SetValue(fTemp)
@property
def Name(self) -> str:
return self._strName.GetValue()
@Name.setter
def Name(self, strName: str) -> None:
self._strName.SetValue(strName)
@property
def Scores(self) -> List[int]:
return self._lstScores.GetValue()
ModelBase.mSubModels[TestModel.__name__] = TestModel
def PrintIfChanged() -> None:
print("Model has changed")
model = TestModel()
model.Connect(PrintIfChanged)
model.Temp = 3 # ---> "Model has changed"
print(model.ToDict())
# Output:
# {
# "__class__": "TestModel",
# "_nValue": 3,
# "_fTemp": 3.0,
# "_strName": "Hello",
# "_lstScores": []
# }
model.FromDict({
"__class__": "TestModel",
"_nValue": 3,
"_fTemp": 3.0,
"_strName": "Hello",
"_lstScores": [4, 3]
})
```
### `Model` Data
``` python
class TestModelClass(ModelBase):
def __init__(self, nScore: int = 4, *args, **kwargs) -> None:
super().__init__()
IntegerProperty(self, nScore, "_nScore")
ModelProperty(self, TestModel(*args, **kwargs), "_mTestModel")
@property
def Score(self) -> int:
return self._nScore.GetValue()
@Score.setter
def Score(self, nNewScore: int) -> None:
self._nScore.SetValue(nNewScore)
@property
def TestModel(self) -> TestModel:
return self._mTestModel.GetValue()
ModelBase.mSubModels[TestModelClass.__name__] = TestModelClass
```
### `Model List` Data
```python
class TestModelListClass(ModelBase):
def __init__(self, fScore: float = 8.5) -> None:
super().__init__()
FloatProperty(self, fScore, "_fScore")
ModelListProperty(self, [], "_mModels")
@property
def Score(self) -> float:
return self._fScore.GetValue()
@Score.setter
def Score(self, fNewScore: float) -> None:
self._fScore.SetValue(fNewScore)
@property
def Models(self) -> List[TestModelClass]:
return self._mModels.GetValue()
ModelBase.mSubModels[TestModelListClass.__name__] = TestModelListClass
```
Raw data
{
"_id": null,
"home_page": "https://github.com/threezinedine/ntt-json-model",
"name": "ntt-json-model",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "json,mvvm,signal,ntt",
"author": "threezinedine",
"author_email": "threezinedine@email.com",
"download_url": "https://files.pythonhosted.org/packages/60/70/d355833d259a76d8393890f3cb2009f728869c6ea437c05d41addaf8a4e1/ntt-json-model-1.0.1.tar.gz",
"platform": null,
"description": "# ntt-json-model\r\nLibrary with model object which is observable and can be serialize and deserialize from json file\r\n\r\n## Example\r\n\r\n### With `primitive` data\r\n\r\n```python\r\nfrom ntt_json_model import *\r\n\r\nclass TestModel(ModelBase):\r\n def __init__(self, \r\n nValue: int = 3, \r\n strName: str = \"Hello\",\r\n fTemp: float = 3.1,\r\n lstScores: List[int] = []) -> None:\r\n super().__init__()\r\n\r\n IntegerProperty(self, nValue, \"_nValue\")\r\n FloatProperty(self, fTemp, \"_fTemp\")\r\n StrProperty(self, strName, \"_strName\")\r\n ListProperty(self, lstScores, \"_lstScores\")\r\n\r\n @property\r\n def Value(self) -> int:\r\n return self._nValue.GetValue()\r\n\r\n @Value.setter\r\n def Value(self, nValue: int) -> None:\r\n self._nValue.SetValue(nValue)\r\n\r\n @property\r\n def Temp(self) -> str:\r\n return self._fTemp.GetValue()\r\n\r\n @Temp.setter\r\n def Temp(self, fTemp: float) -> None:\r\n self._fTemp.SetValue(fTemp)\r\n \r\n @property\r\n def Name(self) -> str:\r\n return self._strName.GetValue()\r\n\r\n @Name.setter\r\n def Name(self, strName: str) -> None:\r\n self._strName.SetValue(strName)\r\n\r\n @property\r\n def Scores(self) -> List[int]:\r\n return self._lstScores.GetValue()\r\n\r\nModelBase.mSubModels[TestModel.__name__] = TestModel\r\n\r\ndef PrintIfChanged() -> None:\r\n print(\"Model has changed\")\r\n\r\nmodel = TestModel()\r\nmodel.Connect(PrintIfChanged)\r\nmodel.Temp = 3 # ---> \"Model has changed\"\r\n\r\nprint(model.ToDict()) \r\n# Output:\r\n# {\r\n# \"__class__\": \"TestModel\",\r\n# \"_nValue\": 3,\r\n# \"_fTemp\": 3.0,\r\n# \"_strName\": \"Hello\",\r\n# \"_lstScores\": []\r\n# }\r\n\r\nmodel.FromDict({\r\n \"__class__\": \"TestModel\",\r\n \"_nValue\": 3,\r\n \"_fTemp\": 3.0,\r\n \"_strName\": \"Hello\",\r\n \"_lstScores\": [4, 3]\r\n})\r\n```\r\n\r\n### `Model` Data\r\n\r\n``` python\r\nclass TestModelClass(ModelBase):\r\n def __init__(self, nScore: int = 4, *args, **kwargs) -> None:\r\n super().__init__()\r\n\r\n IntegerProperty(self, nScore, \"_nScore\")\r\n ModelProperty(self, TestModel(*args, **kwargs), \"_mTestModel\")\r\n\r\n @property\r\n def Score(self) -> int:\r\n return self._nScore.GetValue()\r\n\r\n @Score.setter\r\n def Score(self, nNewScore: int) -> None:\r\n self._nScore.SetValue(nNewScore)\r\n\r\n @property\r\n def TestModel(self) -> TestModel:\r\n return self._mTestModel.GetValue()\r\n\r\nModelBase.mSubModels[TestModelClass.__name__] = TestModelClass\r\n```\r\n\r\n### `Model List` Data\r\n\r\n```python\r\nclass TestModelListClass(ModelBase):\r\n def __init__(self, fScore: float = 8.5) -> None:\r\n super().__init__()\r\n\r\n FloatProperty(self, fScore, \"_fScore\")\r\n ModelListProperty(self, [], \"_mModels\")\r\n \r\n @property\r\n def Score(self) -> float:\r\n return self._fScore.GetValue()\r\n\r\n @Score.setter\r\n def Score(self, fNewScore: float) -> None:\r\n self._fScore.SetValue(fNewScore)\r\n\r\n @property\r\n def Models(self) -> List[TestModelClass]:\r\n return self._mModels.GetValue()\r\n\r\nModelBase.mSubModels[TestModelListClass.__name__] = TestModelListClass\r\n```\r\n\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Small library for observation mechanism",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/threezinedine/ntt-json-model",
"Source": "https://github.com/threezinedine/ntt-json-model",
"Tracker": "https://github.com/threezinedine/ntt-json-model/issues"
},
"split_keywords": [
"json",
"mvvm",
"signal",
"ntt"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "36fa5f2b160c270825ecc57102350207a1e648cbd2c7098b4949c0341d36cdd4",
"md5": "439892e933e797daf749f0255344aba5",
"sha256": "404812f9ce653081701d66a3b57ee2501242ccf12f770d594d3db0d1affb139e"
},
"downloads": -1,
"filename": "ntt_json_model-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "439892e933e797daf749f0255344aba5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 12187,
"upload_time": "2023-11-27T15:27:36",
"upload_time_iso_8601": "2023-11-27T15:27:36.201086Z",
"url": "https://files.pythonhosted.org/packages/36/fa/5f2b160c270825ecc57102350207a1e648cbd2c7098b4949c0341d36cdd4/ntt_json_model-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6070d355833d259a76d8393890f3cb2009f728869c6ea437c05d41addaf8a4e1",
"md5": "50d28bf3ee3ae08c880c0acc17dd5455",
"sha256": "39c359c0ac6abc1774d28055f859e404f012b17533e843407b2878c9006b3ae1"
},
"downloads": -1,
"filename": "ntt-json-model-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "50d28bf3ee3ae08c880c0acc17dd5455",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8302,
"upload_time": "2023-11-27T15:27:38",
"upload_time_iso_8601": "2023-11-27T15:27:38.306177Z",
"url": "https://files.pythonhosted.org/packages/60/70/d355833d259a76d8393890f3cb2009f728869c6ea437c05d41addaf8a4e1/ntt-json-model-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-27 15:27:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "threezinedine",
"github_project": "ntt-json-model",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "certifi",
"specs": [
[
"==",
"2023.11.17"
]
]
},
{
"name": "charset-normalizer",
"specs": [
[
"==",
"3.3.2"
]
]
},
{
"name": "colorama",
"specs": [
[
"==",
"0.4.6"
]
]
},
{
"name": "docutils",
"specs": [
[
"==",
"0.20.1"
]
]
},
{
"name": "exceptiongroup",
"specs": [
[
"==",
"1.2.0"
]
]
},
{
"name": "idna",
"specs": [
[
"==",
"3.6"
]
]
},
{
"name": "importlib-metadata",
"specs": [
[
"==",
"6.8.0"
]
]
},
{
"name": "iniconfig",
"specs": [
[
"==",
"2.0.0"
]
]
},
{
"name": "jaraco.classes",
"specs": [
[
"==",
"3.3.0"
]
]
},
{
"name": "keyring",
"specs": [
[
"==",
"24.3.0"
]
]
},
{
"name": "markdown-it-py",
"specs": [
[
"==",
"3.0.0"
]
]
},
{
"name": "mdurl",
"specs": [
[
"==",
"0.1.2"
]
]
},
{
"name": "more-itertools",
"specs": [
[
"==",
"10.1.0"
]
]
},
{
"name": "nh3",
"specs": [
[
"==",
"0.2.14"
]
]
},
{
"name": "ntt-observable-list",
"specs": [
[
"==",
"1.0.0"
]
]
},
{
"name": "ntt-signal",
"specs": [
[
"==",
"1.0.3"
]
]
},
{
"name": "packaging",
"specs": [
[
"==",
"23.2"
]
]
},
{
"name": "pkginfo",
"specs": [
[
"==",
"1.9.6"
]
]
},
{
"name": "pluggy",
"specs": [
[
"==",
"1.3.0"
]
]
},
{
"name": "Pygments",
"specs": [
[
"==",
"2.17.2"
]
]
},
{
"name": "pytest",
"specs": [
[
"==",
"7.4.3"
]
]
},
{
"name": "pywin32-ctypes",
"specs": [
[
"==",
"0.2.2"
]
]
},
{
"name": "readme-renderer",
"specs": [
[
"==",
"42.0"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.31.0"
]
]
},
{
"name": "requests-toolbelt",
"specs": [
[
"==",
"1.0.0"
]
]
},
{
"name": "rfc3986",
"specs": [
[
"==",
"2.0.0"
]
]
},
{
"name": "rich",
"specs": [
[
"==",
"13.7.0"
]
]
},
{
"name": "tomli",
"specs": [
[
"==",
"2.0.1"
]
]
},
{
"name": "twine",
"specs": [
[
"==",
"4.0.2"
]
]
},
{
"name": "urllib3",
"specs": [
[
"==",
"2.1.0"
]
]
},
{
"name": "zipp",
"specs": [
[
"==",
"3.17.0"
]
]
}
],
"lcname": "ntt-json-model"
}