-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
217 lines (169 loc) · 7.57 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
"""
Script for managing hot reloading of the project.
For more details see the documentation page -
https://kivymd.readthedocs.io/en/latest/api/kivymd/tools/patterns/create_project/
To run the application in hot boot mode, execute the command in the console:
DEBUG=1 python main.py
"""
import importlib
import os
from pathlib import Path
from kivy import Config
from PIL import ImageGrab
# TODO: You may know an easier way to get the size of a computer display.
resolution = ImageGrab.grab().size
# Change the values of the application window size as you need.
Config.set("graphics", "height", "715")
Config.set("graphics", "width", "317")
from kivy.core.window import Window
# Place the application window on the right side of the computer screen.
Window.top = 28
Window.left = resolution[0] - Window.width + 3
from kivymd.tools.hotreload.app import MDApp
from kivymd.uix.screenmanager import MDScreenManager
from kivymd.uix.transition import MDSwapTransition
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDFillRoundFlatIconButton
from kivymd.utils.set_bars_colors import set_bars_colors
import json
from View.HomeScreen.components.weather_api_data import get_weather
from kivy.clock import Clock
Clock.max_iteration = 30
class nfsWeather(MDApp):
KV_DIRS = [os.path.join(os.getcwd(), "View")]
DEBUG=True
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.theme_cls.primary_palette = "Indigo"
self.theme_cls.primary_dark_hue = "800"
self.theme_cls.primary_light_hue = "50"
self.theme_cls.accent_palette = "Indigo"
self.theme_cls.accent_dark_hue = "600"
self.theme_cls.accent_light_hue = "100"
self.basic_font = "assets/fonts/PTSansNarrow-Regular.ttf"
self.basic_bold_font = "assets/fonts/PTSansNarrow-Bold.ttf"
self.apply_styles("Light")
self.update_context_data(["chicago"])
def build_app(self) -> MDScreenManager:
"""
In this method, you don't need to change anything other than the
application theme.
"""
import View.screens
self.manager_screens = MDScreenManager()
Window.bind(on_key_down=self.on_keyboard_down)
importlib.reload(View.screens)
screens = View.screens.screens
for i, name_screen in enumerate(screens.keys()):
model = screens[name_screen]["model"]()
controller = screens[name_screen]["controller"](model)
view = controller.get_view()
view.manager_screens = self.manager_screens
view.name = name_screen
self.manager_screens.add_widget(view)
self.manager_screens.padding = "44dp"
self.manager_screens.current = "home screen"
self.manager_screens.transition = MDSwapTransition()
return self.manager_screens
def apply_styles(self, style="Light"):
self.theme_cls.theme_style = style
def update_context_data(self, name_list):
for cities in name_list:
data=get_weather(cities)
with open("assets/json/data.json", "w", encoding="utf-8") as weather_data_file:
data=json.dumps(data)
weather_data_file.write(data)
with open("assets/json/data.json", "r", encoding="utf-8") as weather_data_file:
weather_data=weather_data_file.read()
weather_data=json.loads(weather_data)
self.weather_data = weather_data
def on_keyboard_down(self, window, keyboard, keycode, text, modifiers) -> None:
"""
The method handles keyboard events.
By default, a forced restart of an application is tied to the
`CTRL+R` key on Windows OS and `COMMAND+R` on Mac OS.
"""
if "meta" in modifiers or "ctrl" in modifiers and text == "r":
self.rebuild()
if __name__ == "__main__":
nfsWeather().run()
# After you finish the project, remove the above code and uncomment the below
# code to test the application normally without hot reloading.
# """
# The entry point to the application.
#
# The application uses the MVC template. Adhering to the principles of clean
# architecture means ensuring that your application is easy to test, maintain,
# and modernize.
#
# You can read more about this template at the links below:
#
# https://github.com/HeaTTheatR/LoginAppMVC
# https://en.wikipedia.org/wiki/Model–view–controller
# """
#
# from kivymd.app import MDApp
# from kivymd.uix.screenmanager import MDScreenManager
# from kivymd.uix.transition import MDSwapTransition
# from kivymd.uix.dialog import MDDialog
# from kivymd.uix.button import MDFillRoundFlatIconButton
# from kivymd.utils.set_bars_colors import set_bars_colors
# from kivy.clock import Clock
# Clock.max_iteration=30
# from View.screens import screens
# from PIL import ImageGrab
# # TODO: You may know an easier way to get the size of a computer display.
# resolution = ImageGrab.grab().size
# # Change the values of the application window size as you need.
# from kivy.core.window import Window
# # Place the application window on the right side of the computer screen.
# Window.top = 30
# Window.left = resolution[0] - Window.width
# class nfsWeather(MDApp):
# def __init__(self, **kwargs):
# super().__init__(**kwargs)
# self.load_all_kv_files(self.directory)
# self.theme_cls.primary_palette="Indigo"
# self.theme_cls.primary_dark_hue="800"
# self.theme_cls.primary_light_hue="50"
# self.theme_cls.accent_palette="Indigo"
# self.theme_cls.accent_dark_hue="600"
# self.theme_cls.accent_light_hue="100"
# self.basic_font="assets/fonts/PTSansNarrow-Regular.ttf"
# self.basic_bold_font="assets/fonts/PTSansNarrow-Bold.ttf"
# self.apply_styles("Light")
# # This is the screen manager that will contain all the screens of your
# # application.
# self.manager_screens = MDScreenManager()
# def build(self) -> MDScreenManager:
# self.generate_application_screens()
# self.set_bars_colors()
# self.manager_screens.padding="44dp"
# self.manager_screens.current="home screen"
# self.manager_screens.transition=MDSwapTransition()
# return self.manager_screens
# def generate_application_screens(self) -> None:
# """
# Creating and adding screens to the screen manager.
# You should not change this cycle unnecessarily. He is self-sufficient.
# If you need to add any screen, open the `View.screens.py` module and
# see how new screens are added according to the given application
# architecture.
# """
# for i, name_screen in enumerate(screens.keys()):
# model = screens[name_screen]["model"]()
# controller = screens[name_screen]["controller"](model)
# view = controller.get_view()
# view.manager_screens = self.manager_screens
# view.name = name_screen
# self.manager_screens.add_widget(view)
# def set_bars_colors(self):
# set_bars_colors(
# self.theme_cls.primary_color, # status bar color
# self.theme_cls.primary_color, # navigation bar color
# "Light", # icons color of status bar
# )
# def apply_styles(self,style="Light"):
# self.theme_cls.theme_style=style
# if __name__ == '__main__':
# nfsWeather().run()