-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.py
319 lines (279 loc) · 10.7 KB
/
Application.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#====================================================================#
# File Information
#====================================================================#
from Libraries.BRS_Python_Libraries.BRS.Debug.LoadingLog import LoadingLog
from Programs.Local.Hardware.RGB import KontrolRGB
LoadingLog.Start("Application.py")
#===================================================================#
# Imports
#===================================================================#
LoadingLog.Import("Python")
import os
LoadingLog.Import("Kivy")
from kivy.core.window import Window
from kivy.config import Config
from kivy.uix.screenmanager import ScreenManager
# -------------------------------------------------------------------
LoadingLog.Import("KivyMD")
from kivymd.app import MDApp
# -------------------------------------------------------------------
LoadingLog.Import("Libraries")
from Libraries.BRS_Python_Libraries.BRS.GUI.Utilities.font import Font
from Libraries.BRS_Python_Libraries.BRS.Network.WiFi.WiFi import WiFiStatusUpdater
from Libraries.BRS_Python_Libraries.BRS.Utilities.AppScreenHandler import AppManager
from Libraries.BRS_Python_Libraries.BRS.Utilities.LanguageHandler import AppLanguage
from Libraries.BRS_Python_Libraries.BRS.Debug.consoleLog import Debug
from Libraries.BRS_Python_Libraries.BRS.Utilities.Information import Information
from Libraries.BRS_Python_Libraries.BRS.Utilities.FileHandler import AppendPath
from Libraries.BRS_Python_Libraries.BRS.Utilities.addons import Addons
# -------------------------------------------------------------------
LoadingLog.Import("Local")
from Programs.Local.FileHandler.Cache import Cache
from Programs.Pages.ProfileMenu import ProfileMenu
from Programs.Pages.Startup import Startup_Screens
from Programs.Pages.AppLoading import AppLoading_Screens
from Programs.Pages.PopUps import PopUps_Screens
from Programs.Local.Updating.LaunchHandling import Shutdown
from Programs.Local.Hardware.RGB import KontrolRGB
# from Programs.Pages.WiFiLogin import WiFiConnecting_Screens, WiFiLogin_Screens
#====================================================================#
# Configuration
#====================================================================#
# region -- Font
ButtonFont = Font()
ButtonFont.isBold = True
ButtonFont.size = "32sp"
# endregion
#====================================================================#
# Functions
#====================================================================#
# 0 being off 1 being on as in true / false
# you can use 0 or 1 && True or False
# Config.set('graphics', 'resizable', '0')
# fix the width of the window
# Config.set('graphics', 'width', '720')
# Config. set('graphics', 'height', '576')
#====================================================================#
# Classes
#====================================================================#
# ------------------------------------------------------------------------
LoadingLog.Class("Application")
class Application(MDApp):
def SetDefaultTheme(self):
"""
SetDefaultTheme:
================
Summary:
--------
This function sets the default theme
that the application will have before
cache is loaded in. This function is
called in :ref:`build` automatically.
"""
Debug.Start("SetDefaultTheme")
self.theme_cls.material_style = 'M3'
self.theme_cls.primary_palette = "Purple"
self.theme_cls.accent_palette = "Yellow"
self.theme_cls.theme_style = "Dark"
self.theme_cls.theme_style_switch_animation = False
self.theme_cls.theme_style_switch_animation_duration = 0
Debug.End()
def SetDefaultLanguage(self):
"""
SetDefaultLanguage:
===================
Summary:
--------
This function initializes the
:ref:`AppLanguage` class. It defaults
the language of the application to
US_English until the cache is initialized.
This function is called automatically in
:ref:`build`
"""
Debug.Start("SetDefaultLanguage")
# Load available languages
Debug.Log("Initializing AppLanguage. Defaulting to US_English")
path = AppendPath(os.getcwd(), "/Local/Languages/locale")
AppLanguage.__init__(AppLanguage, path, "US_English")
# Set default AppInfo informations
Debug.Log("Setting Information")
if(AppLanguage.Current == None):
Debug.Warn("Your application cannot use languages")
Information.CanUse.Languages = False
else:
Information.CanUse.Languages = True
Debug.End()
def SetKivyConfig(self):
"""
SetKivyConfig:
==============
Summary:
--------
This function's purpose is
to set the default application
kivy settings in the Config before
the application is fully loaded in.
Such configurations can be wether the
mouse is displayed or not.
"""
Debug.Start("SetKivyConfig")
if(Information.platform == "Linux"):
Debug.Log("Turning off cursor")
Window.show_cursor = False
Debug.enableConsole = False
Debug.Log("Turning off aliasing")
Config.set("graphics", "multisamples", 0)
Config.write()
Debug.End()
return
if(Information.platform == "Windows"):
Window.show_cursor = True
Debug.End()
return
Debug.End()
def StartGlobalThreads(self):
"""
StartGlobalThreads:
===================
Summary:
--------
Starts the threads of multiple
background processes used to
constantly show up to date informations
such as if your device can access the
internet or if your device can use RGB
lights and so on.
"""
Debug.Start("StartGlobalThreads")
Debug.Log("Starting slow network information updater")
WiFiStatusUpdater.StartUpdating()
Debug.Log("Trying to start RGB class.")
KontrolRGB.Initialize()
Debug.End()
def LoadSavedCache(self):
"""
LoadSavedCache:
===============
Summary:
--------
Initializes the saved cache
of your application. This needs
to be called AFTER the following:
- :ref:`SetDefaultTheme`
- :ref:`SetDefaultLanguage`
- :ref:`SetKivyConfig`
"""
Debug.Start("LoadSavedCache")
if(Cache.Load()):
Debug.Error("Failed to load the application's cache")
else:
Debug.Log("CACHE LOAD SUCCESS")
Debug.End()
def ConfigureAndLoadStartScreen(self):
"""
ConfigureAndLoadStartScreen:
============================
Summary:
--------
This function configures the
_Screens classes of the following
transitional screens:
- :ref:`Startup_Screens`
- :ref:`AppLoading_Screens`
- :ref:`PopUps_Screens`
It then calls the Call function of :ref:`Startup_Screens`
so that Kontrol can launch. This needs to be the last
function in :ref:`build` right before the return statement.
"""
Debug.Start("ConfigureAndLoadStartScreen")
# Create screen manager
Debug.Log("Creating ScreenManager()")
AppManager.manager = ScreenManager()
AppLoading_Screens.SetExiter(PopUps_Screens, "PopUps")
AppLoading_Screens.SetCaller(Startup_Screens, "Startup")
PopUps_Screens.SetExiter(ProfileMenu, "ProfileMenu")
PopUps_Screens.SetCaller(AppLoading_Screens, "AppLoading")
Startup_Screens.SetExiter(AppLoading_Screens, "AppLoading")
Startup_Screens.SetCaller(Application, "Application")
Startup_Screens.Call()
Debug.End()
def ConfigureWindowAttributes(self):
"""
ConfigureWindowAttributes:
==========================
Summary:
--------
Sets the default values of
Kivy's :ref:`Window` class
such as if it's border less,
in full screen etc.
"""
Debug.Start("SetWindowInformations")
#Window.borderless = True
#Window.resizable = True
#Window.left = -1024
#Window.top = 600
#Window.fullscreen = False
Window.size = (720, 576)
Debug.End()
LoadingLog.Method("build")
def build(self):
"""
build:
======
Summary:
--------
This creates the Screen manager, which is stored inside of the global AppManager class.
After which, all the screens the application uses are added as widgets to the manager.
They each have a name unique to them.
The build function is execute when the application launches.
It creates language handlers, cache handlers or any other handler necessary
for Kontrol to function properly.
"""
Debug.enableConsole = False
Debug.Start("build")
self.SetKivyConfig()
self.SetDefaultTheme()
self.SetDefaultLanguage()
self.ConfigureWindowAttributes()
self.LoadSavedCache()
self.StartGlobalThreads()
self.ConfigureAndLoadStartScreen()
Debug.End()
return AppManager.manager
LoadingLog.Method("on_start")
def on_start(self):
print("Application built... starting")
LoadingLog.Method("on_stop")
def on_stop(self):
Debug.Start("Application -> on_stop")
if(Cache.loaded):
try:
Cache.GetAppInfo()
Cache.SetExit("User")
Cache.SetDate("Exit")
Cache.SaveFile()
print("===============================")
print("--------- CACHE SAVED ---------")
print("===============================")
except:
print("[BRS] CACHE ERRORS")
Debug.Warn("Cache failed to save on_stop. This might be normal tho.")
Debug.End()
# ------------------------------------------------------------------------
# try:
Application().run()
# except:
# if(Cache.loaded):
# Cache.SetExit("Crashed")
# Cache.SetDate("Exit")
# Cache.SaveFile()
Shutdown.ShutdownFunction()
KontrolRGB.Uninitialize()
Addons.StopAll()
WiFiStatusUpdater.StopUpdating()
# Debug.Log("KILLING PYTHON PROCESS")
# KillPython()
Shutdown.Kontrol()
LoadingLog.End("Application.py")