| Name | CTkMVC JSON |
| Version |
0.0.3
JSON |
| download |
| home_page | None |
| Summary | Base classes for easy using MVC pattern with CTk library |
| upload_time | 2024-08-05 10:31:21 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.7 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# CTkMVC
## Install
```
pip install ctkmvc
```
## Description
The library that provides a few base classes for easy using MVC architecture pattern together with CTk library to make simple and lightweight desktop applications.
## Using example
In this example we will create a simple system that let us to make a button changing its text by clicking on it. To make your own `View`, `Controller` and `Model` classes you should inherit them from base abstract classes `View`, `Controller` and `ObservableModel` like that:
* Imports
```python
from customtkinter import CTkButton
from random import Random
from view import View
from model import ObservableModel
from controller import Controller
```
* Our View
```python
class MyWindow(View):
def __init__(self, controller, model):
super().__init__(controller, model)
self.wm_title('Window')
self.resizable(False, False)
self.geometry('600x400')
self.button = CTkButton(self, command=self._controller.button_click)
self.button.grid(row=4, column=0, padx=(20, 20), pady=(10, 10), sticky="ew")
def model_is_changed(self):
self.button.configure(text=self._model.button_text)
```
Inherit our `View`from `View` abstract class and override `model_is_changed` method to react to `Model` changes. Then in `__init__` method we create CTk attributes to design our window and do not forget to call super `__init__` method to construct base `View` class by passing our `Controller` and `Model` objects.
* Our Model
```python
class MyWindowModel(ObservableModel):
def __init__(self):
super().__init__()
self.__button_text = None
@property
def button_text(self):
return self.__button_text
@button_text.setter
def button_text(self, value):
self.__button_text = value
self.notify_observers()
```
Inherit our `Model` from `ObservableModel` base abstract class and implement necessary properties our `View` observes. In setter method we call `notify_observers` method to notify subscibed views.
* Our Controller
```python
class MyWindowController(Controller):
def __init__(self, view_cls, model):
super().__init__(view_cls, model)
def button_click(self):
button_names = ['ctk', 'MVC', 'architecture', 'pattern']
self._model.button_text = Random().choice(button_names)
```
Inherit our `Controller` from `Controller` base abstract class. Our `Controller` controles creating `View` object therefore in its `__init__` method we pass our `Model` object and CLASS itself but not certain object of our `View` beacuse of this:
```python
class Controller(ABC):
def __init__(self, view_cls: 'type[View]', model: ObservableModel):
self._view = view_cls(self, model)
# Some code...
```
### Result
```python
from window import MyWindow, MyWindowModel, MyWindowController
def main():
MyWindowController(
MyWindow,
MyWindowModel()
)
if __name__=='__main__':
main()
```
We get a window with a button that changes its text by clicking on it.
Raw data
{
"_id": null,
"home_page": null,
"name": "CTkMVC",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Ivan Kirov <evankirk@vk.com>",
"download_url": "https://files.pythonhosted.org/packages/fd/4b/e544b8566fd5cfb486ab3cb8b0e98bc62d8ce6ae8cc979084a387f68e8b8/ctkmvc-0.0.3.tar.gz",
"platform": null,
"description": "# CTkMVC\n\n## Install\n\n```\npip install ctkmvc\n```\n\n## Description\n\nThe library that provides a few base classes for easy using MVC architecture pattern together with CTk library to make simple and lightweight desktop applications.\n\n## Using example\n\nIn this example we will create a simple system that let us to make a button changing its text by clicking on it. To make your own `View`, `Controller` and `Model` classes you should inherit them from base abstract classes `View`, `Controller` and `ObservableModel` like that:\n\n* Imports\n\n```python\nfrom customtkinter import CTkButton\nfrom random import Random\n\nfrom view import View\nfrom model import ObservableModel\nfrom controller import Controller\n```\n\n* Our View\n\n```python\nclass MyWindow(View):\n\n def __init__(self, controller, model):\n\n super().__init__(controller, model)\n\n self.wm_title('Window')\n\n self.resizable(False, False)\n\n self.geometry('600x400')\n\n self.button = CTkButton(self, command=self._controller.button_click)\n\n self.button.grid(row=4, column=0, padx=(20, 20), pady=(10, 10), sticky=\"ew\")\n\n\n def model_is_changed(self):\n \n self.button.configure(text=self._model.button_text)\n```\n\nInherit our `View`from `View` abstract class and override `model_is_changed` method to react to `Model` changes. Then in `__init__` method we create CTk attributes to design our window and do not forget to call super `__init__` method to construct base `View` class by passing our `Controller` and `Model` objects.\n\n* Our Model\n\n```python\nclass MyWindowModel(ObservableModel):\n\n def __init__(self):\n\n super().__init__()\n \n self.__button_text = None\n\n @property\n def button_text(self):\n return self.__button_text\n \n @button_text.setter\n def button_text(self, value):\n\n self.__button_text = value\n\n self.notify_observers()\n```\n\nInherit our `Model` from `ObservableModel` base abstract class and implement necessary properties our `View` observes. In setter method we call `notify_observers` method to notify subscibed views.\n\n* Our Controller\n\n```python\nclass MyWindowController(Controller):\n\n def __init__(self, view_cls, model):\n\n super().__init__(view_cls, model)\n\n \n def button_click(self):\n\n button_names = ['ctk', 'MVC', 'architecture', 'pattern']\n\n self._model.button_text = Random().choice(button_names)\n```\n\nInherit our `Controller` from `Controller` base abstract class. Our `Controller` controles creating `View` object therefore in its `__init__` method we pass our `Model` object and CLASS itself but not certain object of our `View` beacuse of this:\n\n```python\nclass Controller(ABC):\n\n def __init__(self, view_cls: 'type[View]', model: ObservableModel):\n\n self._view = view_cls(self, model)\n \n # Some code...\n```\n\n### Result\n\n```python\nfrom window import MyWindow, MyWindowModel, MyWindowController\n\ndef main():\n \n MyWindowController(\n\n MyWindow,\n MyWindowModel()\n )\n\n\nif __name__=='__main__':\n main()\n```\n\nWe get a window with a button that changes its text by clicking on it.",
"bugtrack_url": null,
"license": null,
"summary": "Base classes for easy using MVC pattern with CTk library",
"version": "0.0.3",
"project_urls": {
"GitHub": "https://github.com/ovxrhxavxn/ctkmvc"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "54ad2b7cffb1ac04a8fa67e805d585aa9416c7e8264bbe28ee29769a8cf70a62",
"md5": "085950c91c0bc12867048fe56b6af2cf",
"sha256": "b160aaacffb589200def130d35b122b3db7f6f5dacad374347a56d9f5a5263a7"
},
"downloads": -1,
"filename": "ctkmvc-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "085950c91c0bc12867048fe56b6af2cf",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 4365,
"upload_time": "2024-08-05T10:31:20",
"upload_time_iso_8601": "2024-08-05T10:31:20.118111Z",
"url": "https://files.pythonhosted.org/packages/54/ad/2b7cffb1ac04a8fa67e805d585aa9416c7e8264bbe28ee29769a8cf70a62/ctkmvc-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fd4be544b8566fd5cfb486ab3cb8b0e98bc62d8ce6ae8cc979084a387f68e8b8",
"md5": "599d0683a6e3a3e1b8ecc1671f346948",
"sha256": "e82373d4b8bd9ac48373719430e2e29116bd6e85da6d9fbcf6e5309a5ef475ea"
},
"downloads": -1,
"filename": "ctkmvc-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "599d0683a6e3a3e1b8ecc1671f346948",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 4153,
"upload_time": "2024-08-05T10:31:21",
"upload_time_iso_8601": "2024-08-05T10:31:21.501074Z",
"url": "https://files.pythonhosted.org/packages/fd/4b/e544b8566fd5cfb486ab3cb8b0e98bc62d8ce6ae8cc979084a387f68e8b8/ctkmvc-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-05 10:31:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ovxrhxavxn",
"github_project": "ctkmvc",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ctkmvc"
}