-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
160 lines (129 loc) · 4.3 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
"""
Main module of Linconym.
"""
###############
### Imports ###
###############
### Python imports ###
import os
### Kivy imports ###
# Disable back arrow
from kivy.config import Config
Config.set('kivy', 'exit_on_escape', '0')
from kivy.app import App
from kivy.uix.screenmanager import (
ScreenManager,
NoTransition,
Screen
)
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.clock import Clock, mainthread
### Local imports ###
from tools.path import (
PATH_IMAGES,
PATH_TEMP_IMAGES
)
from tools.constants import (
ANDROID_MODE,
FPS,
MSAA_LEVEL
)
import screens.opening
from screens.custom_widgets import LoadingPopup
###############
### General ###
###############
class WindowManager(ScreenManager):
"""
Screen manager, which allows the navigation between the different menus.
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.transition = NoTransition()
self.list_previous_screens = []
current_screen = Screen(name="temp")
self.add_widget(current_screen)
self.current = "temp"
def change_all_background_images(self, new_image_path, include_themes_screen=False):
for screen_name in self.screen_names:
if screen_name != "temp" and (screen_name != "themes" or include_themes_screen):
screen = self.get_screen(screen_name)
screen.set_back_image_path(new_image_path)
if screen_name == "themes":
screen.set_back_image_path(new_image_path, mode="second")
def go_to_previous_screen(self):
if len(self.list_previous_screens) != 0:
previous_screen = self.list_previous_screens.pop()
screen_name = previous_screen[0]
self.get_screen(screen_name).reload_kwargs(previous_screen[1])
self.current = screen_name
def go_to_next_screen(self, next_screen_name, current_dict_kwargs={}, next_dict_kwargs={}):
current_screen_name = self.current
self.list_previous_screens.append(
(current_screen_name, current_dict_kwargs))
self.get_screen(next_screen_name).reload_kwargs(next_dict_kwargs)
self.current = next_screen_name
class MainApp(App, Widget):
"""
Main class of the application.
"""
def build_config(self, config):
"""
Build the config file for the application.
It sets the FPS number and the antialiasing level.
"""
config.setdefaults('graphics', {
'maxfps': str(FPS),
'multisamples': str(MSAA_LEVEL)
})
def build(self):
"""
Build the application.
Parameters
----------
None
Returns
-------
None
"""
Window.clearcolor = (0, 0, 0, 1)
self.icon = PATH_IMAGES + "logo.png"
@mainthread
def on_resume(self):
print("reloading")
current_screen_name = self.root_window.children[0].current
screen = self.root_window.children[0].get_screen(current_screen_name)
loading_popup = LoadingPopup(
font_ratio=screen.font_ratio,
primary_color=screen.primary_color,
secondary_color=screen.secondary_color,
)
print("popup created")
loading_popup.open()
print("opened")
Clock.schedule_once(loading_popup.dismiss, 2)
return super().on_resume()
def on_stop(self):
temp_images_list = os.listdir(PATH_TEMP_IMAGES)
for temp_image in temp_images_list:
if temp_image.endswith(".png"):
os.remove(PATH_TEMP_IMAGES + temp_image)
return super().on_stop()
def on_start(self):
if ANDROID_MODE:
Window.update_viewport()
# Open the opening screen
opening_screen = screens.opening.OpeningScreen(name="opening")
self.root_window.children[0].add_widget(opening_screen)
self.root_window.children[0].current = "opening"
Clock.schedule_once(
self.root_window.children[0].get_screen("opening").launch_thread)
print("Main app started")
return super().on_start()
# Run the application
if __name__ == "__main__":
if not ANDROID_MODE:
Window.size = (405, 720)
# Window.size = (750, 1000)
MainApp().run()