CTkMVC 0.0.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.

Potentially problematic release.


This version of CTkMVC might be problematic. Click here for more details.

ctkmvc/controller.py ADDED
@@ -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()
ctkmvc/interface.py ADDED
@@ -0,0 +1,8 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+
4
+ class ModelObserver(ABC):
5
+
6
+ @abstractmethod
7
+ def model_is_changed(self):
8
+ pass
ctkmvc/model.py ADDED
@@ -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()
ctkmvc/view.py ADDED
@@ -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)
@@ -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.
@@ -0,0 +1,8 @@
1
+ ctkmvc/controller.py,sha256=Lky0Xj7dN58Y3GXT8NSC3b-9zNhE9r-lJwpPGqi58Es,349
2
+ ctkmvc/interface.py,sha256=k_4yG5YtYXAao_ZVUxyBaiWcXW-iX-cfxzmRssC1Suw,136
3
+ ctkmvc/model.py,sha256=q6NtZ3V-SbCSGLXQt-9D9u1Zyl72KOHzHbPFr9Y9t5Y,518
4
+ ctkmvc/view.py,sha256=TSztzLn0-eLCOwTAy2XQfyfaU4P_Dve4hPhugXFZ1Ww,453
5
+ ctkmvc-0.0.1.dist-info/METADATA,sha256=c-Tk7ImIyn37ERX8G_1xNz4zi81OrMq2ozyqmk2sMQM,3627
6
+ ctkmvc-0.0.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
7
+ ctkmvc-0.0.1.dist-info/licenses/LICENSE,sha256=K9VPpuDPEcbDVlG74iFCbYVxyeumCXQ3-ULbcZawLQo,1059
8
+ ctkmvc-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.25.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -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.