CTkMVC 0.0.1__tar.gz
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.
Potentially problematic release.
This version of CTkMVC might be problematic. Click here for more details.
- ctkmvc-0.0.1/.gitignore +130 -0
- ctkmvc-0.0.1/LICENSE +7 -0
- ctkmvc-0.0.1/PKG-INFO +141 -0
- ctkmvc-0.0.1/README.md +127 -0
- ctkmvc-0.0.1/pyproject.toml +27 -0
- ctkmvc-0.0.1/src/ctkmvc/controller.py +17 -0
- ctkmvc-0.0.1/src/ctkmvc/interface.py +8 -0
- ctkmvc-0.0.1/src/ctkmvc/model.py +23 -0
- ctkmvc-0.0.1/src/ctkmvc/view.py +20 -0
ctkmvc-0.0.1/.gitignore
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
*pyproject*
|
|
30
|
+
|
|
31
|
+
# PyInstaller
|
|
32
|
+
# Usually these files are written by a python script from a template
|
|
33
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
34
|
+
*.manifest
|
|
35
|
+
*.spec
|
|
36
|
+
|
|
37
|
+
# Installer logs
|
|
38
|
+
pip-log.txt
|
|
39
|
+
pip-delete-this-directory.txt
|
|
40
|
+
|
|
41
|
+
# Unit test / coverage reports
|
|
42
|
+
htmlcov/
|
|
43
|
+
.tox/
|
|
44
|
+
.nox/
|
|
45
|
+
.coverage
|
|
46
|
+
.coverage.*
|
|
47
|
+
.cache
|
|
48
|
+
nosetests.xml
|
|
49
|
+
coverage.xml
|
|
50
|
+
*.cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
target/
|
|
76
|
+
|
|
77
|
+
# Jupyter Notebook
|
|
78
|
+
.ipynb_checkpoints
|
|
79
|
+
|
|
80
|
+
# IPython
|
|
81
|
+
profile_default/
|
|
82
|
+
ipython_config.py
|
|
83
|
+
|
|
84
|
+
# pyenv
|
|
85
|
+
.python-version
|
|
86
|
+
|
|
87
|
+
# pipenv
|
|
88
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
89
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
90
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
91
|
+
# install all needed dependencies.
|
|
92
|
+
#Pipfile.lock
|
|
93
|
+
|
|
94
|
+
# celery beat schedule file
|
|
95
|
+
celerybeat-schedule
|
|
96
|
+
|
|
97
|
+
# SageMath parsed files
|
|
98
|
+
*.sage.py
|
|
99
|
+
|
|
100
|
+
# Environments
|
|
101
|
+
.env
|
|
102
|
+
.venv
|
|
103
|
+
env/
|
|
104
|
+
venv/
|
|
105
|
+
ENV/
|
|
106
|
+
env.bak/
|
|
107
|
+
venv.bak/
|
|
108
|
+
|
|
109
|
+
# Spyder project settings
|
|
110
|
+
.spyderproject
|
|
111
|
+
.spyproject
|
|
112
|
+
|
|
113
|
+
# Rope project settings
|
|
114
|
+
.ropeproject
|
|
115
|
+
|
|
116
|
+
# mkdocs documentation
|
|
117
|
+
/site
|
|
118
|
+
|
|
119
|
+
# mypy
|
|
120
|
+
.mypy_cache/
|
|
121
|
+
.dmypy.json
|
|
122
|
+
dmypy.json
|
|
123
|
+
|
|
124
|
+
# Pyre type checker
|
|
125
|
+
.pyre/
|
|
126
|
+
|
|
127
|
+
# Dev Specific
|
|
128
|
+
.DS_Store
|
|
129
|
+
.vscode/
|
|
130
|
+
.idea/
|
ctkmvc-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2024 CTkMVC
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the «Software»), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
ctkmvc-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: CTkMVC
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Base classes for easy using MVC pattern with CTk library
|
|
5
|
+
Project-URL: GitHub, https://github.com/ovxrhxavxn/ctkmvc
|
|
6
|
+
Author-email: Ivan Kirov <evankirk@vk.com>
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Requires-Dist: customtkinter>=5.2.2
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# CTkMVC
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
pip install ctkmvc
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Description
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
## Using example
|
|
28
|
+
|
|
29
|
+
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:
|
|
30
|
+
|
|
31
|
+
* Imports
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from customtkinter import CTkButton
|
|
35
|
+
from random import Random
|
|
36
|
+
|
|
37
|
+
from view import View
|
|
38
|
+
from model import ObservableModel
|
|
39
|
+
from controller import Controller
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
* Our View
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
class MyWindow(View):
|
|
46
|
+
|
|
47
|
+
def __init__(self, controller, model):
|
|
48
|
+
|
|
49
|
+
super().__init__(controller, model)
|
|
50
|
+
|
|
51
|
+
self.wm_title('Papa')
|
|
52
|
+
|
|
53
|
+
self.resizable(False, False)
|
|
54
|
+
|
|
55
|
+
self.geometry('600x400')
|
|
56
|
+
|
|
57
|
+
self.button = CTkButton(self, command=self._controller.button_click)
|
|
58
|
+
|
|
59
|
+
self.button.grid(row=4, column=0, padx=(20, 20), pady=(10, 10), sticky="ew")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def model_is_changed(self):
|
|
63
|
+
|
|
64
|
+
self.button.configure(text=self._model.button_text)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
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.
|
|
68
|
+
|
|
69
|
+
* Our Model
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
class MyWindowModel(ObservableModel):
|
|
73
|
+
|
|
74
|
+
def __init__(self):
|
|
75
|
+
|
|
76
|
+
super().__init__()
|
|
77
|
+
|
|
78
|
+
self.__button_text = None
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def button_text(self):
|
|
82
|
+
return self.__button_text
|
|
83
|
+
|
|
84
|
+
@button_text.setter
|
|
85
|
+
def button_text(self, value):
|
|
86
|
+
|
|
87
|
+
self.__button_text = value
|
|
88
|
+
|
|
89
|
+
self.notify_observers()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
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.
|
|
93
|
+
|
|
94
|
+
* Our Controller
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
class MyWindowController(Controller):
|
|
98
|
+
|
|
99
|
+
def __init__(self, view_cls, model):
|
|
100
|
+
|
|
101
|
+
super().__init__(view_cls, model)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def button_click(self):
|
|
105
|
+
|
|
106
|
+
button_names = ['ctk', 'MVC', 'architecture', 'pattern']
|
|
107
|
+
|
|
108
|
+
self._model.button_text = Random().choice(button_names)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
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:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
class Controller(ABC):
|
|
115
|
+
|
|
116
|
+
def __init__(self, view_cls: 'type[View]', model: ObservableModel):
|
|
117
|
+
|
|
118
|
+
self._view = view_cls(self, model)
|
|
119
|
+
|
|
120
|
+
# Some code...
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Result
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from window import MyWindow, MyWindowModel, MyWindowController
|
|
127
|
+
|
|
128
|
+
def main():
|
|
129
|
+
|
|
130
|
+
MyWindowController(
|
|
131
|
+
|
|
132
|
+
MyWindow,
|
|
133
|
+
MyWindowModel()
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
if __name__=='__main__':
|
|
138
|
+
main()
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
We get a window with a button that changes its text by clicking on it.
|
ctkmvc-0.0.1/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# CTkMVC
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
pip install ctkmvc
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Description
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
## Using example
|
|
14
|
+
|
|
15
|
+
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:
|
|
16
|
+
|
|
17
|
+
* Imports
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from customtkinter import CTkButton
|
|
21
|
+
from random import Random
|
|
22
|
+
|
|
23
|
+
from view import View
|
|
24
|
+
from model import ObservableModel
|
|
25
|
+
from controller import Controller
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
* Our View
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
class MyWindow(View):
|
|
32
|
+
|
|
33
|
+
def __init__(self, controller, model):
|
|
34
|
+
|
|
35
|
+
super().__init__(controller, model)
|
|
36
|
+
|
|
37
|
+
self.wm_title('Papa')
|
|
38
|
+
|
|
39
|
+
self.resizable(False, False)
|
|
40
|
+
|
|
41
|
+
self.geometry('600x400')
|
|
42
|
+
|
|
43
|
+
self.button = CTkButton(self, command=self._controller.button_click)
|
|
44
|
+
|
|
45
|
+
self.button.grid(row=4, column=0, padx=(20, 20), pady=(10, 10), sticky="ew")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def model_is_changed(self):
|
|
49
|
+
|
|
50
|
+
self.button.configure(text=self._model.button_text)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
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.
|
|
54
|
+
|
|
55
|
+
* Our Model
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
class MyWindowModel(ObservableModel):
|
|
59
|
+
|
|
60
|
+
def __init__(self):
|
|
61
|
+
|
|
62
|
+
super().__init__()
|
|
63
|
+
|
|
64
|
+
self.__button_text = None
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def button_text(self):
|
|
68
|
+
return self.__button_text
|
|
69
|
+
|
|
70
|
+
@button_text.setter
|
|
71
|
+
def button_text(self, value):
|
|
72
|
+
|
|
73
|
+
self.__button_text = value
|
|
74
|
+
|
|
75
|
+
self.notify_observers()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
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.
|
|
79
|
+
|
|
80
|
+
* Our Controller
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
class MyWindowController(Controller):
|
|
84
|
+
|
|
85
|
+
def __init__(self, view_cls, model):
|
|
86
|
+
|
|
87
|
+
super().__init__(view_cls, model)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def button_click(self):
|
|
91
|
+
|
|
92
|
+
button_names = ['ctk', 'MVC', 'architecture', 'pattern']
|
|
93
|
+
|
|
94
|
+
self._model.button_text = Random().choice(button_names)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
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:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
class Controller(ABC):
|
|
101
|
+
|
|
102
|
+
def __init__(self, view_cls: 'type[View]', model: ObservableModel):
|
|
103
|
+
|
|
104
|
+
self._view = view_cls(self, model)
|
|
105
|
+
|
|
106
|
+
# Some code...
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Result
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from window import MyWindow, MyWindowModel, MyWindowController
|
|
113
|
+
|
|
114
|
+
def main():
|
|
115
|
+
|
|
116
|
+
MyWindowController(
|
|
117
|
+
|
|
118
|
+
MyWindow,
|
|
119
|
+
MyWindowModel()
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
if __name__=='__main__':
|
|
124
|
+
main()
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
We get a window with a button that changes its text by clicking on it.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[tool.hatch.build.targets.wheel]
|
|
6
|
+
packages = ["src/ctkmvc"]
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "CTkMVC"
|
|
10
|
+
version = "0.0.1"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name="Ivan Kirov", email="evankirk@vk.com" },
|
|
13
|
+
]
|
|
14
|
+
description = "Base classes for easy using MVC pattern with CTk library"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
requires-python = ">=3.7"
|
|
17
|
+
dependencies = [
|
|
18
|
+
"customtkinter>=5.2.2"
|
|
19
|
+
]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
GitHub="https://github.com/ovxrhxavxn/ctkmvc"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from typing import TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from model import ObservableModel
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from view import View
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Controller(ABC):
|
|
11
|
+
|
|
12
|
+
def __init__(self, view_cls: 'type[View]', model: ObservableModel):
|
|
13
|
+
|
|
14
|
+
self._view = view_cls(self, model)
|
|
15
|
+
self._model = model
|
|
16
|
+
|
|
17
|
+
self._view.mainloop()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
|
|
3
|
+
from interface import ModelObserver
|
|
4
|
+
|
|
5
|
+
class ObservableModel(ABC):
|
|
6
|
+
|
|
7
|
+
def __init__(self):
|
|
8
|
+
|
|
9
|
+
self._observers: list[ModelObserver] = []
|
|
10
|
+
|
|
11
|
+
def add_observer(self, observer: ModelObserver):
|
|
12
|
+
|
|
13
|
+
self._observers.append(observer)
|
|
14
|
+
|
|
15
|
+
def remove_observer(self, observer: ModelObserver):
|
|
16
|
+
|
|
17
|
+
self._observers.remove(observer)
|
|
18
|
+
|
|
19
|
+
def notify_observers(self):
|
|
20
|
+
|
|
21
|
+
for observer in self._observers:
|
|
22
|
+
|
|
23
|
+
observer.model_is_changed()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from customtkinter import CTk
|
|
2
|
+
from typing import TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from interface import ModelObserver
|
|
5
|
+
from model import ObservableModel
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from controller import Controller
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class View(CTk, ModelObserver):
|
|
12
|
+
|
|
13
|
+
def __init__(self, controller: 'Controller', model: ObservableModel):
|
|
14
|
+
|
|
15
|
+
super().__init__()
|
|
16
|
+
|
|
17
|
+
self._controller = controller
|
|
18
|
+
self._model = model
|
|
19
|
+
|
|
20
|
+
self._model.add_observer(self)
|